Beispiel #1
0
async def unmute(cmd, message, args):
    channel = message.channel
    server = message.server
    if not message.mentions:
        await cmd.bot.send_message(message.channel, cmd.help())
        return
    user_q = message.mentions[0]
    if message.author is not user_q:
        if check_man_msg(message.author, channel) and check_man_roles(
                message.author, channel):
            for chan in server.channels:
                if str(chan.type).lower() == 'text':
                    if not check_write(user_q, chan):
                        await cmd.bot.delete_channel_permissions(chan, user_q)
            embed = discord.Embed(color=0x66CC66,
                                  title=':white_check_mark: ' + user_q.name +
                                  ' can write again.')
            await cmd.bot.send_message(message.channel, None, embed=embed)
        else:
            out_content = discord.Embed(
                type='rich',
                color=0xDB0000,
                title=
                ':no_entry: Insufficient Permissions. Manage Messages and Manage Roles Permissions Required.'
            )
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
Beispiel #2
0
async def createrole(cmd, message, args):
    
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(type='rich', color=0xDB0000, title='⛔ Insufficient Permissions. Server Admin Only.')
        await message.channel.send(None, embed=out_content)
        return
    
    if not args:
        out_content = discord.Embed(type='rich', color=0xDB0000, title='❗ Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return
    
    role_qry = ' '.join(args)
    exists = matching_role(message.guild, role_qry)
    
    if exists:
        out_content = discord.Embed(type='rich', color=0xFF9900, title='⚠ Error')
        out_content.add_field(name='Role Exists', value='A role with the name **' + role_qry + '** already exists.')
        await message.channel.send(None, embed=out_content)
        return

    await message.guild.create_role(name=role_qry)
    out_content = discord.Embed(type='rich', color=0x33CC33, title='✅ Role ' + role_qry + ' created.')
    await message.channel.send(None, embed=out_content)
Beispiel #3
0
async def addselfrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(type='rich', color=0xDB0000,
                                    title='⛔ Insufficient Permissions. Server Admin Only.')
        await message.channel.send(None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich', color=0xDB0000, title='❗ Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return
    role_qry = ' '.join(args)
    target_role = matching_role(message.guild, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich', color=0xFF9900, title='❗ Error')
        out_content.add_field(name='Role Not Found', value='I was unable to find **' + role_qry + '** on this server.')
        await message.channel.send(None, embed=out_content)
    else:
        try:
            self_roles = cmd.db.get_settings(message.guild.id, 'SelfRoles')
        except:
            cmd.db.set_settings(message.guild.id, 'SelfRoles', [])
            self_roles = []
        if target_role.id not in self_roles:
            self_roles.append(target_role.id)
            cmd.db.set_settings(message.guild.id, 'SelfRoles', self_roles)
            out_content = discord.Embed(type='rich', color=0x66cc66,
                                        title='✅ Role **' + target_role.name + '** added to the self assignable roles list.')
            await message.channel.send(None, embed=out_content)
        else:
            out_content = discord.Embed(type='rich', color=0xFF9900, title='⚠ Error')
            out_content.add_field(name='Role In List',
                                  value='The role **' + role_qry + '** is already in the list of self assignable roles.')
            await message.channel.send(None, embed=out_content)
Beispiel #4
0
async def delselfrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(type='rich', color=0xDB0000,
                                    title=':no_entry: Insufficient Permissions. Server Admin Only.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich', color=0xDB0000, title=':exclamation: Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role_qry = ' '.join(args)
    target_role = matching_role(message.server, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich', color=0xFF9900, title=':exclamation: Error')
        out_content.add_field(name='Role Not Found', value='I was unable to find **' + role_qry + '** on this server.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
    else:
        try:
            self_roles = cmd.db.get_settings(message.server.id, 'SelfRoles')
        except:
            cmd.db.set_settings(message.server.id, 'SelfRoles', [])
            self_roles = []
        if target_role.name in self_roles:
            self_roles.remove(target_role.name)
            cmd.db.set_settings(message.server.id, 'SelfRoles', self_roles)
            out_content = discord.Embed(type='rich', color=0x66cc66,
                                        title=':white_check_mark: Role **' + target_role.name + '** removed from the self assignable roles list.')
            await cmd.bot.send_message(message.channel, None, embed=out_content)
        else:
            out_content = discord.Embed(type='rich', color=0xFF9900, title=':warning: Error')
            out_content.add_field(name='Role Not Self Assignable',
                                  value='I was unable to find **' + role_qry + '** in the list of self assignable roles.')
            await cmd.bot.send_message(message.channel, None, embed=out_content)
Beispiel #5
0
async def destroyrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title='⛔ Insufficient Permissions. Server Admin Only.')
        await message.channel.send(None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return
    role_qry = ' '.join(args)
    target_role = matching_role(message.guild, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='❗ Error')
        out_content.add_field(name='Role Not Found',
                              value='I was unable to find **' + role_qry +
                              '** on this server.')
        await message.channel.send(None, embed=out_content)
    else:
        await target_role.delete()
        out_content = discord.Embed(type='rich',
                                    color=0x66cc66,
                                    title='✅ Role ' + role_qry + ' destroyed.')
        await message.channel.send(None, embed=out_content)
Beispiel #6
0
async def mute(cmd, message, args):
    channel = message.channel
    server = message.server
    if not message.mentions:
        await cmd.bot.send_message(message.channel, cmd.help())
        return
    user_q = message.mentions[0]
    overwrite = PermissionOverwrite()
    overwrite.send_messages = False
    if message.author is not user_q:
        if check_man_msg(message.author, channel) and check_man_roles(
                message.author, channel):
            try:
                for chan in server.channels:
                    if str(chan.type).lower() == 'text':
                        if check_write(user_q, chan):
                            await cmd.bot.edit_channel_permissions(
                                chan, user_q, overwrite)
                await cmd.bot.send_message(
                    message.channel, 'Execution Successful.\nUser **' +
                    user_q.name + '** was muted')
            except Exception as e:
                cmd.log.error(e)
                await cmd.bot.send_message(message.channel, str(e))
        else:
            response = await cmd.bot.send_message(
                message.channel,
                'Only a user with the **Manage Messages and Manage Roles** privilege can use this command. :x:'
            )
            await asyncio.sleep(10)
            await cmd.bot.delete_message(response)
Beispiel #7
0
async def wftag(cmd, message, args):
    if check_man_roles(message.author, message.channel):
        if args:
            if len(args) > 1:
                alert_tag = args[0].lower()
                alert_role_search = ' '.join(args[1:]).lower()
                alert_role = None
                for role in message.guild.roles:
                    if role.name.lower() == alert_role_search:
                        alert_role = role
                        break
                if alert_role:
                    try:
                        wf_tags = cmd.db.get_settings(message.guild.id, 'WarframeTags')
                    except:
                        wf_tags = {}
                    if alert_tag not in wf_tags:
                        response_title = f'`{alert_tag.upper()}` has been bound to {alert_role.name}'
                    else:
                        response_title = f'`{alert_tag.upper()}` has been updated to bind to {alert_role.name}'
                    wf_tags.update({alert_tag: alert_role.id})
                    cmd.db.set_settings(message.guild.id, 'WarframeTags', wf_tags)
                    response = discord.Embed(title=f'✅ {response_title}', color=0x66CC66)
                else:
                    response = discord.Embed(title=f'❗ {alert_role_search.upper()} Was Not Found', color=0xDB0000)
            else:
                response = discord.Embed(title='❗ Not Enough Arguments', color=0xDB0000)
        else:
            response = discord.Embed(title='❗ Nothing Was Inputted', color=0xDB0000)
    else:
        response = discord.Embed(title='⛔ Unpermitted. Manage Roles Permission Required.', color=0xDB0000)
    await message.channel.send(embed=response)
Beispiel #8
0
async def createrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=':no_entry: Insufficient Permissions. Server Admin Only.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title=':exclamation: Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role_qry = ' '.join(args)
    exists = matching_role(message.server, role_qry)
    if exists:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title=':warning: Error')
        out_content.add_field(name='Role Exists',
                              value='A role with the name **' + role_qry +
                              '** already exists.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
    else:
        out_content = discord.Embed(type='rich',
                                    color=0x33CC33,
                                    title=':white_check_mark: Role ' +
                                    role_qry + ' created.')
        await cmd.bot.create_role(message.server, name=role_qry)
        await cmd.bot.send_message(message.channel, None, embed=out_content)
Beispiel #9
0
async def destroyrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=':no_entry: Insufficient Permissions. Server Admin Only.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title=':exclamation: Error')
        out_content.add_field(name='Not Enough Arguments', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role_qry = ' '.join(args)
    target_role = matching_role(message.server, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title=':exclamation: Error')
        out_content.add_field(name='Role Not Found',
                              value='I was unable to find **' + role_qry +
                              '** on this server.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
    else:
        await cmd.bot.delete_role(message.server, target_role)
        out_content = discord.Embed(type='rich',
                                    color=0x66cc66,
                                    title=':white_check_mark: Role ' +
                                    role_qry + ' destroyed.')
        await cmd.bot.create_role(message.server, name=role_qry)
        await cmd.bot.send_message(message.channel, None, embed=out_content)
Beispiel #10
0
async def blind(cmd, message, args):
    channel = message.channel
    server = message.server
    if not message.mentions:
        await cmd.bot.send_message(message.channel, cmd.help())
        return
    user_q = message.mentions[0]
    overwrite = discord.PermissionOverwrite()
    overwrite.read_messages = False
    if message.author is not user_q:
        if check_man_msg(message.author, channel) and check_man_roles(
                message.author, channel):
            for chan in server.channels:
                if not chan.is_default:
                    if str(chan.type).lower() == 'text':
                        if check_write(user_q, chan):
                            await cmd.bot.edit_channel_permissions(
                                chan, user_q, overwrite)
            embed = discord.Embed(color=0x66CC66,
                                  title='✅ ' + user_q.name + ' Was Blinded!')
            await cmd.bot.send_message(message.channel, None, embed=embed)
        else:
            out_content = discord.Embed(
                color=0xDB0000,
                title=
                '⛔ Insufficient Permissions. Users with Ban permissions only.')
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
Beispiel #11
0
async def giverole(cmd, message, args):

    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title='⛔ Insufficient Permissions. Needs manage roles permission.')
        await message.channel.send(None, embed=out_content)
        return

    if len(args) < 2:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Missing Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return

    if not message.mentions:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Missing Target User', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return

    role_qry = ' '.join(args[1:])
    target_role = matching_role(message.guild, role_qry)
    target_user = message.mentions[0]
    user_contained_role = user_matching_role(target_user, role_qry)

    if not target_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='❗ Error')
        out_content.add_field(name='Role Not Found',
                              value='I was unable to find **' + role_qry +
                              '** on this server.')
        await message.channel.send(None, embed=out_content)
        return

    if user_contained_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='❗ Error')
        out_content.add_field(name='User Has Role',
                              value='The user **' + target_user.name +
                              '** already has this role.')
        await message.channel.send(None, embed=out_content)

    await target_user.add_roles(target_role)
    out_content = discord.Embed(type='rich',
                                color=0x66cc66,
                                title='✅ Role ' + role_qry + ' given to **' +
                                target_user.name + '**.')
    await message.channel.send(None, embed=out_content)
Beispiel #12
0
async def takerole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title='⛔ Insufficient Permissions. Server Admin Only.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if len(args) < 2:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Missing Arguments', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not message.mentions:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Missing Target User', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role_qry = ' '.join(args[1:])
    target_role = matching_role(message.server, role_qry)
    target_user = message.mentions[0]
    user_contained_role = user_matching_role(target_user, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='❗ Error')
        out_content.add_field(name='Role Not Found',
                              value='I was unable to find **' + role_qry +
                              '** on this server.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
    else:
        if user_contained_role:
            await cmd.bot.remove_roles(target_user, target_role)
            out_content = discord.Embed(type='rich',
                                        color=0x66cc66,
                                        title='✅ Role ' + role_qry +
                                        ' removed from **' + target_user.name +
                                        '**.')
            await cmd.bot.create_role(message.server, name=role_qry)
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
        else:
            out_content = discord.Embed(type='rich',
                                        color=0xFF9900,
                                        title='❗ Error')
            out_content.add_field(name='User Missing Role',
                                  value='I was unable to find **' + role_qry +
                                  '** in ' + target_user.name + '\'s roles.')
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
Beispiel #13
0
async def giverole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=':no_entry: Insufficient Permissions. Server Admin Only.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if len(args) < 2:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title=':exclamation: Error')
        out_content.add_field(name='Missing Arguments', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not message.mentions:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title=':exclamation: Error')
        out_content.add_field(name='Missing Target User', value=cmd.help())
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role_qry = ' '.join(args[1:])
    target_role = matching_role(message.server, role_qry)
    target_user = message.mentions[0]
    user_contained_role = user_matching_role(target_user, role_qry)
    if not target_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title=':exclamation: Error')
        out_content.add_field(name='Role Not Found',
                              value='I was unable to find **' + role_qry +
                              '** on this server.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
    else:
        if not user_contained_role:
            await cmd.bot.add_roles(target_user, target_role)
            out_content = discord.Embed(type='rich',
                                        color=0x66cc66,
                                        title=':white_check_mark: Role ' +
                                        role_qry + ' given to **' +
                                        target_user.name + '**.')
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
        else:
            out_content = discord.Embed(type='rich',
                                        color=0xFF9900,
                                        title=':exclamation: Error')
            out_content.add_field(name='User Has Role',
                                  value='The user **' + target_user.name +
                                  '** already has this role.')
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
Beispiel #14
0
async def mute(cmd, message, args):
    channel = message.channel
    server = message.server
    if not message.mentions:
        await cmd.bot.send_message(message.channel, cmd.help())
        return
    user_q = message.mentions[0]
    overwrite = discord.PermissionOverwrite()
    overwrite.send_messages = False
    if message.author is not user_q:
        if check_man_msg(message.author, channel) and check_man_roles(
                message.author, channel):
            if args:
                try:
                    timeout_period = int(args[0])
                except:
                    embed = discord.Embed(
                        color=0xDB0000,
                        title='❗ Invalid number of seconds for the timeout.')
                    await cmd.bot.send_message(message.channel,
                                               None,
                                               embed=embed)
                    return
            else:
                timeout_period = None
            for chan in server.channels:
                if str(chan.type).lower() == 'text':
                    if check_write(user_q, chan):
                        await cmd.bot.edit_channel_permissions(
                            chan, user_q, overwrite)
            embed = discord.Embed(color=0x66CC66,
                                  title='✅ ' + user_q.name + ' muted.')
            await cmd.bot.send_message(message.channel, None, embed=embed)
            if timeout_period:
                await asyncio.sleep(timeout_period)
                for chan in server.channels:
                    if str(chan.type).lower() == 'text':
                        if not check_write(user_q, chan):
                            await cmd.bot.delete_channel_permissions(
                                chan, user_q)
                embed = discord.Embed(color=0x66CC66,
                                      title='✅ ' + user_q.name +
                                      ' can write again.')
                await cmd.bot.send_message(message.channel, None, embed=embed)
        else:
            out_content = discord.Embed(
                type='rich',
                color=0xDB0000,
                title=
                '⛔ Insufficient Permissions. Requires Manage Messages and Manage Roles Permissions.'
            )
            await cmd.bot.send_message(message.channel,
                                       None,
                                       embed=out_content)
async def linkuserprofiles(cmd, message, args):
    args = [arg for arg in args if arg.strip() != '']

    if len(args) < 2:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Missing Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return

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

    account_type = args[1]
    account_link = args[2]

    if (message.author.id != target.id) and not check_man_roles(
            message.author, message.channel):
        embed = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=
            '⛔ Insufficient Permissions. Requires Manage Roles Permission For Modifying Others Users\' Linked Profiles.'
        )
        await message.channel.send(None, embed=embed)
        return

    if (message.author.id == target.id) and not check_man_srv(
            message.author, message.channel):
        try:
            if cmd.db.isModerationDiscordProfileLink(target.id) is True:
                embed = discord.Embed(
                    type='rich',
                    color=0xDB0000,
                    title=
                    '⛔ You have been restricted from modifying your own profile links.'
                )
                await message.channel.send(None, embed=embed)
                return
        except:
            pass  # Profile doesn't exist yet. No moderation control (yet)

    cmd.db.updateDiscordProfileLink(target.id, account_type, account_link)

    embed = discord.Embed(type='rich',
                          color=0x66CC66,
                          title='✅ Linked ' + target.name + '\'s profile to ' +
                          account_type)
    await message.channel.send(None, embed=embed)
async def removelinkeduserprofile(cmd, message, args):
    args = [arg for arg in args if arg.strip() != '']

    if not message.mentions:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Error')
        out_content.add_field(name='Invalid Arguments', value=cmd.help())
        await message.channel.send(None, embed=out_content)
        return

    target = message.mentions[0]
    if len(args) > 1: account_type = args[1]
    else: account_type = None

    if account_type is None:
        if not message.author.id in permitted_id:
            embed = discord.Embed(
                type='rich',
                color=0xDB0000,
                title=
                '⛔ Only Bot Owner can remove the entire user entry. Please specify the specific linked profile to remove instead.'
            )
            await message.channel.send(None, embed=embed)
            return

    if account_type is not None:
        if (message.author.id != target.id) and not check_man_roles(
                message.author, message.channel):
            embed = discord.Embed(
                type='rich',
                color=0xDB0000,
                title=
                '⛔ Insufficient Permissions. Requires Manage Roles Permission For Modifying Others Users\' Linked Profiles.'
            )
            await message.channel.send(None, embed=embed)
            return

    cmd.db.removeDiscordProfileLink(target.id, account_type)

    embed = discord.Embed(type='rich',
                          color=0x66CC66,
                          title='✅ ' + 'Removed profile link(s) for ' +
                          target.name)
    await message.channel.send(None, embed=embed)
Beispiel #17
0
async def clrrole(cmd, message, args):

    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title='⛔ Requires the Manage Roles Permission.')
        await message.channel.send(None, embed=out_content)
        return

    if not args:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Missing Arguments.')
        await message.channel.send(None, embed=out_content)
        return

    qry = ' '.join(args[1:])
    clr = args[0].replace('#', '')

    try:
        clr_int = int(clr, 16)
        clr_obj = discord.Colour(clr_int)
    except:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='❗ Invalid Color. Please use HEX.')
        await message.channel.send(None, embed=out_content)
        return

    role = matching_role(message.guild, qry)
    if not role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='⚠ ' + qry + ' was not found.')
        await message.channel.send(None, embed=out_content)
        return

    await role.edit(color=clr_obj)
    edit_success = discord.Embed(type='rich',
                                 color=0x66cc66,
                                 title='✅ Color Changed.')
    await message.channel.send(None, embed=edit_success)
Beispiel #18
0
async def clrrole(cmd, message, args):
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=':no_entry: Requires the Manage Roles Permission.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    if not args:
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title=':exclamation: Missing Arguments.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    qry = ' '.join(args[1:])
    clr = args[0].replace('#', '')
    try:
        clr_int = int(clr, 16)
        clr_obj = discord.Colour(clr_int)
    except:
        out_content = discord.Embed(
            type='rich',
            color=0xDB0000,
            title=':exclamation: Invalid Color. Please use HEX.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    role = matching_role(message.server, qry)
    if not role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title=':warning: ' + qry +
                                    ' was not found.')
        await cmd.bot.send_message(message.channel, None, embed=out_content)
        return
    await cmd.bot.edit_role(message.server, role, color=clr_obj)
    edit_success = discord.Embed(type='rich',
                                 color=0x66cc66,
                                 title=':white_check_mark: Color Changed.')
    await cmd.bot.send_message(message.channel, None, embed=edit_success)
Beispiel #19
0
async def setcolor(cmd, message, args):
    # if no args, send help message
    if not args:
        await message.channel.send(cmd.help())
        return

    # checks permissions
    if not check_man_roles(message.author, message.channel):
        out_content = discord.Embed(type='rich',
                                    color=0xDB0000,
                                    title='⛔ Error')
        out_content.add_field(name='Insufficient Permissions',
                              value='You require the Manage Roles permission.')
        await message.channel.send(None, embed=out_content)
        return

    color = args[0].lstrip('#').upper()
    # check if color is a proper format
    if not is_valid_hex(color):
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='⚠ Error')
        out_content.add_field(
            name='Invalid Input',
            value=
            'A valid hexadecimal color code has numbers from 0–9 and letters from A–F, and has six characters.'
        )
        await message.channel.send(None, embed=out_content)
        return

    # check if user has role
    target = message.author if not message.mentions else message.mentions[0]
    has_role = discord.utils.get(target.roles,
                                 name=color)  #returns None if no role found
    if has_role:
        out_content = discord.Embed(type='rich',
                                    color=0xFF9900,
                                    title='⚠ Error')
        out_content.add_field(
            name='Role Present',
            value=f'This user already has the role **{color}**.')
        await message.channel.send(None, embed=out_content)
        return

    # check if role exists
    exists = matching_role(message.guild, color)
    if not exists:
        discord_colour = discord.Colour(int(color, 16))
        target_role = await message.guild.create_role(name=color,
                                                      colour=discord_colour,
                                                      reason="Color role")
    else:
        target_role = exists

    # loop through list of user's roles and delete/remove any color roles as necessary
    for role in target.roles:
        if is_valid_hex(role.name):
            if len(role.members) == 1:
                await role.delete()
            else:
                await target.remove_roles(role)

    await target.add_roles(target_role)

    # display confirmation
    out_content = discord.Embed(type='rich',
                                color=int(color, base=16),
                                title='✅ Success')
    out_content.add_field(
        name='Role Added Successfully',
        value=f'Role **{target_role.name}** was added to <@{target.id}>.')
    await message.channel.send(None, embed=out_content)
Beispiel #20
0
async def role(cmd, message, args):
    if not args:
        await cmd.bot.send_message(message.channel, cmd.help())
        return
    else:
        try:
            if check_man_roles(message.author, message.channel):
                if len(args) < 2:
                    await cmd.bot.send_message(message.channel, cmd.help())
                    return
                else:
                    mode_list = ['create', 'destroy', 'give', 'take', 'auto', 'add', 'del']
                    mode = args[0].lower()
                    role_name = ' '.join(args[1:]).lower()
                    if message.mentions:
                        mention_text = ' <@' + message.mentions[0].id + '>'
                        role_name = role_name[:-(len(mention_text))]
                        if role_name.endswith(' '):
                            role_name = role_name[:-1]
                        if role_name.startswith(' '):
                            role_name = role_name[1:]
                    if mode not in mode_list:
                        await cmd.bot.send_message(message.channel, cmd.help())
                        return
                    else:
                        if mode == 'give' or mode == 'take':
                            if not message.mentions:
                                await cmd.bot.send_message(message.channel, cmd.help())
                                return
                            else:
                                target_usr = message.mentions[0]
                                if mode == 'give':
                                    role_choice = None
                                    for role_elem in message.server.roles:
                                        if role_elem.name.lower() == role_name.lower():
                                            role_choice = role_elem
                                    if role_choice is not None:
                                        try:
                                            await cmd.bot.add_roles(target_usr, role_choice)
                                        except Exception as e:
                                            cmd.log.error(e)
                                            await cmd.bot.send_message(message.channel, 'I can not edit the roles of that user.\n' + str(e))
                                            return
                                        await cmd.bot.send_message(message.channel, 
                                            'Role **' + role_name + '** has been given to ' + target_usr.name)
                                    else:
                                        await cmd.bot.send_message(message.channel, 'Role **' + role_name + '** has not been found.')
                                elif mode == 'take':
                                    role_choice = None
                                    for role_elem in message.server.roles:
                                        if role_elem.name.lower() == role_name.lower():
                                            role_choice = role_elem
                                    if role_choice is not None:
                                        try:
                                            await cmd.bot.remove_roles(target_usr, role_choice)
                                        except Exception as e:
                                            cmd.log.error(e)
                                            await cmd.bot.send_message(message.channel, 'I can not edit the roles of that user.\n' + str(e))
                                            return
                                        await cmd.bot.send_message(message.channel, 
                                            'Role **' + role_name + '** has been removed from ' + target_usr.name)
                                    else:
                                        await cmd.bot.send_message(message.channel, 'Role **' + role_name + '** has not been found.')
                        elif mode == 'create':
                            await cmd.bot.create_role(message.server, name=role_name)
                            await cmd.bot.send_message(message.channel, 'Role ' + role_name + ' has been created.')
                        elif mode == 'destroy':
                            role_choice = None
                            for role_elem in message.server.roles:
                                if role_elem.name.lower() == role_name.lower():
                                    role_choice = role_elem
                            if role_choice is not None:
                                await cmd.bot.delete_role(message.server, role_choice)
                                await cmd.bot.send_message(message.channel, 'Role **' + role_name + '** has been destroyed.')
                            else:
                                await cmd.bot.send_message(message.channel, 'Role **' + role_name + '** has not been found.')
                        elif mode == 'add':
                            role_on_server = False
                            for role_res in message.server.roles:
                                if role_name.lower() == role_res.name.lower():
                                    role_on_server = True
                                    break
                            if role_on_server:
                                role_check_results = cmd.db.find('SelfRoles', {'ServerID': message.server.id})
                                rol_exists_in_db = 0
                                self_role_data = {
                                    'ServerID': message.server.id,
                                    'RoleName': role_name
                                }
                                for result in role_check_results:
                                    rol_exists_in_db += 1
                                for result in role_check_results:
                                    rol_exists_in_db = result[0]
                                if rol_exists_in_db == 0:
                                    cmd.db.insert_one('SelfRoles', self_role_data)
                                    await cmd.bot.send_message(message.channel, 'Role **' + role_name + '** added to the self role database.')
                                else:
                                    role_search_data = {
                                        'ServerID': message.server.id,
                                        'RoleName': role_name
                                    }
                                    role_search = cmd.db.find('SelfRoles', role_search_data)
                                    res_count = 0
                                    for role in role_search:
                                        res_count += 1
                                    if res_count == 0:
                                        cmd.db.insert_one('SelfRoles', self_role_data)
                                        await cmd.bot.send_message(message.channel, 
                                            'Role **' + role_name + '** added to the self role database.')
                                    else:
                                        await cmd.bot.send_message(message.channel, 'This role is already in the database.')
                                        return
                        elif mode == 'del':
                            role_on_server = False
                            for role_res in message.server.roles:
                                if role_name.lower() == role_res.name.lower():
                                    role_on_server = True
                                    break
                            if role_on_server:
                                role_search_data = {
                                    'ServerID': message.server.id,
                                    'RoleName': role_name
                                }
                                role_search = cmd.db.find('SelfRoles', role_search_data)
                                res_count = 0
                                for role in role_search:
                                    res_count += 1
                                if res_count == 0:
                                    await cmd.bot.send_message(message.channel, 'This role is not in the database.')
                                else:
                                    cmd.db.delete_one('SelfRoles', role_search_data)
                                    await cmd.bot.send_message(message.channel, 'The role **' + role_name + '** has been removed from the database.')

                        elif mode == 'auto':
                            if check_admin:
                                role_on_server = False
                                for role_res in message.server.roles:
                                    if role_name.lower() == role_res.name.lower():
                                        role_on_server = True
                                        break
                                check_exist = cmd.db.find('AutoRoles', {'ServerID': message.server.id})
                                exists = 0
                                for result in check_exist:
                                    exists += 1
                                if role_name.lower() == 'remove':
                                    if exists == 0:
                                        response = await cmd.bot.send_message(message.channel, 'There are no auto role settings to remove.')
                                        await asyncio.sleep(10)
                                        await cmd.bot.delete_message(response)
                                    else:
                                        cmd.db.delete_one('AutoRoles', {'ServerID': message.server.id})
                                        response = await cmd.bot.send_message(message.channel, 'The auto role has been removed.')
                                        await asyncio.sleep(10)
                                        await cmd.bot.delete_message(response)
                                elif role_name.lower() == 'remove' and exists == 0:
                                    response = await cmd.bot.send_message(message.channel, 'There are no auto role settings to remove.')
                                    await asyncio.sleep(10)
                                    await cmd.bot.delete_message(response)
                                else:
                                    if role_on_server == False:
                                        response = await cmd.bot.send_message(message.channel, 
                                            'The role ' + role_name + ' was not found on the server.')
                                        await asyncio.sleep(10)
                                        await cmd.bot.delete_message(response)
                                    else:
                                        if exists is not 0:
                                            search_data = {
                                                'ServerID': message.server.id,
                                            }
                                            role_name_check = cmd.db.find('AutoRoles', search_data)
                                            role_name_res = None
                                            for name in role_name_check:
                                                role_name_res = name['RoleName']
                                            if role_name_res.lower() == role_name.lower():
                                                response = await cmd.bot.send_message(message.channel, 
                                                    'That role is the current Auto Role already.')
                                                await asyncio.sleep(10)
                                                await cmd.bot.delete_message(response)
                                            else:
                                                update_query = {'$set': {
                                                    'RoleName': role_name
                                                }}
                                                cmd.db.update_one('AutoRoles', {'ServerID': message.server.id}, update_query)
                                                response = await cmd.bot.send_message(message.channel, 'The auto role has been updated.')
                                                await asyncio.sleep(10)
                                                await cmd.bot.delete_message(response)
                                        else:
                                            add_qry = {
                                                'ServerID': message.server.id,
                                                'RoleName': role_name
                                            }
                                            cmd.db.insert_one('AutoRoles', add_qry)
                                            response = await cmd.bot.send_message(message.channel, 
                                                'The auto role **' + role_name + '** has been set for ' + message.server.name + '.')
                                            await asyncio.sleep(10)
                                            await cmd.bot.delete_message(response)
                        else:
                            response = await cmd.bot.send_message(message.channel, 
                                'Only a user with **Administrator** privileges can use this function. :x:')
                            await asyncio.sleep(10)
                            await cmd.bot.delete_message(response)
            else:
                response = await cmd.bot.send_message(message.channel, 'Only a user with the **Manage Roles** privilege can use this command. :x:')
                await asyncio.sleep(10)
                await cmd.bot.delete_message(response)
        except SyntaxError as e:
            cmd.log.error(e)
            await cmd.bot.send_message(message.channel, 'We\'ve ran into an error.\n' + str(e))