mirror of
https://github.com/polyjitter/searchbot-discord.git
synced 2024-08-14 22:46:55 +00:00
New help command, fixed ping assist
This commit is contained in:
parent
7943cd930c
commit
d74e285764
5 changed files with 72 additions and 6 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -51,3 +51,4 @@ coverage.xml
|
||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
extensions/__pycache__/core.cpython-38.pyc
|
||||||
|
|
Binary file not shown.
|
@ -12,7 +12,7 @@ from discord.ext import commands, tasks
|
||||||
import dbl
|
import dbl
|
||||||
|
|
||||||
|
|
||||||
class Botlist(commands.Cog):
|
class BotList(commands.Cog, name='Bot List'):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.request = bot.request
|
self.request = bot.request
|
||||||
|
@ -116,4 +116,4 @@ class Botlist(commands.Cog):
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(Botlist(bot))
|
bot.add_cog(BotList(bot))
|
||||||
|
|
|
@ -7,6 +7,7 @@ import sys
|
||||||
import cpuinfo
|
import cpuinfo
|
||||||
import math
|
import math
|
||||||
import psutil
|
import psutil
|
||||||
|
import itertools
|
||||||
|
|
||||||
|
|
||||||
class Core(commands.Cog):
|
class Core(commands.Cog):
|
||||||
|
@ -17,6 +18,12 @@ class Core(commands.Cog):
|
||||||
'extensions': []
|
'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()
|
self._init_extensions()
|
||||||
|
|
||||||
def _init_extensions(self):
|
def _init_extensions(self):
|
||||||
|
@ -168,6 +175,64 @@ Number of extensions present: {len(ctx.bot.cogs)}
|
||||||
await ctx.send(':zzz: **Restarting.**')
|
await ctx.send(':zzz: **Restarting.**')
|
||||||
exit()
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(Core(bot))
|
bot.add_cog(Core(bot))
|
||||||
|
|
4
main.py
4
main.py
|
@ -75,7 +75,7 @@ class Bot(commands.Bot):
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
|
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
mentions = commands.when_mentioned(bot, message)
|
mentions = [self.user.mention, f'<@!{self.user.id}>']
|
||||||
ctx = await self.get_context(message)
|
ctx = await self.get_context(message)
|
||||||
|
|
||||||
# Handling
|
# Handling
|
||||||
|
@ -88,7 +88,7 @@ class Bot(commands.Bot):
|
||||||
elif self.maintenance and not message.author.is_owner():
|
elif self.maintenance and not message.author.is_owner():
|
||||||
# Maintenance mode
|
# Maintenance mode
|
||||||
return
|
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
|
# Empty ping for assistance
|
||||||
assist_msg = (
|
assist_msg = (
|
||||||
"**Hi there! How can I help?**\n\n"
|
"**Hi there! How can I help?**\n\n"
|
||||||
|
|
Loading…
Reference in a new issue