async def commandstats(self, ctx, all_stats: bool = False): data = self.config.get('data', {}) if all_stats: title = "Bot" commands = {} for d in data: server_cmds = data.get(d, {}) for c in server_cmds.keys(): current = commands.get(c, 0) commands[c] = current + server_cmds[c] else: title = "This Server" commands = data.get(ctx.message.server.id, {}) commands = OrderedDict( sorted(commands.items(), key=lambda x: x[1], reverse=True)) stats = [] for c in commands.keys(): stats.append(c + ": " + str(commands[c])) try: pager = Pages(self.bot, message=ctx.message, entries=stats) pager.embed.colour = Colors.get_default(self.bot) pager.embed.set_author(name="Command stats for " + title, icon_url=ctx.message.server.icon_url) await pager.paginate() except Exception as e: await self.bot.say(e)
def __init__(self, help_command, commands): super().__init__(entries=sorted(commands.keys(), key=lambda c: c.qualified_name), per_page=6) self.commands = commands self.help_command = help_command self.prefix = help_command.clean_prefix
async def help_cog(self, command_or_cog): #send help for a cog commands = self.bot.commands embed = discord.Embed(title=command_or_cog, description="help command shitshow", color=self.bot.embed_color) string_commands = "" list_commands = [] for command in commands.keys(): command = commands[command] if command.cog_name == command_or_cog and command not in list_commands: string_commands = string_commands + "**{0}** -> {1}\n".format( command.name, command.brief) list_commands.append(command) embed.add_field(name="Commands in Cog:", value=string_commands, inline=False) embed.set_footer( text="{}help [comando] para saberes mais sobre algum comando".format( self.bot.command_prefix)) await self.bot.say(embed=embed)
async def on_message(self, msg): """Check for custom commands on every message""" # Get commands, if the message is in commands.keys() send the command with open("data/commands.json", "r") as f: commands = json.load(f) if msg.content in commands.keys() and msg.author.id != self.bot.user.id: await msg.channel.send(commands[msg.content])
def __init__(self, help_command, commands): # entries = [(cog, len(sub)) for cog, sub in commands.items()] # entries.sort(key=lambda t: (t[0].qualified_name, t[1]), reverse=True) super().__init__(entries=sorted(commands.keys(), key=lambda c: c.qualified_name), per_page=3) self.commands = commands self.help_command = help_command self.prefix = help_command.clean_prefix
def __init__(self, commands: Dict[commands.Cog, List[commands.Command]]): cogs = sorted(commands.keys(), key=lambda c: c.qualified_name) self.commands = commands super().__init__(cogs, per_page=4) total_commands = 0 for commands in commands.values(): total_commands += len(commands) self.total_commands = total_commands
def help(self, message, state): """Shows this help message""" response = f'In game help for {state.game}:\n\n' commands = self.__help_commands() width = max([len(c) for c in commands.keys()]) +2 fmt = "{{cmd:{width}}}{{help}}\n".format(width=width) for cmd, func in commands.items(): response += fmt.format(cmd=cmd,help=getattr(self,func).__doc__) response = "```" + response + "```" return response
async def on_message(message): if message.author.bot: return # add user to db if not exist if not str(message.author) in users and not str( message.author) in superusers: insert_statement = 'INSERT INTO users (name, is_superuser, can_alias) values (%s,%s,%s);' cursor.execute(insert_statement, (str(message.author), False, False)) conn.commit() users.append(str(message.author)) if message.content.startswith('<@' + bot.user.id + '>') or message.content.startswith('?'): # PIPES M**********R to_process = message.content[1:].split('|') to_process = [m.lstrip().rstrip() for m in to_process] # All commands MUST output a string output = [] for command in to_process: pieces = shlex.split(command) if pieces[0] == 'help': if not output == []: args = pieces[1:] + output else: args = pieces[1:] output = commands[pieces[0]].call(message, [descriptions, args]) elif pieces[0] in commands.keys(): args = [] # TODO: implement placeholder locations for output of prev command if not output == []: args = pieces[1:] + output else: args = pieces[1:] output = commands[pieces[0]].call(message, args) else: await bot.send_message( message.channel, "{0} is not a valid command. :cry:".format(pieces[0])) return if not output == []: out = '' for o in output: out = out + o + " " await bot.send_message(message.channel, out.rstrip()) else: reply = process_karma(message, conn, cursor, config["karma_timeout"]) if not reply == "": await bot.send_message(message.channel, reply)
async def listcommands(self, ctx): """Lists custom commands""" with open("data/commands.json", "r") as f: commands = json.load(f) desc = "\n".join([k for k in commands.keys()]) embed = discord.Embed(title="Custom Commands", description=desc, color=0xFF0000) await ctx.send(embed=embed)
def embed(self, commands, page, title, thumbnail): keys = list(commands.keys()) embed = discord.Embed(title=title) for x in range(0, 4): try: active_key = keys[page * 4 + (x - 4)] embed.add_field(name="\u200b", value=f"[`{active_key}`](https://hurb.gg/commands)\n**Parameters:** *{commands[active_key][0]}*\n**What it does:** *{commands[active_key][1]}*\n**Example:** `{commands[active_key][2]}`", inline=False) except IndexError: pass embed.set_thumbnail(url=thumbnail) embed.set_footer(text=f"______________________________________\nUse ⬅️ and ️➡️ to switch pages | Page {page} / {round(len(commands)/4)}") return embed
async def help(self, ctx, *command_or_cog): cogs = self.bot.cogs commands = self.bot.commands if len(command_or_cog) == 0: await help_all(self) else: command_or_cog = command_or_cog[0] if command_or_cog in cogs.keys(): await help_cog(self, command_or_cog) elif command_or_cog in commands.keys(): await help_command(self, command_or_cog) else: await self.bot.say("Command or cog not found")
async def process_commands(ctx, *args): """All commands start here.""" if args == [] or args[0].strip() == "": await ctx.send("A command is needed.") return if args[0] in commands.keys(): # It's a command that already exists, so call it func = commands[args[0]] await func(ctx, args) # Give it all the args except the command's name return # The user wants a subreddit image await subreddit_image(ctx, args ) # Include subreddit name and possible other args
async def Help(ctx, client=None, args=None, commands=None): if len(args) < 1: embed = discord.Embed(title='Commands', color=0xff0000) for command in commands.keys(): embed.add_field(name=f'`{command}`', value=commands[command], inline=False) await ctx.channel.send(embed=embed) elif args[0] == 'play': args.pop(0) quote = ' '.join(args) embed = discord.Embed(title='play Commands', color=0xff0000) for key in triggers.keys(): embed.add_field(name=f'`{key}`', value=triggers[key], inline=False) await ctx.channel.send(embed=embed)
async def help_command(message): channel = message.channel await delete_if_can(message) message_content = "```\n" message_content += "Hi there,\n" message_content += "My name is {} and I'm a magical unicorn!\n".format(client.user.name) message_content += "Here's what I can do:\n\n" for group in commands.keys(): message_content += group + ':\n' for command in commands[group]: message_content += ' !{}: {}\n'.format(command['name'], command['description']) if 'aliases' in command.keys(): aliasString = '' for aliasName in command['aliases']: if aliasString aliasString += ', ' aliasString += '!{}'.format(aliasName) message_content += ' *Aliases: {}\n'.format(aliasString) message_content += '\n' message_content += '```' await client.send_message(channel, message_content)
async def help(self, ctx, *, command_or_cog=None): """How does this work? Example: [p]help [p]help trivia [p]help Trivia (Note the capital T to get all the commands for that cog/category.)""" command = command_or_cog if command == None: if not ctx.message.channel.is_private: msg = await self.bot.say("I am sending you help in dms!") commands = {} help_msg = "{}\n\n".format(self.bot.description) counter = 0 for cog in self.bot.cogs: commands[cog] = [] 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 = False if not found: continue commands[cog].append(cmd) commandsCopy = commands.copy() for cog in commandsCopy: if len(commands[cog]) == 0: del commands[cog] for cog in list(commands.keys()): help_msg += "**{}**\n".format(cog) for cmd in commands[cog]: if (self.bot.commands[cmd].cog_name == cog) and not (self.bot.commands[cmd].hidden): if self.bot.commands[cmd].short_doc == "": help_msg += "\t\t**{}**\n".format(cmd) else: if len(self.bot.commands[cmd].short_doc) > 64: help_msg += "\t\t**{}**: {}...\n".format(cmd, self.bot.commands[cmd].short_doc[:64]) else: help_msg += "\t\t**{}**: {}\n".format(cmd, self.bot.commands[cmd].short_doc) if len(help_msg) > 1750: if counter >= 5: await asyncio.sleep(5) counter = 0 try: await self.bot.send_message(ctx.message.author, help_msg) except: pass help_msg = "" counter += 1 try: await self.bot.send_message(ctx.message.author, help_msg) except: pass if not ctx.message.channel.is_private: await self.bot.edit_message(msg, "I've sent you help in dms!") else: if command in self.bot.cogs: await self.send_cog_help(ctx, command) elif command.split()[0] in self.bot.commands: await self.send_cmd_help(ctx, command) else: await self.bot.say("That's not a valid command nor a cog/category.")
def removecommand(command): if command not in commands.keys(): return -1 commanddetails = commands[command] {"prefix": prefixcommands, "match": matchcommands, "contain": containcommands}[commanddetails[1]].remove(command) del commands[command]