예제 #1
0
async def adminControl(message):
    p = DictionaryReader()
    roles = message.author.roles
    canBan = False
    for role in roles:
        canBan = canBan or (role.name in p.roles())
    if not canBan:
        print('{0.author.name} can\'t manage members!'.format(message))
        await message.author.send('You can\'t manage members!')  
        return
    else:
        # Bans - Format:  !ban 9999999999999
        if message.content.startswith(prefix+'ban'):
            if not message.guild.me.guild_permissions.ban_members:
                await message.author.send('The bot does not have permissions to manage members.')
                return
            id = message.content.split(' ')[1]
            reason = ' '.join(message.content.split(' ')[2::])
            try:
                user = await client.get_user_info(id)
                await message.guild.ban(user=user, reason=reason)
                if user != None:
                    await message.author.send('User {0.mention} banned successfully'.format(user))
                else:
                    await message.author.send('Invalid user ID')                            
            except discord.HTTPException:
                pass
            finally:
                await message.delete()
        # Ban info - Format:  !info 9999999999999
        if message.content.startswith(prefix+'info'):        
            if not message.guild.me.guild_permissions.view_audit_log:
                await message.author.send('The bot does not have permissions to view audit logs.')
                return
            id = message.content.split(' ')[1]
            isUserBanned = False
            
            try:
                await message.delete()
            except (HTTPException, Forbidden):
                print('Error deleting message, probably from whisper')
            
            user = await client.get_user_info(id)
            
            await message.author.send( 'User {0.mention}\n```Bans```'.format(user) )
            
            async for entry in message.guild.audit_logs(action=discord.AuditLogAction.ban):                
                if str(entry.target.id) == str(id):               
                    await message.author.send('-> User {0.target}({0.target.id}) was **banned** by {0.user}({0.user.id}) on {0.created_at} (UTC)\n\tReason: {0.reason}\n'.format(entry))
                    isUserBanned = True
            
            await message.author.send( '```Unbans```' )
            async for entry in message.guild.audit_logs(action=discord.AuditLogAction.unban):
                if entry.target.id == int(id):
                    await message.author.send('-> User {0.target} was **unbanned** by {0.user}({0.user.id}) on {0.created_at} (UTC)'.format(entry))                    
            if not isUserBanned:
                await message.author.send('User was never banned.')
예제 #2
0
async def forwardMessage(message):
    p = DictionaryReader()
    roles = message.author.roles
    canSend = False
    for role in roles:
        canSend = canSend or (role.name in p.roles())
    if not canSend:
        print('{0.author.name} can\'t send whispers'.format(message))
        return
    entries = message.content.split(' ')
    target = message.mentions[0]
    if target != None:
        entry = ' '.join(entries[2::])
        msg = p.commandReader(entry)
        if msg != None:
            await target.send(msg)
            await message.delete()
            await message.author.send('Message sent to {0.mention}'.format(target))
        else:
            await message.channel.send('Invalid Message, {0.mention}'.format(message.author))
예제 #3
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))
예제 #4
0
async def adminControl(message):
    p = DictionaryReader()
    roles = message.author.roles
    canBan = False
    for role in roles:
        canBan = canBan or (role.name in p.roles())
    if not canBan:
        print('{0.author.name} can\'t manage members!'.format(message))
        await message.author.send('You can\'t manage members!')
        return
    else:
        # Mass bans - Format: !banall id0 id1 id2
        if message.content.startswith(prefix + 'banall'):
            if not message.guild.me.guild_permissions.ban_members:
                await message.author.send(
                    'The bot does not have permissions to manage members.')
                return
            ids = message.content.split(' ')[1::]
            reason = 'mass ban'
            bannedCount = 0
            for id in ids:
                try:
                    user = await client.fetch_user(id)
                    await message.guild.ban(user=user,
                                            reason=reason,
                                            delete_message_days=7)
                    if user != None:
                        await message.author.send(
                            'User {0.mention} banned successfully'.format(user)
                        )
                        bannedCount += 1
                    else:
                        await message.author.send(
                            '{0} is an invalid user ID'.format(str(id)))
                except discord.HTTPException:
                    continue
            await message.author.send('Successfully banned {0} users'.format(
                str(bannedCount)))
            await message.delete()

        # Bans - Format:  !ban 9999999999999
        elif message.content.startswith(prefix + 'ban'):
            if not message.guild.me.guild_permissions.ban_members:
                await message.author.send(
                    'The bot does not have permissions to manage members.')
                return
            splitMessage = message.content.split(' ')
            id = splitMessage[1]
            deleteDays = 0
            reasonStart = 2
            if len(splitMessage) > 2:
                deleteDays = splitMessage[2] if splitMessage[2].isdigit(
                ) else 0
                reasonStart = 3 if splitMessage[2].isdigit() else 2

            reason = ' '.join(splitMessage[reasonStart::])
            print(reason)
            try:
                user = await client.fetch_user(id)
                if user != None:
                    await message.guild.ban(user=user,
                                            reason=reason,
                                            delete_message_days=deleteDays)
                    await message.author.send(
                        'User {0.mention} banned successfully'.format(user))
                else:
                    await message.author.send('Invalid user ID')
            except discord.HTTPException:
                pass
            finally:
                await message.delete()
        # Ban info - Format:  !info 9999999999999
        elif message.content.startswith(prefix + 'info'):
            if not message.guild.me.guild_permissions.view_audit_log:
                await message.author.send(
                    'The bot does not have permissions to view audit logs.')
                return
            id = message.content.split(' ')[1]
            isUserBanned = False

            try:
                await message.delete()
            except (HTTPException, Forbidden):
                print('Error deleting message, probably from whisper')

            user = await client.fetch_user(id)

            await message.author.send(
                'User {0.mention}\n```Bans```'.format(user))

            async for entry in message.guild.audit_logs(
                    action=discord.AuditLogAction.ban):
                if str(entry.target.id) == str(id):
                    await message.author.send(
                        '-> User {0.target}({0.target.id}) was **banned** by {0.user}({0.user.id}) on {0.created_at} (UTC)\n\tReason: {0.reason}\n'
                        .format(entry))
                    isUserBanned = True

            await message.author.send('```Unbans```')
            async for entry in message.guild.audit_logs(
                    action=discord.AuditLogAction.unban):
                if entry.target.id == int(id):
                    await message.author.send(
                        '-> User {0.target} was **unbanned** by {0.user}({0.user.id}) on {0.created_at} (UTC)'
                        .format(entry))
            if not isUserBanned:
                await message.author.send('User was never banned.')