mirror of
https://github.com/miaowware/qrm2.git
synced 2025-05-28 12:22:26 -04:00
Merge pull request #178 from classabbyamp/help-checks
Verify checks in help commands
This commit is contained in:
commit
29e75c38e1
@ -39,7 +39,8 @@ cat = SimpleNamespace(lookup='Information Lookup',
|
|||||||
maps='Mapping',
|
maps='Mapping',
|
||||||
ref='Reference',
|
ref='Reference',
|
||||||
study='Exam Study',
|
study='Exam Study',
|
||||||
weather='Land and Space Weather')
|
weather='Land and Space Weather',
|
||||||
|
admin='Bot Control')
|
||||||
|
|
||||||
emojis = SimpleNamespace(check_mark='✅',
|
emojis = SimpleNamespace(check_mark='✅',
|
||||||
x='❌',
|
x='❌',
|
||||||
|
28
exts/base.py
28
exts/base.py
@ -25,11 +25,13 @@ import data.options as opt
|
|||||||
class QrmHelpCommand(commands.HelpCommand):
|
class QrmHelpCommand(commands.HelpCommand):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(command_attrs={'help': 'Shows help about qrm or a command', 'aliases': ['h']})
|
super().__init__(command_attrs={'help': 'Shows help about qrm or a command', 'aliases': ['h']})
|
||||||
|
self.verify_checks = True
|
||||||
|
|
||||||
def get_bot_mapping(self):
|
async def get_bot_mapping(self):
|
||||||
bot = self.context.bot
|
bot = self.context.bot
|
||||||
mapping = {}
|
mapping = {}
|
||||||
for cmd in bot.commands:
|
|
||||||
|
for cmd in await self.filter_commands(bot.commands, sort=True):
|
||||||
cat = cmd.__original_kwargs__.get('category', None)
|
cat = cmd.__original_kwargs__.get('category', None)
|
||||||
if cat in mapping:
|
if cat in mapping:
|
||||||
mapping[cat].append(cmd)
|
mapping[cat].append(cmd)
|
||||||
@ -37,7 +39,7 @@ class QrmHelpCommand(commands.HelpCommand):
|
|||||||
mapping[cat] = [cmd]
|
mapping[cat] = [cmd]
|
||||||
return mapping
|
return mapping
|
||||||
|
|
||||||
def get_command_signature(self, command):
|
async def get_command_signature(self, command):
|
||||||
parent = command.full_parent_name
|
parent = command.full_parent_name
|
||||||
if command.aliases != []:
|
if command.aliases != []:
|
||||||
aliases = ', '.join(command.aliases)
|
aliases = ', '.join(command.aliases)
|
||||||
@ -61,9 +63,9 @@ class QrmHelpCommand(commands.HelpCommand):
|
|||||||
embed.title = 'qrm Help'
|
embed.title = 'qrm Help'
|
||||||
embed.description = (f'For command-specific help and usage, use `{opt.prefix}help [command name]`'
|
embed.description = (f'For command-specific help and usage, use `{opt.prefix}help [command name]`'
|
||||||
'. Many commands have shorter aliases.')
|
'. Many commands have shorter aliases.')
|
||||||
|
mapping = await mapping
|
||||||
|
|
||||||
for cat, cmds in mapping.items():
|
for cat, cmds in mapping.items():
|
||||||
cmds = list(filter(lambda x: not x.hidden, cmds))
|
|
||||||
if cmds == []:
|
if cmds == []:
|
||||||
continue
|
continue
|
||||||
names = sorted([cmd.name for cmd in cmds])
|
names = sorted([cmd.name for cmd in cmds])
|
||||||
@ -74,17 +76,25 @@ class QrmHelpCommand(commands.HelpCommand):
|
|||||||
await self.context.send(embed=embed)
|
await self.context.send(embed=embed)
|
||||||
|
|
||||||
async def send_command_help(self, command):
|
async def send_command_help(self, command):
|
||||||
|
if self.verify_checks:
|
||||||
|
if not await command.can_run(self.context):
|
||||||
|
raise commands.CheckFailure
|
||||||
|
for p in command.parents:
|
||||||
|
if not await p.can_run(self.context):
|
||||||
|
raise commands.CheckFailure
|
||||||
embed = cmn.embed_factory(self.context)
|
embed = cmn.embed_factory(self.context)
|
||||||
embed.title = self.get_command_signature(command)
|
embed.title = await self.get_command_signature(command)
|
||||||
embed.description = command.help
|
embed.description = command.help
|
||||||
await self.context.send(embed=embed)
|
await self.context.send(embed=embed)
|
||||||
|
|
||||||
async def send_group_help(self, group):
|
async def send_group_help(self, group):
|
||||||
|
if self.verify_checks and not await group.can_run(self.context):
|
||||||
|
raise commands.CheckFailure
|
||||||
embed = cmn.embed_factory(self.context)
|
embed = cmn.embed_factory(self.context)
|
||||||
embed.title = self.get_command_signature(group)
|
embed.title = await self.get_command_signature(group)
|
||||||
embed.description = group.help
|
embed.description = group.help
|
||||||
for cmd in group.commands:
|
for cmd in await self.filter_commands(group.commands, sort=True):
|
||||||
embed.add_field(name=self.get_command_signature(cmd), value=cmd.help, inline=False)
|
embed.add_field(name=await self.get_command_signature(cmd), value=cmd.help, inline=False)
|
||||||
await self.context.send(embed=embed)
|
await self.context.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@ -166,7 +176,7 @@ class BaseCog(commands.Cog):
|
|||||||
"(https://github.com/classabbyamp/discord-qrm2/issues)!")
|
"(https://github.com/classabbyamp/discord-qrm2/issues)!")
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@commands.command(name="echo", aliases=["e"], hidden=True)
|
@commands.command(name="echo", aliases=["e"], category=cmn.cat.admin)
|
||||||
@commands.check(cmn.check_if_owner)
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _echo(self, ctx: commands.Context,
|
async def _echo(self, ctx: commands.Context,
|
||||||
channel: Union[cmn.GlobalChannelConverter, commands.UserConverter], *, msg: str):
|
channel: Union[cmn.GlobalChannelConverter, commands.UserConverter], *, msg: str):
|
||||||
|
6
main.py
6
main.py
@ -60,7 +60,7 @@ bot.qrm.debug_mode = debug_mode
|
|||||||
|
|
||||||
# --- Commands ---
|
# --- Commands ---
|
||||||
|
|
||||||
@bot.command(name="restart", aliases=["rs"], hidden=True)
|
@bot.command(name="restart", aliases=["rs"], category=cmn.cat.admin)
|
||||||
@commands.check(cmn.check_if_owner)
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _restart_bot(ctx: commands.Context):
|
async def _restart_bot(ctx: commands.Context):
|
||||||
"""Restarts the bot."""
|
"""Restarts the bot."""
|
||||||
@ -71,7 +71,7 @@ async def _restart_bot(ctx: commands.Context):
|
|||||||
await bot.logout()
|
await bot.logout()
|
||||||
|
|
||||||
|
|
||||||
@bot.command(name="shutdown", aliases=["shut"], hidden=True)
|
@bot.command(name="shutdown", aliases=["shut"], category=cmn.cat.admin)
|
||||||
@commands.check(cmn.check_if_owner)
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _shutdown_bot(ctx: commands.Context):
|
async def _shutdown_bot(ctx: commands.Context):
|
||||||
"""Shuts down the bot."""
|
"""Shuts down the bot."""
|
||||||
@ -82,7 +82,7 @@ async def _shutdown_bot(ctx: commands.Context):
|
|||||||
await bot.logout()
|
await bot.logout()
|
||||||
|
|
||||||
|
|
||||||
@bot.group(name="extctl", aliases=["ex"], hidden=True)
|
@bot.group(name="extctl", aliases=["ex"], category=cmn.cat.admin)
|
||||||
@commands.check(cmn.check_if_owner)
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _extctl(ctx: commands.Context):
|
async def _extctl(ctx: commands.Context):
|
||||||
"""Extension control commands.
|
"""Extension control commands.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user