async def greetings(self, ctx, command: str = None, *args): if (len(args) != 0) or (command not in ['config', 'demo', 'reset']): prefix = get_prefix(self.bot, ctx.message) await ctx.send(embed=create_help_embed(self.help, prefix)) elif command == 'config': await self.config(ctx) elif command == 'demo': await self.demo(ctx) elif command == 'reset': await self.reset(ctx)
async def nicknames(self, ctx, command: str = None, *args): if command in ['add', 'change', 'insert', 'set', 'update' ] and len(args) > 1: await self.insert_or_update_nickname(ctx, args) elif command in ['del', 'delete', 'remove', 'rm'] and len(args) >= 1: await self.delete_nickname(ctx, args) elif command in ['all', 'list', 'ls', 'show'] and len(args) == 0: await self.list_nicknames(ctx) else: prefix = get_prefix(self.bot, ctx.message) await ctx.send(embed=create_help_embed(self.help, prefix))
async def rewrite(self, ctx, command: str = None, *args): if not ctx.author.guild_permissions.administrator: await ctx.send(embed=create_basic_embed( "Sorry, you aren't authorized to use that command!", EMOJI_ERROR)) elif command == 'post' and len(args) == 2: await Rewrite.post(ctx, args[0], args[1]) elif command == 'edit' and len(args) == 1: await Rewrite.edit(ctx, args[0]) elif command == 'replace' and len(args) == 2: await Rewrite.replace(ctx, args[0], args[1]) else: prefix = get_prefix(self.bot, ctx.message) await ctx.send(embed=create_help_embed(self.help, prefix))
async def show_help(bot: Bot, message: Message): if not await Permissions.check(bot, Permission.VIEW_HELP, message.guild, message.channel): await message.channel.send( embed=create_error_embed(TEXT_MISSING_PERMISSION)) return help_cogs = [] for cog_name, cog_object in bot.cogs.items(): if hasattr(cog_object, 'help') and not callable(getattr(cog_object, 'help')): help_cogs.append((cog_name, cog_object)) help_cogs.sort() await message.channel.send(embed=create_help_embed( Help.build_help_dict(help_cogs), get_prefix(bot, message)))
async def events(self, ctx, command: str = None, *args): if command == 'template' and len(args) == 0: await ctx.send(FORMAT_JSON.format(Event().to_json())) elif command == 'create' and len(args) == 1: await self.create_event(ctx, args[0]) elif command == 'new' and len(args) == 0: # TODO: Document and implement this - interactive event creation session. pass elif command == 'edit' and len(args) == 1: pass elif command == 'copy' and len(args) == 2: pass elif command == 'open' and len(args) == 1: pass elif command == 'close' and len(args) == 1: pass else: prefix = get_prefix(self.bot, ctx.message) await ctx.send(embed=create_help_embed(self.help, prefix))
async def show_details(self, ctx: Context, permission: Permission): server = ctx.guild permission_config = await self.get_permission_config_for_server( server.id, permission) embed_text = DETAILS_TITLE_FORMAT.format(permission.name) if not permission_config.is_enabled: embed_text += DETAILS_STATUS_LABEL_FORMAT.format( EMOJI_PERMISSION_DISABLED) embed_text += DETAILS_STATUS_DISABLED_FORMAT.format(server.name) elif not permission_config.whitelisted_channel_ids: embed_text += DETAILS_STATUS_LABEL_FORMAT.format( EMOJI_PERMISSION_ENABLED) embed_text += DETAILS_STATUS_ENABLED_FORMAT.format(server.name) else: embed_text += DETAILS_STATUS_LABEL_FORMAT.format( EMOJI_PERMISSION_RESTRICTED) if len(permission_config.whitelisted_channel_ids) == 1: whitelisted_channel_id = next( iter(permission_config.whitelisted_channel_ids)) embed_text += DETAILS_STATUS_RESTRICTED_SINGULAR_FORMAT.format( whitelisted_channel_id) else: embed_text += DETAILS_STATUS_RESTRICTED_PLURAL + permission_config.get_channel_whitelist_display_text( ) embed_text += DETAILS_COMMANDS_LABEL commands = permission.display_commands # TODO: Also display a description of what each of these commands does (e.g. from their 'help' menu). if commands: prefix = get_prefix(self.bot, ctx.message) embed_text += ' '.join( DETAILS_COMMANDS_VISIBLE_FORMAT.format(prefix, command) for command in commands) else: embed_text += DETAILS_COMMANDS_HIDDEN await ctx.send( embed=create_basic_embed(embed_text, EMOJI_PERMISSION_DETAILS))
async def permissions(self, ctx: Context, command: str = None, *args): prefix = get_prefix(self.bot, ctx.message) # The VIEW_PERMISSIONS permission is required for all commands in this module. if not await Permissions.check(self.bot, Permission.VIEW_PERMISSIONS, ctx.guild, ctx.channel): await ctx.send(embed=create_error_embed(TEXT_MISSING_PERMISSION)) return if (not command) or (command == 'help'): await ctx.send(embed=create_help_embed(self.help, prefix)) return # Many aliases for this command are given in case the user gets confused about where to find permission names. if command in ('overview', 'ov', 'list', 'ls', 'all', 'names'): await self.show_overview(ctx) return # If a permission name is given as a "command" with no arguments, just show the details for that permission. if command and (command.upper() in VALID_PERMISSION_NAMES) and (not args): await self.show_details(ctx, Permission[command.upper()]) return if command not in ('details', 'enable', 'disable', 'toggle'): error_text = ERROR_INVALID_COMMAND_TEXT_FORMAT.format(command) error_hint = ERROR_INVALID_COMMAND_HINT_FORMAT.format(prefix) await ctx.send(embed=create_error_embed(error_text, error_hint)) return # All remaining possible commands require a permission name to be specified, so try to form one out of the args. possible_permission_name = '_'.join( arg for arg in args if '#' not in arg).replace(' ', '_').upper() if not possible_permission_name: await ctx.send(embed=create_error_embed( ERROR_UNSPECIFIED_PERMISSION_FORMAT.format(command))) return if possible_permission_name not in VALID_PERMISSION_NAMES: error_text = ERROR_INVALID_PERMISSION_TEXT_FORMAT.format( possible_permission_name) error_hint = ERROR_INVALID_PERMISSION_HINT_FORMAT.format(prefix) await ctx.send(embed=create_error_embed(error_text, error_hint)) return # This is guaranteed to be a valid permission because all of the above checks have passed. target_permission = Permission[possible_permission_name] if command == 'details': await self.show_details(ctx, target_permission) return # The CHANGE_PERMISSIONS permission is required for all remaining possible commands. if not await Permissions.check(self.bot, Permission.CHANGE_PERMISSIONS, ctx.guild, ctx.channel): await ctx.send(embed=create_error_embed(TEXT_MISSING_PERMISSION)) elif command == 'enable': await self.enable_permission(ctx, target_permission) elif command == 'disable': await self.disable_permission(ctx, target_permission) elif command == 'toggle' and ctx.message.channel_mentions: await self.toggle_permission_for_channel( ctx, target_permission, ctx.message.channel_mentions) else: await ctx.send(embed=create_error_embed(ERROR_UNSPECIFIED_CHANNEL))