async def unpermit(cmd, pld): """ :param cmd: The command object referenced in the command. :type cmd: sigma.core.mechanics.command.SigmaCommand :param pld: The payload with execution data and details. :type pld: sigma.core.mechanics.payload.CommandPayload """ if pld.msg.author.permissions_in(pld.msg.channel).manage_guild: if pld.args: if len(pld.args) >= 3: if ':' in pld.args[1]: target_type = get_target_type(pld.args[0].lower()) if target_type: perm_mode = pld.args[1].split(':')[0].lower() node_name = pld.args[1].split(':')[1].lower() modes = { 'c': ('command_exceptions', cmd.bot.modules.commands, True), 'm': ('module_exceptions', cmd.bot.modules.categories, False) } mode_vars = modes.get(perm_mode) if mode_vars: exc_group, check_group, check_alts = mode_vars targets, valid_targets = get_targets(pld.msg, pld.args, target_type) if valid_targets: perms = await get_all_perms(cmd.db, pld.msg) if check_alts: if node_name in cmd.bot.modules.alts: node_name = cmd.bot.modules.alts[node_name] if node_name in check_group: node_exc = perms[exc_group] if node_name in perms[exc_group]: inner_exc = node_exc[node_name] else: inner_exc = generate_cmd_data(node_name)[node_name] exc_usrs = inner_exc[target_type] bad_item = None for target in targets: if target.id in exc_usrs: exc_usrs.remove(target.id) inner_exc.update({target_type: exc_usrs}) node_exc.update({node_name: inner_exc}) perms.update({exc_group: node_exc}) else: bad_item = target break if not bad_item: await cmd.db.cache.del_cache(pld.msg.guild.id) await cmd.db[cmd.db.db_nam].Permissions.update_one( {'server_id': pld.msg.guild.id}, {'$set': perms} ) if len(targets) > 1: title = f'{len(targets)} {target_type} can no longer use `{node_name}`.' response = ok(title) else: pnd = '#' if target_type == 'channels' else '' response = ok(f'{pnd}{targets[0].name} can no longer use `{node_name}`.') else: pnd = '#' if target_type == 'channels' else '' title = f'{pnd}{bad_item.name} didn\'t have an override for `{node_name}`.' response = warn(title) else: perm_type = 'Command' if perm_mode == 'c' else 'Module' response = not_found(f'{perm_type} not found.') else: if targets: response = not_found(f'{targets} not found.') else: ender = 'specified' if target_type == 'roles' else 'targeted' response = not_found(f'No {target_type} {ender}.') else: response = error('Unrecognized lookup mode, see usage example.') else: response = error('Invalid target type.') else: response = error('Separate permission type and name with a colon.') else: response = error('Not enough arguments.') else: response = error('Nothing inputted.') else: response = denied('Access Denied. Manage Server needed.') await pld.msg.channel.send(embed=response)
async def unpermitrole(cmd: SigmaCommand, message: discord.Message, args: list): if args: if len(args) >= 2: if not message.author.permissions_in(message.channel).manage_guild: response = permission_denied('Manage Server') else: target_name = ' '.join(args[1:]) target = discord.utils.find( lambda x: x.name.lower() == target_name.lower(), message.guild.roles) if target: error_response = discord.Embed(color=0xBE1931, title='❗ Bad input.') try: perm_mode, cmd_name = args[0].split(':') except ValueError: await message.channel.send(embed=error_response) return cmd_name = cmd_name.lower() perm_mode = perm_mode.lower() if perm_mode == 'c': exception_group = 'command_exceptions' check_group = cmd.bot.modules.commands check_alts = True elif perm_mode == 'm': exception_group = 'module_exceptions' 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 = await 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}) await cmd.db[cmd.db.db_nam].Permissions.update_one( {'server_id': message.guild.id}, {'$set': perms}) scp_cache.del_cache(message.guild.id) 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: perm_type = 'Command' if perm_mode == 'c' else 'Module' response = discord.Embed( color=0x696969, title=f'🔍 {perm_type} not found.') else: response = discord.Embed( color=0x696969, title=f'🔍 {target_name} not found.') else: response = discord.Embed(color=0xBE1931, title='❗ Not enough arguments.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') await message.channel.send(embed=response)
async def permitchannel(cmd: SigmaCommand, message: discord.Message, args: list): if args: if len(args) >= 2: if not message.author.permissions_in(message.channel).manage_guild: response = permission_denied('Manage Server') else: if message.channel_mentions: targets = message.channel_mentions error_response = discord.Embed(color=0xBE1931, title='❗ Bad input.') try: perm_mode, cmd_name = args[0].split(':') except ValueError: 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 = await 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['Channels'] bad_item = False for target in targets: if target.id in exc_usrs: bad_item = target break else: exc_usrs.append(target.id) inner_exc.update({'Channels': exc_usrs}) cmd_exc.update({cmd_name: inner_exc}) perms.update({exception_group: cmd_exc}) if bad_item: response_title = f'⚠ #{bad_item.name} can already use `{cmd_name}`.' response = discord.Embed(color=0xFFCC4D, title=response_title) else: await cmd.db[cmd.db.db_nam].Permissions.update_one( {'ServerID': message.guild.id}, {'$set': perms}) scp_cache.del_cache(message.guild.id) if len(targets) > 1: response_title = f'✅ {len(targets)} channels can now use `{cmd_name}`.' else: response_title = f'✅ #{targets[0].name} can now use `{cmd_name}`.' response = discord.Embed(color=0x77B255, title=response_title) else: perm_type = 'Command' if perm_mode == 'c' else 'Module' response = discord.Embed( color=0x696969, title=f'🔍 {perm_type} not found.') else: response = discord.Embed(color=0x696969, title=f'🔍 No channel targeted.') else: response = discord.Embed(color=0xBE1931, title='❗ Not enough arguments.') else: response = discord.Embed(color=0xBE1931, title='❗ Nothing inputted.') await message.channel.send(embed=response)