diff --git a/.gitignore b/.gitignore index 482d026..9d71bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -50,4 +50,5 @@ coverage.xml *.pot # Sphinx documentation -docs/_build/ \ No newline at end of file +docs/_build/ +extensions/__pycache__/core.cpython-38.pyc diff --git a/extensions/__pycache__/core.cpython-38.pyc b/extensions/__pycache__/core.cpython-38.pyc index 5fdc384..c4719e9 100644 Binary files a/extensions/__pycache__/core.cpython-38.pyc and b/extensions/__pycache__/core.cpython-38.pyc differ diff --git a/extensions/botlist.py b/extensions/botlist.py index 15ff567..6e9d377 100644 --- a/extensions/botlist.py +++ b/extensions/botlist.py @@ -12,7 +12,7 @@ from discord.ext import commands, tasks import dbl -class Botlist(commands.Cog): +class BotList(commands.Cog, name='Bot List'): def __init__(self, bot): self.bot = bot self.request = bot.request @@ -116,4 +116,4 @@ class Botlist(commands.Cog): def setup(bot): - bot.add_cog(Botlist(bot)) + bot.add_cog(BotList(bot)) diff --git a/extensions/core.py b/extensions/core.py index cd78407..c4dfa51 100644 --- a/extensions/core.py +++ b/extensions/core.py @@ -7,16 +7,23 @@ import sys import cpuinfo import math import psutil +import itertools class Core(commands.Cog): def __init__(self, bot): self.bot = bot - self.settings = { + self.settings = { 'extensions': [] } + # + self._original_help_command = bot.help_command + if bot.config['CUSTOM_HELP']: + bot.help_command = HelpCommand() + bot.help_command.cog = self + self._init_extensions() def _init_extensions(self): @@ -168,6 +175,64 @@ Number of extensions present: {len(ctx.bot.cogs)} await ctx.send(':zzz: **Restarting.**') exit() + def cog_unload(self): + self.bot.help_command = self._original_help_command + +class HelpCommand(commands.MinimalHelpCommand): + def __init__(self, **options): + super().__init__(**options) + + def add_bot_commands_formatting(self, commands, heading): + if commands: + self.paginator.add_line(f"**{heading}**") + if heading == 'Main': + self.paginator.add_line(", ".join(f"`{c.name}`" for c in commands)) + else: + for c in commands: + self.paginator.add_line(f'`{c.name}` - _{c.short_doc}_') + self.paginator.add_line() + + async def send_bot_help(self, mapping): + ctx = self.context + bot = ctx.bot + + if bot.description: + self.paginator.add_line(bot.description, empty=True) + + note = self.get_opening_note() + if note: + self.paginator.add_line(note, empty=True) + + no_category = '\u200b{0.no_category}'.format(self) + def get_category(command, *, no_category=no_category): + cog = command.cog + return cog.qualified_name if cog is not None else no_category + + filtered = await self.filter_commands(bot.commands, sort=True, key=get_category) + to_iterate = itertools.groupby(filtered, key=get_category) + + main_cmds = [] + other_cmds = {} + + for category, commands in to_iterate: + commands = sorted(commands, key=lambda c: c.name) if self.sort_commands else list(commands) + if category in ['Core', 'Bot List']: + main_cmds.extend(commands) + else: + other_cmds[category] = commands + + self.add_bot_commands_formatting(main_cmds, 'Main') + for category, commands in other_cmds.items(): + self.add_bot_commands_formatting(commands, category) + + note = self.get_ending_note() + if note: + self.paginator.add_line() + self.paginator.add_line(note) + + await self.send_pages() + + def setup(bot): bot.add_cog(Core(bot)) diff --git a/main.py b/main.py index ae84488..b7edef9 100644 --- a/main.py +++ b/main.py @@ -75,7 +75,7 @@ class Bot(commands.Bot): async def on_message(self, message): # Prerequisites - mentions = commands.when_mentioned(bot, message) + mentions = [self.user.mention, f'<@!{self.user.id}>'] ctx = await self.get_context(message) # Handling @@ -88,7 +88,7 @@ class Bot(commands.Bot): elif self.maintenance and not message.author.is_owner(): # Maintenance mode return - elif message.content in mentions and self.config['MENTION_ASSIST']: + elif message.content in mentions and self.config.get('MENTION_ASSIST'): # Empty ping for assistance assist_msg = ( "**Hi there! How can I help?**\n\n"