Beispiel #1
0
    async def toggleUserState(client, before, after):
        p = DictionaryReader()

        streamingRole = utils.find(lambda r: r.name == p.streamingRole(),
                                   before.guild.roles)

        # User doesn't have the streaming role, move along
        if streamingRole not in before.roles:
            return

        # Left the server
        if after is None:
            #print('left server')
            await RoleHandler.removeStream(client, before)
        # Role was removed
        elif streamingRole in before.roles and streamingRole not in after.roles:
            #print('role removed')
            await RoleHandler.removeStream(client, before)

        # Checks if the Game state changed or if the user isn't streaming
        # This or statement might be costly and subject to improvement
        elif before.activity != after.activity or after.activity is None or after.activity.type != ActivityType.streaming:
            p = DictionaryReader()
            if after.activity is None or after.activity.type != ActivityType.streaming:
                #print('stopped stream')
                # Stopped Streaming
                await RoleHandler.removeStream(client, after)

            elif after.activity.type == ActivityType.streaming:
                # Started Streaming
                #print('started stream')
                await RoleHandler.addStream(client, after)
Beispiel #2
0
    async def toggleStream(client, message):
        p = DictionaryReader()

        print(message.content)

        target = message.mentions[0] if message.mentions else message.author

        role = utils.find(lambda r: r.name == p.streamingRole(), target.roles)
        staff = utils.find(lambda r: r.name == p.roles(), message.author.roles)
        donor = utils.find(lambda r: r.name == p.donor(), message.author.roles)
        streamingRole = utils.find(lambda r: r.name == p.streamingRole(),
                                   message.author.guild.roles)

        # Target doesn't have the Streaming Role
        if role is None:

            # If user has the Staff role
            if staff is not None:
                await target.add_roles(streamingRole,
                                       reason='Role added by {0.name}'.format(
                                           message.author))

            else:
                # Donors can add the role to themselves
                if donor is not None:
                    await message.author.add_roles(
                        streamingRole,
                        reason='Donor adding role to themselves')

        # User already has the Streaming Role, so remove it
        else:
            # If user has the Staff role or is the author
            if staff is not None or target == message.author:
                await target.remove_roles(
                    role,
                    reason='Role removed by {0.name}'.format(message.author))
Beispiel #3
0
    async def toggleUserState(client, before, after):
        p = DictionaryReader()

        streamingRole = utils.find(lambda r: r.name == p.streamingRole(),
                                   before.guild.roles)

        # User doesn't have the streaming role, move along
        if streamingRole not in before.roles:
            return

        # Left the server
        if after is None:
            await RoleHandler.removeStream(client, before)
        # Role was removed
        elif streamingRole in before.roles and streamingRole not in after.roles:
            print('role removed')
            await RoleHandler.removeStream(client, before)

        # Checks if the Game state changed or if the user isn't streaming
        # This or statement might be costly and subject to improvement
        elif before.activity != after.activity or after.activity is None or after.activity.type != ActivityType.streaming:

            # Fetches streaming activities in after and before to compare, to avoid reposting
            beforeStream = None
            stream = None
            for act in after.activities:
                if act.type == ActivityType.streaming:
                    stream = act
                    break

            for act in before.activities:
                if act.type == ActivityType.streaming:
                    beforeStream = act
                    break

            if after.activity is None or not stream:
                # Stopped Streaming
                await RoleHandler.removeStream(client, after)

            elif stream and beforeStream != stream:
                # Started Streaming
                await RoleHandler.addStream(client, after)