async def setup_help_pag(self, ctx, entity=None, title=None): entity = entity or self.client title = title or self.client.description pages = [] if isinstance(entity, commands.Command): filtered_commands = (list(set(entity.all_commands.values())) if hasattr(entity, "all_commands") else []) filtered_commands.insert(0, entity) else: filtered_commands = await self.return_filtered_commands( entity, ctx) for i in range(0, len(filtered_commands), self.cmds_per_page): next_commands = filtered_commands[i:i + self.cmds_per_page] commands_entry = "" for cmd in next_commands: desc = cmd.short_doc or cmd.description signature = self.get_command_signature(cmd, ctx) subcommand = "Has subcommands" if hasattr( cmd, "all_commands") else "" commands_entry += ( f"• **__{cmd.name}__**\n```\n{signature}\n```\n{desc}\n" if isinstance(entity, commands.Command) else f"• **__{cmd.name}__**\n{desc}\n {subcommand}\n") pages.append(commands_entry) book = reactionbook(self.client, ctx, TITLE=title) book.createpages(pages, ITEM_PER_PAGE=True) await book.createbook(MODE="numbers", COLOUR=0xCE2029, TIMEOUT=180)
async def status(self, ctx): user = ctx.author db.addchannel(ctx.channel.id, ctx.guild.id) guild_id = ctx.guild.id channels = db.getallstatus(guild_id) view_channel = "self.bot.get_channel(%0).overwrites_for(self.ctx.guild.default_role).pair()[1].view_channel" modtoggle = db.getmodtoggle(ctx.guild.id) priority = db.getpriority(ctx.guild.id) header = f"{circle[modtoggle]} Modtoggle is `{modtoggle}`\n{volume[priority]} Responds to `{priority}`" colour = self.bot.get_colour(user.id) book = reactionbook(self.bot, ctx, TITLE="FBot Status") book.createpages(channels, "<#%0>", EMPTY=emptyon, SUBHEADER=on, check1=("%1", "on"), subcheck1=(view_channel, False)) book.createpages(channels, "<#%0>", EMPTY=emptyoff, SUBHEADER=off, check1=("%1", "off"), subcheck1=(view_channel, False)) await book.createbook(HEADER=header, COLOUR=colour)
async def modstatus(self, ctx): user = ctx.author db.addchannel(ctx.channel.id, ctx.guild.id) if not ctx.author.guild_permissions.administrator: await ctx.reply( "Only members with administrator privileges can toggle this") return guild = ctx.guild channels = db.getallstatus(guild.id) modtoggle = db.getmodtoggle(ctx.guild.id) priority = db.getpriority(ctx.guild.id) header = f"{circle[modtoggle]} Modtoggle is `{modtoggle}`\n{volume[priority]} Responds to `{priority}`" colour = self.bot.get_colour(user.id) book = reactionbook(self.bot, ctx, TITLE="FBot Mod Status") book.createpages(channels, "<#%0>", EMPTY=emptyon, SUBHEADER=on, check1=("%1", "on")) book.createpages(channels, "<#%0>", EMPTY=emptyoff, SUBHEADER=off, check1=("%1", "off")) await book.createbook(HEADER=header, COLOUR=colour)
async def _await(self, CTX, *, content): global bot, ctx bot, ctx = self.bot, CTX exec( f"global function\nasync def function():\n result = await {content}\n if result: return result" ) colour = self.bot.get_colour(ctx.author.id) book = reactionbook(self.bot, ctx, TITLE="FBot Eval") try: result = str(await function()) except Exception as e: result = "".join(format_exception(e, e, e.__traceback__)) pages = [] content = f"Input:\n```py\nawait {content}```\n" if result: for i in range(0, len(result), 2000): pages.append(f"Output:\n```py\n{result[i:i + 2000]}\n```") if len(content + pages[0]) > 2000: pages.insert(0, content) else: pages[0] = content + pages[0] book.createpages(pages, ITEM_PER_PAGE=True) else: book.createpages(content) await book.createbook(MODE="arrows", COLOUR=colour, TIMEOUT=180)
async def eval(self, ctx, *, content): bot = self.bot ftime = bot.ftime cache = bot.cache channel = ctx.channel author = ctx.author message = ctx.message if str(channel.type) != "private": guild = ctx.guild colour = self.bot.get_colour(ctx.author.id) book = reactionbook(self.bot, ctx, TITLE="FBot Eval") try: result = str(eval(content)) except Exception as e: result = "".join(format_exception(e, e, e.__traceback__)) pages = [] content = f"Input:\n```py\n{content}```\n" for i in range(0, len(result), 2000): pages.append(f"Output:\n```py\n{result[i:i + 2000]}\n```") if len(content + pages[0]) > 2000: pages.insert(0, content) else: pages[0] = content + pages[0] book.createpages(pages, ITEM_PER_PAGE=True) await book.createbook(MODE="arrows", COLOUR=colour, TIMEOUT=180)
async def devcmds(self, ctx): colour = self.bot.get_colour(ctx.author.id) book = reactionbook(self.bot, ctx, LINES=20) book.createpages(cm.devcmdlist, LINE="`%0`", SUBHEADER="**__FBot Dev Commands__**\n") await book.createbook(MODE="numbers", COLOUR=colour)
async def servers(self, ctx): guilds = [] members = 0 for guild in self.bot.guilds: guilds.append([guild.member_count, guild.name, guild.id]) members += guild.member_count guilds.sort(reverse=True) colour = self.bot.get_colour(ctx.author.id) book = reactionbook(self.bot, ctx, TITLE="FBot Servers") book.createpages(guilds, f"`%1`: **%0**") await book.createbook(SHOW_RESULTS=True, COLOUR=colour)
async def cogs(self, ctx): colour = self.bot.get_colour(ctx.author.id) check = "'%l'[:-3] in self.bot.cogs" empty = "All cogs loaded" book = reactionbook(self.bot, ctx, TITLE="FBot Cogs") book.createpages(fn.getcogs(), EMPTY=empty, SUBHEADER="**Loaded:**", check1=(check, True)) book.createpages(fn.getcogs(), EMPTY=empty, SUBHEADER="**Not Loaded:**", check1=(check, False)) await book.createbook(MODE="numbers", COLOUR=colour)
async def search(self, ctx, *, query): matches = [] query = query.lower() for guild in self.bot.guilds: if query in guild.name.lower(): to_append = (guild.name, guild.id) matches.append(to_append) if matches: colour = self.bot.get_colour(ctx.author.id) book = reactionbook(self.bot, ctx, TITLE="FBot Search") matches.sort() book.createpages(matches, "`%0` - `%1`") await book.createbook(SHOW_RESULTS=True, COLOUR=colour) else: embed = self.bot.embed(ctx.author, "FBot Search", f"No matches found for `{query}`") await ctx.send(embed=embed)
async def on_command_error(self, ctx, error): if hasattr(ctx.command, "on_error"): return cog = ctx.cog if cog: if cog._get_overridden_method(cog.cog_command_error) is not None: return error_type = type(error) if error_type is commands.CommandNotFound: return elif error_type is commands.MissingPermissions: return elif error_type is commands.NotOwner: return elif error_type is commands.MessageNotFound: return elif error_type is commands.DisabledCommand: await ctx.reply("**This command is disabled.** If you'd like to find out more join our support server") elif error_type is commands.BadArgument: await ctx.reply("**Bad argument.** Whoops! Looks like one of the arguments you entered is a bit off...") elif error_type is commands.MissingRequiredArgument: await ctx.reply("**Command missing an argument.** Whoops! You've missed an argument for this command") elif error_type is commands.NoPrivateMessage: await ctx.reply("**Server only command.** This command can only be used in a server") elif error_type is commands.UserNotFound: await ctx.reply("**No user found.** Hmm we couldn't find that user, maybe try something else") elif error_type is commands.CommandOnCooldown: retry = round(error.retry_after, 2) await ctx.reply(f"**You're on cooldown!.** Please wait `{retry}s` to use this command", delete_after=5) elif error_type is commands.CheckFailure: error = str(error) errorlines = error.split("\n") embed = self.bot.embed(fn.user, errorlines[0], *errorlines[2:]) try: try: await ctx.send(embed=embed) except: await ctx.reply(error) except: try: channel = await ctx.author.create_dm() await channel.send(embed=embed) except: pass elif error_type is commands.UserNotFound: await ctx.reply("User not found") elif error_type is commands.ChannelNotFound: await ctx.reply("Channel not found") elif error_type is commands.GuildNotFound: await ctx.reply("Guild not found") else: if error_type is commands.CommandInvokeError: if type(error.original) is discord.Forbidden: error = error.original if error.text == "Missing Permissions": try: await ctx.reply("FBot is missing permissions to complete this action") except: channel = await ctx.author.create_dm() await channel.send(f"FBot doesn't have permissions to send messages in <#{ctx.message.id}>") return elif type(error.original) is discord.errors.NotFound: if error.original.text == "Unknown User": await ctx.reply("Looks like that member doesn't exist") return await ctx.reply(error.original.text) embed = self.bot.embed( ctx.author, "An unusual error has occurred", "The devs have been notified, please contact:\n" "`@justjude#2296` or `@Lines#9260`\nOR join our " f"[support server]({fn.links.server}) and give us a ping" ) try: await ctx.send(embed=embed) except: try: channel = await ctx.author.create_dm() await channel.send(embed=embed) except: pass ctx.channel = self.errorlogs book = reactionbook(self.bot, ctx, TITLE="Error Log") result = "".join(format_exception(error, error, error.__traceback__)) pages = [] content = f"Error on message:\n```{ctx.message.content}```" content += f"```by {ctx.message.author.name} ({ctx.message.author.id})```" content += f"```{ctx.message.channel.type} channel (server: {ctx.message.guild})```" for i in range(0, len(result), 2000): pages.append(f"```py\n{result[i:i + 1000]}\n```") if len(content + pages[0]) > 2000: pages.insert(0, content) else: pages[0] = content + pages[0] book.createpages(pages, ITEM_PER_PAGE=True) await book.createbook(MODE="arrows", COLOUR=fn.colours.red, TIMEOUT=180)