New help command, fixed ping assist

This commit is contained in:
Adriene Hutchins 2020-03-01 23:58:05 -05:00
parent 7943cd930c
commit d74e285764
5 changed files with 72 additions and 6 deletions

3
.gitignore vendored
View File

@ -50,4 +50,5 @@ coverage.xml
*.pot
# Sphinx documentation
docs/_build/
docs/_build/
extensions/__pycache__/core.cpython-38.pyc

View File

@ -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))

View File

@ -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))

View File

@ -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"