async def autorole(cmd, message, args): if message.author.permissions_in(message.channel).manage_guild: if args: lookup = ' '.join(args) if lookup.lower() != 'disable': target_role = matching_role(message.guild, lookup) if target_role: role_bellow = bool(target_role.position < message.guild.me.top_role.position) if role_bellow: cmd.db.set_guild_settings(message.guild.id, 'AutoRole', target_role.id) response = discord.Embed(color=0x77B255, title=f'✅ {target_role.name} is now the autorole.') else: response = discord.Embed(color=0xBE1931, title='❗ This role is above my highest role.') else: response = discord.Embed(color=0x696969, title=f'🔍 I can\'t find {lookup} on this server.') else: cmd.db.set_guild_settings(message.guild.id, 'AutoRole', None) response = discord.Embed(color=0x77B255, title=f'✅ Autorole has been disabled.') else: curr_role_id = cmd.db.get_guild_settings(message.guild.id, 'AutoRole') if curr_role_id: curr_role = discord.utils.find(lambda x: x.id == curr_role_id, message.guild.roles) if curr_role: response = discord.Embed(color=0xF9F9F9, title=f'📇 The current autorole is **{curr_role}**.') else: response = discord.Embed(color=0xBE1931, title='❗ An autorole is set but was not found.') else: response = discord.Embed(color=0xF9F9F9, title='📇 No autorole set.') else: response = discord.Embed(title='⛔ Access Denied. Manage Server needed.', color=0xBE1931) await message.channel.send(embed=response)
async def togglerole(cmd, message, args): if args: lookup = ' '.join(args) target_role = matching_role(message.guild, lookup) if target_role: self_roles = cmd.db.get_guild_settings(message.guild.id, 'SelfRoles') if self_roles is None: self_roles = [] if target_role.id in self_roles: role_bellow = bool(target_role.position < message.guild.me.top_role.position) if role_bellow: user_role_match = user_matching_role(message.author, target_role.name) if not user_role_match: await message.author.add_roles(target_role, reason='Role self assigned.') addition_title = f'✅ {target_role.name} has been **added** to you.' response = discord.Embed(color=0x77B255, title=addition_title) else: await message.author.remove_roles(target_role, reason='Role self assigned.') removal_title = f'💣 {target_role.name} has been **removed** from you.' response = discord.Embed(color=0x262626, title=removal_title) else: role_hierarchy_error = '❗ This role is above my highest role. I can not manage it.' response = discord.Embed(color=0xBE1931, title=role_hierarchy_error) else: response = discord.Embed(color=0xFFCC4D, title=f'⚠ {target_role} is not self assignable.') else: response = discord.Embed(color=0x696969, title=f'🔍 I can\'t find {lookup} on this server.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') await message.channel.send(embed=response)
async def removerole(cmd, message, args): if message.author.permissions_in(message.channel).manage_roles: if args: if len(args) >= 2: if message.mentions: target = message.mentions[0] lookup = ' '.join(args[1:]) role = matching_role(message.guild, lookup) if role: permit_self = (message.guild.me.top_role.position >= role.position) if permit_self: user_has_role = user_matching_role(target, lookup) if user_has_role: author = f'{message.author.name}#{message.author.discriminator}' await target.remove_roles(role, reason=f'Role removed by {author}.') title = f'✅ {role.name} has been removed from {target.name}.' response = discord.Embed(color=0x77B255, title=title) else: response = discord.Embed(color=0xBE1931, title='❗ User does not have this role.') else: response = discord.Embed(color=0xBE1931, title='❗ That role is above me.') else: response = discord.Embed(color=0xBE1931, title=f'❗ I couldn\'t find {lookup}.') else: response = discord.Embed(color=0xBE1931, title='❗ No user targetted.') else: response = discord.Embed(color=0xBE1931, title='❗ Not enough arguments.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') else: response = discord.Embed(title='⛔ Access Denied. Manage Roles needed.', color=0xBE1931) await message.channel.send(embed=response)
async def unpermitrole(cmd, message, args): if args: if len(args) >= 2: if not message.author.permissions_in(message.channel).manage_guild: response = discord.Embed(title='⛔ Access Denied. Manage Server needed.', color=0xBE1931) else: target_name = args[1] target = matching_role(message.guild, target_name) if target: error_response = discord.Embed(color=0xBE1931, title='❗ Bad Input') try: perm_mode, cmd_name = args[0].split(':') except Exception: await message.channel.send(embed=error_response) return cmd_name = cmd_name.lower() perm_mode = perm_mode.lower() if perm_mode == 'c': exception_group = 'CommandExceptions' check_group = cmd.bot.modules.commands check_alts = True elif perm_mode == 'm': exception_group = 'ModuleExceptions' check_group = cmd.bot.modules.categories check_alts = False else: await message.channel.send(embed=error_response) return if check_alts: if cmd_name in cmd.bot.modules.alts: cmd_name = cmd.bot.modules.alts[cmd_name] if cmd_name in check_group: perms = get_all_perms(cmd.db, message) cmd_exc = perms[exception_group] if cmd_name in perms[exception_group]: inner_exc = cmd_exc[cmd_name] else: inner_exc = generate_cmd_data(cmd_name)[cmd_name] exc_usrs = inner_exc['Roles'] if target.id in exc_usrs: exc_usrs.remove(target.id) inner_exc.update({'Roles': exc_usrs}) cmd_exc.update({cmd_name: inner_exc}) perms.update({exception_group: cmd_exc}) cmd.db[cmd.db.db_cfg.database].Permissions.update_one({'ServerID': message.guild.id}, {'$set': perms}) response = discord.Embed(color=0x77B255, title=f'✅ `{target.name}` can no longer use `{cmd_name}`.') else: response = discord.Embed(color=0xFFCC4D, title=f'⚠ {target.name} is not able to use `{cmd_name}`') else: response = discord.Embed(color=0x696969, title='🔍 Command/Module Not Found') else: response = discord.Embed(color=0x696969, title=f'🔍 No {target_name} Role Found') else: response = discord.Embed(color=0xBE1931, title='❗ Not Enough Arguments') else: response = discord.Embed(color=0xBE1931, title='❗ Not Arguments Given') await message.channel.send(embed=response)
async def addselfrole(cmd, message, args): if message.author.permissions_in(message.channel).manage_roles: if args: lookup = ' '.join(args) target_role = matching_role(message.guild, lookup) if target_role: role_bellow = bool( target_role.position < message.guild.me.top_role.position) if role_bellow: selfroles = cmd.db.get_guild_settings( message.guild.id, 'SelfRoles') if selfroles is None: selfroles = [] if target_role.id in selfroles: response = discord.Embed( color=0xBE1931, title='❗ This role is already self assignable.') else: selfroles.append(target_role.id) cmd.db.set_guild_settings(message.guild.id, 'SelfRoles', selfroles) response = discord.Embed( color=0x77B255, title=f'✅ {target_role.name} added.') else: response = discord.Embed( color=0xBE1931, title='❗ This role is above my highest role.') else: response = discord.Embed( color=0x696969, title=f'🔍 I can\'t find {lookup} on this server.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') else: response = discord.Embed(title='⛔ Access Denied. Manage Roles needed.', color=0xBE1931) await message.channel.send(embed=response)
async def togglerole(cmd, message, args): if args: lookup = ' '.join(args) target_role = matching_role(message.guild, lookup) if target_role: selfroles = cmd.db.get_guild_settings(message.guild.id, 'SelfRoles') if selfroles is None: selfroles = [] if target_role.id in selfroles: user_role_match = user_matching_role(message.author, target_role.name) if not user_role_match: await message.author.add_roles( target_role, reason='Role self assigned.') response = discord.Embed( color=0x77B255, title=f'✅ {target_role.name} has been **added** to you.' ) else: await message.author.remove_roles( target_role, reason='Role self assigned.') response = discord.Embed( color=0x77B255, title= f'✅ {target_role.name} has been **removed** from you.') else: response = discord.Embed( color=0xFF9900, title=f'⚠ {target_role} is not self assignable.') else: response = discord.Embed( color=0x696969, title=f'🔍 I can\'t find {lookup} on this server.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') await message.channel.send(embed=response)