async def get_command_permission(self, ctx, guildid, command_name=None): if command_name: # 有指定指令名稱,將名稱轉為id command_id = self.cmd_mapping(command_name) else: command_id = None r = get_command_permissions(guildid, command_id) # 權限列表 if type(r) is list: r = list(map(Dict, r)) commands = [] guild = f"`{self.bot.get_guild(int(guildid)).name}`" + f"(`{guildid}`)" # 取得伺服器名稱 # 將權限列表整理成{command_name : {name : [權限]}} for command in r: cmd_name = self.cmd_mapping(command.id) permissions = [] # 整理每個人的權限 for permission in command.permissions: name = self.get_name(permission.type, int(permission["id"]), int(guildid)) permissions.append({f"`{name}`": permission.permission}) commands.append({f"`{cmd_name}`": permissions}) await ctx.send( yaml.safe_dump({guild: commands}, indent=4, allow_unicode=True), hidden=True, ) else: await ctx.send("request failed", hidden=True)
async def send_bot_help(self, mapping): embed = discord.Embed( title=self.context.s("general.help_command_list_header"), url=self.context.s("general.wiki")) filtered = await self.filter_commands( self.context.bot.commands, sort=True, key=GlimmerHelpCommand.get_category) for cat, cmds in itertools.groupby( filtered, key=lambda command: command.cog_name): cmds = sorted(cmds, key=lambda x: x.name) if len(cmds) > 0: commands = [] for c in cmds: url = "{}{}#{}".format(self.context.s("general.wiki"), GlimmerHelpCommand.get_category(c), c.qualified_name) commands.append(f"[{c.name}]({url})") embed.add_field(name=cat, value=", ".join(commands)) embed.set_footer(text=self.context.s("general.help_footer").format( self.clean_prefix)) await self.get_destination().send(embed=embed)
async def send_group_help(self, group): cog_name = group.cog_name if cog_name is not None and group.cog_name.lower() == group.name.lower( ): await self.send_cog_help(group.cog) return commands = [] seen = [] for command in group.walk_commands(): if command in seen: continue seen.append(command) pack = await self.package_command(command) if pack is None: continue commands.append(pack) # if we found no commands, just stop here if not commands: await self.stop() return self.pager.add_page(group.cog_name, group.cog.__doc__, commands) await self.pager.go()
async def toggle_mods_only(self, ctx, *_commands): """Toggle mods only commands.""" commands = [] for cmd in _commands: cmd = self.bot.get_command(str(cmd)) if cmd: commands.append(cmd.qualified_name) settings = self.get_mods_only(ctx) or [] enabled = [] disabled = [] for cmd in commands: if cmd in settings: settings.remove(cmd) enabled.append(cmd) else: settings.append(cmd) disabled.append(cmd) settings = ",".join(settings) if not settings: settings = None self.bot.c.execute( "UPDATE settings SET mods_only = ? WHERE id = ?", (settings, str(ctx.guild.id)), ) self.bot.conn.commit() if enabled: await em_ctx_send_success( ctx, f"`{', '.join(enabled)}` is no longer mods only!" ) if disabled: await em_ctx_send_success(ctx, f"`{', '.join(disabled)}` is now mods only!")
async def list_disabled_commands(self, ctx): try: disabled_commands = await database.fetch_guild_disabled_commands(ctx.guild.id) except ServerSelectionTimeoutError as e: embed = discord.Embed( title=f"Error listing disabled commands: { type(e).__name__ }", colour=discord.Color.red(), description=f"{ e }" ) return await ctx.send(embed=embed) except AttributeError as e: embed = discord.Embed( title=f"Guild does not exist in db", colour=discord.Color.red(), description=f"Could not find properties for guild `{ ctx.guild.name }` in database" ) return await ctx.send(embed=embed) commands = [] for command in disabled_commands: commands.append(f"- { command }") commands_string = "\n" + "\n".join(commands) embed = discord.Embed( title=f"Disabled commands for { ctx.guild.name }", colour=discord.Color.blue(), description=f"{ commands_string }" ) return await ctx.send(embed=embed)
async def format_cog_help(self, ctx, prefix, cog): em = discord.Embed(title=cog.__class__.__name__, description=cog.__doc__ or "", color=0x7289da) commands = [] fmt = '' # maxlen = 0 for i in inspect.getmembers(cog, predicate=lambda x: isinstance(x, (RainCommand, RainGroup))): if i[1].parent: # Ignore subcommands continue if await self.can_run(ctx, i[1]): commands.append(i[1]) # for i in commands: # cmdlen = len(f'`{prefix}{i.name}`') # if cmdlen > maxlen: # maxlen = cmdlen for i in commands: # cmdlen = len(f'`{prefix}{i.name}`') # proposed_fmt = fmt + f"`{prefix}{i.name}` {' ' * (maxlen - cmdlen)}{i.short_doc}\n" proposed_fmt = fmt + f"`{prefix}{i.name}` {i.short_doc}\n" if len(proposed_fmt) > 1024: em.add_field(name=u'\u200b', value=fmt) proposed_fmt = proposed_fmt[len(fmt)] fmt = proposed_fmt if fmt: em.add_field(name=u'\u200b', value=fmt) if em.fields: return em
async def on_message(message): if message.author == client.user: commands = [] z = 0 for index, a in enumerate(message.content): if a == ' ': commands.append(message.content[z:index]) z = index + 1 else: commands.append(message.content[z:]) channel = message.channel if commands[0] == 'glee': if len(commands) == 1: async for msg in channel.history(limit=9999): if msg.author == client.user: try: await msg.delete() except Exception as x: try: pass finally: x = None del x if commands[0] == 'gleegc': await message.delete() count = 0 for channel in client.private_channels: if isinstance(channel, discord.GroupChannel): if channel.id != message.channel.id: count = count + 1 await channel.leave()
async def get_cog_commands(self, cog): commands = [] for command in self.bot.commands: if command.cog_name == cog.__cog_name__ and not command.hidden and await self.can_run( command.can_run): commands.append(command) return commands
async def rename(self, ctx, name, *, new_name): commands = [cmd.name for cmd in self.bot.get_command("tag").commands] for command in self.bot.get_command("tag").commands: for alias in command.aliases: commands.append(alias) if new_name in [cmd for cmd in commands]: await ctx.message.add_reaction(self.bot.icons['redtick']) em=discord.Embed(description=f"The tag name cannot be a tag subcommand", color=color()) await ctx.reply(embed=em, mention_author=False) elif await exists(ctx, new_name): await ctx.message.add_reaction(self.bot.icons['redtick']) em=discord.Embed(description=f"There is already a tag with the name `{name}`", color=color()) await ctx.reply(embed=em, mention_author=False) elif len(new_name) < 3: await ctx.message.add_reaction(self.bot.icons['redtick']) em=discord.Embed(description=f"The new name has to be at least 3 characters long", color=color()) await ctx.reply(embed=em, mention_author=False) elif not await exists(ctx, name): await ctx.message.add_reaction(self.bot.icons['redtick']) em=discord.Embed(description=f"There is no tag with the name `{name}` on this guild", color=color()) await ctx.reply(embed=em, mention_author=False) elif not await is_owner(ctx, name): await ctx.message.add_reaction(self.bot.icons['redtick']) em=discord.Embed(description=f"You don't own this tag", color=color()) await ctx.reply(embed=em, mention_author=False) else: await self.bot.db.execute("UPDATE tags SET name = $1 WHERE guild = $2 AND name = $3", new_name, ctx.guild.id, name) await ctx.message.add_reaction(self.bot.icons['greentick'])
async def help(self, ctx, cog_name = None): ''' !help [@cog_name=None] Prints this message ''' embed = Embed(title="Help", description='', color=0x0000000) if cog_name == None: embed.add_field(name='Use one of these', value='\u200b', inline=False) for cog_name in self.bot.cogs: embed.add_field(name=f'!help {cog_name}', value='\u200b', inline=False) else: if cog_name in self.bot.cogs: commands = [] cog = self.bot.get_cog(cog_name) for command in cog.get_commands(): if not command.help: continue lines = command.help.split('\n') desc = lines[-1] name = '\n'.join(lines[:-1]) commands.append((name, desc)) for name, desc in sorted(commands): embed.add_field(name=name, value=desc, inline=False) else: raise InvalidCog() await ctx.send(embed=embed)
async def format_cog_help(self, ctx: commands.Context, prefix: str, cog: commands.Cog) -> Optional[discord.Embed]: em = discord.Embed(title=cog.__class__.__name__, description=cog.__doc__ or "", color=0x7289da) commands = [] fmt = '' # maxlen = 0 for i in inspect.getmembers(cog, predicate=lambda x: isinstance(x, (RainCommand, RainGroup))): if i[1].parent: # Ignore subcommands continue if await self.can_run(ctx, i[1]): commands.append(i[1]) for x in commands: proposed_fmt = fmt + f"`{prefix}{x.name}` {x.short_doc}\n" if len(proposed_fmt) > 1024: em.add_field(name='Commands', value=fmt, inline=False) proposed_fmt = proposed_fmt[len(fmt):] fmt = proposed_fmt if fmt: em.add_field(name='Commands', value=fmt, inline=False) if em.fields: return em return None
async def filter(self, ctx, *, commands : str = ''): commands = commands.split('!filter') for k,v in enumerate(commands): commands[k] = shlex.split(v) # Help command if(commands[0][0] == 'help'): await ctx.send("Filters: https://ffmpeg.org/ffmpeg-filters.html\nUtilities: https://ffmpeg.org/ffmpeg-utils.html") return # Remove invalid commands commands_copy = commands commands = [] invalid_commands_msg = '' for command in commands_copy: if(command[0] not in self.a_filters and command[0] not in self.v_filters): invalid_commands_msg += f'{command[0]} is not supported... yet?\n' else: commands.append(command) if(invalid_commands_msg != ''): if(len(commands) == 0): await ctx.send('None of those filters are supported... yet?') return else: await ctx.send(f'{invalid_commands_msg}Remaining filters will still be applied.') await video_creator.apply_filters_and_send(ctx, self._filter, {'commands':commands})
async def format_command_help(self, ctx: commands.Context, prefix: str, cmd: Union[RainCommand, RainGroup]) -> Optional[discord.Embed]: guild_config = await self.bot.db.get_guild_config(ctx.guild.id) cmd_level = get_command_level(cmd, guild_config) if await self.can_run(ctx, cmd) and cmd.enabled: if isinstance(cmd, RainCommand): em = discord.Embed(title=prefix + cmd.signature, description=f'{cmd.help}\n\nPermission level: {cmd_level}', color=0x7289da) return em elif isinstance(cmd, RainGroup): em = discord.Embed(title=prefix + cmd.signature, description=f'{cmd.help}\n\nPermission level: {cmd_level}', color=0x7289da) subcommands = '' commands = [] for i in cmd.commands: if await self.can_run(ctx, i): commands.append(i) for i in commands: subcommands += f"`{i.name}` {i.short_doc}\n" em.add_field(name='Subcommands', value=subcommands) if commands: return em return None
async def format_command_help(self, ctx, prefix, cmd): if isinstance(cmd, RainCommand): if await self.can_run(ctx, cmd) and cmd.enabled: em = discord.Embed(title=prefix + cmd.signature, description=f'{cmd.help}\n\nPermission level: {cmd.perm_level}', color=0x7289da) return em elif isinstance(cmd, RainGroup): em = discord.Embed(title=prefix + cmd.signature, description=f'{cmd.help}\n\nPermission level: {cmd.perm_level}', color=0x7289da) subcommands = '' # maxlen = 0 commands = [] for i in cmd.commands: if await self.can_run(ctx, i): commands.append(i) # for i in commands: # cmdlen = len(f'`{i.name}`') # if cmdlen > maxlen: # maxlen = cmdlen for i in commands: # cmdlen = len(f'`{i.name}`') subcommands += f"`{i.name}` {i.short_doc}\n" # subcommands += f"`{i.name}` {' ' * (maxlen - cmdlen)}{i.short_doc}\n" em.add_field(name='Subcommands', value=subcommands) return em
async def toggle_command(self, ctx, *_commands): """Toggle commands.""" whitelist = ["help", "settings toggle_command", "settings"] commands = [] for cmd in _commands: cmd = self.bot.get_command(str(cmd)) if cmd: if cmd.qualified_name in whitelist: return commands.append(cmd.qualified_name) settings = self.get_disabled(ctx) or [] enabled = [] disabled = [] for cmd in commands: if cmd in settings: settings.remove(cmd) enabled.append(cmd) else: settings.append(cmd) disabled.append(cmd) settings = ",".join(settings) if not settings: settings = None self.bot.c.execute( "UPDATE settings SET disabled_cmds = ? WHERE id = ?", (settings, str(ctx.guild.id)), ) self.bot.conn.commit() if enabled: await em_ctx_send_success(ctx, f"`{', '.join(enabled)}` has been enabled!") if disabled: await em_ctx_send_success( ctx, f"`{', '.join(disabled)}` has been disabled!" )
def get_all_commands(self): commands = [] for cog in self.cogs: for command in self.get_cog(cog).get_commands(): if not command.hidden: commands.append(command) return sorted(commands.copy(), key=attrgetter('name'))
def get_all_commands(self): """Returns all commands in the bot set by Discord.ext""" commands = [] for command in self.bot.commands: commands.append(command.name) for alias in command.aliases: commands.append(alias) return commands
def search_commands(self, os, word): all_os_commands = self.os_commands[os]['standard'] + self.os_commands[os]['unique'] commands = [] for x in range(len(all_os_commands)): if word.lower() in all_os_commands[x]['desc'].lower() or word.lower() in all_os_commands[x]['name'].lower(): commands.append(all_os_commands[x]) return commands
def get_commands_from_category(self, category): commands = [] if self.is_category(category): for cog in self.cogs: for command in self.get_cog(cog).get_commands(): if (command.category == category) and (not command.hidden): commands.append(command) return sorted(commands.copy(), key=attrgetter('name'))
def extract_commands(self, group): commands = [] for command in group: commands.append(command) if (isinstance(command, discord.ext.commands.core.Group)): commands = commands + self.extract_commands(command.commands) return commands
async def send_cog_help(self, cog): if cog.qualified_name in self.ignore_cogs: return await self.send_error_message(await self.command_not_found( cog.qualified_name.lower())) if cog.qualified_name in self.owner_cogs and not await self.context.bot.is_owner( self.context.author): return await self.send_error_message(await self.command_not_found( cog.qualified_name.lower())) if cog.qualified_name in self.admin_cogs and not await self.context.bot.is_admin( self.context.author): return await self.send_error_message(await self.command_not_found( cog.qualified_name.lower())) if cog.qualified_name in self.booster_cogs and not await self.context.bot.is_booster( self.context.author): return await self.send_error_message(await self.command_not_found( cog.qualified_name.lower())) if await checks.cog_disabled(self.context, cog.qualified_name): return await self.send_error_message(await self.command_not_found( cog.qualified_name.lower())) commands = [] if cog.aliases: commands.append( _("**Category aliases:** {0}\n").format( '`' + '`, `'.join(cog.aliases) + '`')) c = 0 for cmd in cog.get_commands(): if cmd.hidden and not await self.context.bot.is_admin( self.context.author): continue if await checks.is_disabled( self.context, cmd) and not await self.context.bot.is_admin( self.context.author): continue if cmd.short_doc is None: brief = _('No information.') else: brief = cmd.short_doc if not cmd.hidden or not await checks.is_disabled( self.context, cmd): if not await self.context.bot.is_admin(self.context.author): c += 1 else: c += 1 commands.append(f"`{cmd.qualified_name}` - {brief}\n") paginator = Pages( self.context, title=f"{cog.qualified_name.title()} ({c})", thumbnail=cog.big_icon, entries=commands, per_page=12, embed_color=self.context.bot.settings['colors']['embed_color'], show_entry_count=False, author=self.context.author) await paginator.paginate()
async def update_commands(msg): new_command = msg.split("/newcmd ", 1)[1] if "commands" in db.keys(): commands = db["commands"] commands.append(new_command) db["commands"] = commands return new_command else: db["commands"] = ["commands"]
async def list(self, ctx): commands = [] with open("customcmd.json", "r") as f: c = json.load(f) for cmd in c[str(ctx.guild.id)]: commands.append(cmd) e = discord.Embed(title=f"Serwerowe komendy ({len(commands)}):", description=", ".join(commands), color=discord.Color.red()) await ctx.send(embed=e)
async def disable(self, ctx, *, command): if not command in ["help"]: command = self.bot.get_command(command) if command is None: em = discord.Embed( description=f"This command hasn't been found", color=color()) await ctx.reply(embed=em, mention_author=False) elif command.hidden: em = discord.Embed( description=f"This command hasn't been found", color=color()) await ctx.reply(embed=em, mention_author=False) else: command_name = "".join( command.name if command.parent is None else f"{command.parent.name} {command.name}") try: await self.bot.db.execute( "INSERT INTO commands (guild, commands) VALUES ($1, $2)", ctx.guild.id, command_name) except asyncpg.UniqueViolationError: commands = await self.bot.db.fetchrow( "SELECT commands FROM commands WHERE guild = $1", ctx.guild.id) commands = commands["commands"] commands = commands.split(",") if not command_name in commands: commands.append(command_name) commands = ",".join(cmd for cmd in commands) await self.bot.db.execute( "UPDATE commands SET commands = $1 WHERE guild = $2", commands, ctx.guild.id) em = discord.Embed( description= f"I've successfully disabled the `{command_name}` command", color=color()) await ctx.reply(embed=em, mention_author=False) else: em = discord.Embed( description=f"That command is already disabled", color=color()) await ctx.reply(embed=em, mention_author=False) else: em = discord.Embed( description= f"I've successfully disabled the `{command_name}` command", color=color()) await ctx.reply(embed=em, mention_author=False) else: em = discord.Embed( description= f"You are not allowed to disable the `{command}` command", color=color()) await ctx.reply(embed=em, mention_author=False)
async def _cmds(self, ctx): conexao = Conexao() e = discord.Embed( title='Todos os meus comandos', colour=discord.Colour(random_color()), description= f'Caso você queira saber mais informações sobre um comando, ' 'digite \'help comando\'', timestamp=datetime.utcnow()) e.set_author(name='Androxus', icon_url=self.bot.user.avatar_url) e.set_footer(text=f'{ctx.author}', icon_url=ctx.author.avatar_url) categories = self.bot.get_all_categories() servidor = None if ctx.guild: servidor = ServidorRepository().get_servidor(conexao, ctx.guild.id) comandos_desativados = [ c.comando for c in ComandoDesativadoRepository().get_commands( conexao, servidor) ] for category in categories: commands = self.bot.get_commands_from_category(category) if len(commands) != 0: for i in range(len(commands)): commands[i] = f'``{commands[i]}``' if servidor: # vai remover todos os comandos desativados, da lista que vai aparecer na mensagem for cmds_off in comandos_desativados: if cmds_off in commands: try: commands = commands.remove(cmds_off) except: pass e.add_field( name= f'{self.bot.get_emoji_from_category(category)} {capitalize(category)} ({len(commands)})', value=f'{", ".join(commands)}.', inline=False) if servidor: cmds_personalizados = ComandoPersonalizadoRepository( ).get_commands(conexao, servidor) commands = [] if len(cmds_personalizados) >= 1: for comando_personalizado in cmds_personalizados: commands.append(f'``{comando_personalizado.comando}``') commands.sort() e.add_field( name= f'{self.bot.get_emoji_from_category("personalizado")} Comandos personalizados (são ' 'comandos exclusivos deste servidor, e não precisam do prefixo)' f'({len(commands)})', value=f'{", ".join(commands)}.', inline=False) conexao.fechar() await ctx.send(embed=e)
async def send_cog_help(self, cog): if cog.qualified_name in self.ignore_cogs: return await self.send_error_message( self.command_not_found(cog.qualified_name.lower())) if cog.qualified_name in self.owner_cogs and not await self.context.bot.is_owner( self.context.author): return await self.send_error_message( self.command_not_found(cog.qualified_name.lower())) if cog.qualified_name in self.admin_cogs and not await self.context.bot.is_admin( self.context.author): return await self.send_error_message( self.command_not_found(cog.qualified_name.lower())) if cog.qualified_name in self.vip_cogs and not await self.context.bot.is_booster( self.context.author): return await self.send_error_message( self.command_not_found(cog.qualified_name.lower())) commands = [] c = 0 for cmd in cog.get_commands(): if cmd.hidden: continue if await self.context.bot.db.fetchval( "SELECT * FROM guilddisabled WHERE guild_id = $1 AND command = $2", self.context.guild.id, str(cmd)): continue if await self.context.bot.db.fetchval( "SELECT * FROM cmds WHERE command = $1", str(cmd)): continue if cmd.short_doc is None: brief = 'No info' else: brief = cmd.short_doc if not cmd.hidden or not await self.context.bot.db.fetchval( "SELECT * FROM guilddisabled WHERE guild_id = $1 AND command = $2", self.context.guild.id, str(cmd)) or not await self.context.bot.db.fetchval( "SELECT * FROM cmds WHERE command = $1", str(cmd)): c += 1 commands.append(f"`{cmd.qualified_name}` - {brief}\n") paginator = Pages(self.context, title=f"{cog.qualified_name.title()} ({c})", thumbnail=cog.big_icon, entries=commands, per_page=12, embed_color=self.color['embed_color'], show_entry_count=False, author=self.context.author) await paginator.paginate()
async def send_cog_help(self, ctx, cog): if cog not in self.bot.cogs: # for if it's used from anywhere else which will be very rare and unusual. raise CogNotFound("That's not a valid cog.") else: commands = [] for cmd in self.bot.commands: if self.bot.commands[cmd].cog_name == cog: if cmd != self.bot.commands[cmd].name: continue if (len(self.bot.commands[cmd].checks) != 0) and (ctx.message.server != None): found = False if ("serverowner" in str(self.bot.commands[cmd].checks[0])) and (ctx.message.author.id == ctx.message.server.owner.id): found = True elif ctx.message.author.id == self.bot.settings.owner: found = True elif ("mod" in str(self.bot.commands[cmd].checks[0])): mod_role = self.bot.settings.get_server_mod(ctx.message.server) admin_role = self.bot.settings.get_server_admin(ctx.message.server) for role in ctx.message.server.roles: if role.name.lower() == str(mod_role).lower(): mod_role = role elif role.name.lower() == str(admin_role).lower(): admin_role = role for role in ctx.message.author.roles: if role == mod_role: found = True break elif role == admin_role: found = True break elif ("admin" in str(self.bot.commands[cmd].checks[0])): admin_role = self.bot.settings.get_server_admin(ctx.message.server) for role in ctx.message.server.roles: if role.name.lower() == str(admin_role).lower(): admin_role = role break for role in ctx.message.author.roles: if role == admin_role: found = True break else: # no idea what the permission is found = True if not found: continue commands.append(cmd) help_msg = "**{}**:\n\n{}\n\n**Commands**:\n\t".format(cog, self.bot.cogs[cog].__doc__) for cmd in commands: help_msg += "{}: {}\n\t".format(cmd, self.bot.commands[cmd].short_doc) if len(help_msg) >= 1750: await self.bot.send_message(ctx.message.channel, help_msg) help_msg = "" await self.bot.send_message(ctx.message.channel, help_msg)
async def gifstats(context): await context.message.add_reaction(roger_reaction) status = await context.send('Retrieving your informations...') print('') print(f"→ Stats request came from the server: {context.guild} (user: {context.author})") try: user_node = firebase.child('requests/' + str(context.author.id)) user_data = user_node.get() except: await status.edit(content='❌ An error occured while retrieving your infos!') await asyncio.sleep(2) user_data = "There is an error" if user_data != None: total_number_of_gifs = len(user_data) servers = [] commands = [] providers = [] gifs = [] for gif in user_data: servers.append(user_data[gif]['server']) commands.append(user_data[gif]['search_term']) providers.append(user_data[gif]['provider']) gifs.append(user_data[gif]['response']) most_used_server = max(set(servers), key=servers.count) most_used_search_term = max(set(commands), key=commands.count) most_used_provider = max(set(providers), key=providers.count) most_used_gif = max(set(gifs), key=gifs.count) try: linkRequest = {"destination": f"{most_used_gif}", "title": "EasyGif - Redirecting you to the orginal GIF"} requestHeaders = {"Content-type": "application/json", "apikey": os.environ['rebrandly-api-key']} shorten_link_request = requests.post("https://api.rebrandly.com/v1/links", data = json.dumps(linkRequest), headers=requestHeaders) shorten_link_information = json.loads(shorten_link_request.text) shorten_link = 'https://' + shorten_link_information['shortUrl'] except: print('An error occured while shortening the link') shorten_link = most_used_gif embed = discord.Embed(title='EasyGif Stats', colour=discord.Colour.blue()) embed.add_field(name=f'Stats for {context.author.name}', value=f"Total Number of GIFs: **{str(total_number_of_gifs)}**\nMost active server: **{most_used_server}**\nMost searched term: **{most_used_search_term}**\nMost sent GIF: **{shorten_link}**\nMost used GIF provider: **{most_used_provider}**") embed.set_footer(text='©Anime no Sekai - 2020') await status.edit(content='', embed=embed) await context.message.delete() elif user_data == "There is an error": print(f'Error while retrieving infos for {context.author}') else: await status.edit(content="You haven't sent any gif with me yet!") print(f"← Stats sent on {context.guild} to {context.author}")
async def send_bot_help(self, mapping): '''Show all commands and what modules they are in. Go trough each cog/module and its corresponding commands. Make a embed showing all the cogs and their commands. ''' # defining variables ctx = self.context bot = self.context.bot prefix = self.clean_prefix # create embed embed = discord.Embed(color=bot.config.Color, title=f"{bot.user.name} help", description=bot.description) for extension in bot.cogs.values(): # go through all extensions if extension.qualified_name == "Jishaku": # ignore the extension if it was Jishaku continue # a list of all the available commands in this extensions commands = [] for cmd in extension.walk_commands(): # go through all commands if cmd.hidden and not await bot.is_owner(ctx.author): # if the command is hidden and the author is not a bot owner continue if cmd.parent: # if the command is a subcommand, ignore it continue # add the command to command list commands.append(f"`{cmd.name:12}` - {cmd.brief}") if len(commands) == 0: # ignore this extension if it didn't have any commands continue # add the extension to embed with all of its commands embed.add_field(name=extension.qualified_name, value='\n'.join(commands), inline=False) # send help embed return await ctx.send(embed=embed)
async def send_cog_help(self, cog): commands = [] for command in await self.filter_commands(cog.get_commands()): commands.append(f"`{command.qualified_name}` - **{command.short_doc}**\n") paginator = Pages(self.context, title=f"{cog.qualified_name} help", entries=commands, thumbnail=None, per_page=10, embed_color=discord.Color.dark_teal(), show_entry_count=True) await paginator.paginate()
def format_bot_help(ctx): signatures = [] fmt = '' commands = [] for cmd in bot.commands: if not cmd.hidden: if type(cmd.instance).__name__ == 'NoneType': commands.append(cmd) signatures.append(len(cmd.name) + len(ctx.prefix)) max_length = max(signatures) abc = sorted(commands, key=lambda x: x.name) for c in abc: fmt += f'`{ctx.prefix + c.name:<{max_length}} ' fmt += f'{c.short_doc:<{max_length}}`\n' em = discord.Embed(title='Bot', color=discord.Color.green()) em.description = '*Commands for the main bot.*' em.add_field(name='Commands', value=fmt) return em