Esempio n. 1
0
    async def addStream(client, member):
        p = DictionaryReader()
        channel = client.get_channel(int(p.streamingBroadcastChannel()))
        currentlyStreaming = utils.find(
            lambda r: r.name == p.currentlyStreamingRole(), member.guild.roles)

        await RoleHandler.removeStream(client, member)

        stream = None
        for act in member.activities:
            if act.type == ActivityType.streaming:
                stream = act

        if channel is None:
            print('Streaming Channel not found!')
            return

        #if not await TwitchHandler.validateStream(stream.url, Key().twitchApiKey()):
        # return
        if not stream.game.startswith('World of Warcraft'):
            return

        title, description, avatar, views, followers = await TwitchHandler.fetchStreamInfo(
            stream.url,
            Key().twitchApiKey())

        emb = Embed()
        emb.title = title
        emb.type = 'rich'
        emb.description = description
        emb.url = stream.url
        emb.colour = Colour.purple()
        emb.set_footer(text='Created by PriestBot', icon_url=p.h2pIcon())
        emb.set_thumbnail(url=avatar)
        emb.set_author(name=member.name, icon_url=member.avatar_url)
        emb.add_field(name='Views', value=views)
        emb.add_field(name='Followers', value=followers)

        if currentlyStreaming not in member.roles:
            await member.add_roles(currentlyStreaming,
                                   reason='User started streaming')
            await channel.send(
                '{0.mention} is now Live on Twitch!'.format(member), embed=emb)

        else:
            # This could be slow, but shouldn't, assuming there should be few messages in the channel
            messages = await channel.history(limit=None).flatten()

            for message in messages:
                if member in message.mentions:
                    await message.edit(embed=emb)
Esempio n. 2
0
    async def removeStream(client, member):
        p = DictionaryReader()
        channel = client.get_channel(int(p.streamingBroadcastChannel()))
        currentlyStreaming = utils.find(
            lambda r: r.name == p.currentlyStreamingRole(), member.guild.roles)

        if channel is None:
            print('Streaming Channel not found!')
            return

        await member.remove_roles(currentlyStreaming,
                                  reason='User stopped streaming')

        # This could be slow, but shouldn't, assuming there should be few messages in the channel
        messages = await channel.history(limit=None).flatten()

        for message in messages:
            if member in message.mentions:
                await message.delete()