mirror of
https://github.com/miaowware/qrm2.git
synced 2025-07-07 10:25:15 -04:00
helpcommand now verifies checks when displaying help
Additionally: - added admin category - removed hidden flag from commands - added checks to all extctl commands Fixes #109
This commit is contained in:
parent
61f0c9423e
commit
831667ec10
@ -40,7 +40,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='❌',
|
||||||
|
34
exts/base.py
34
exts/base.py
@ -23,11 +23,13 @@ import common as cmn
|
|||||||
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)
|
||||||
@ -35,7 +37,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)
|
||||||
@ -59,10 +61,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():
|
||||||
if self.context.author.id not in opt.owners_uids:
|
|
||||||
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])
|
||||||
@ -73,22 +74,23 @@ 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 not command.hidden or self.context.author.id in opt.owners_uids:
|
if self.verify_checks and not await command.can_run(self.context):
|
||||||
|
raise commands.CheckFailure
|
||||||
|
return
|
||||||
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)
|
||||||
else:
|
|
||||||
await cmn.add_react(self.context, cmn.no_entry)
|
|
||||||
|
|
||||||
async def send_group_help(self, group):
|
async def send_group_help(self, group):
|
||||||
if not group.hidden or self.context.author.id in opt.owners_uids:
|
if self.verify_checks and not await group.can_run(self.context):
|
||||||
|
raise commands.CheckFailure
|
||||||
|
return
|
||||||
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):
|
||||||
if not cmd.hidden or self.context.author.id in opt.owners_uids:
|
embed.add_field(name=await self.get_command_signature(cmd), value=cmd.help, inline=False)
|
||||||
embed.add_field(name=self.get_command_signature(cmd), value=cmd.help, inline=False)
|
|
||||||
await self.context.send(embed=embed)
|
await self.context.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@ -170,12 +172,12 @@ 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="bruce", hidden=True)
|
@commands.command(name="bruce")
|
||||||
async def _b_issue(self, ctx: commands.Context):
|
async def _b_issue(self, ctx: commands.Context):
|
||||||
"""Shows how to create an issue for the bot."""
|
"""Shows how to create an issue for the bot."""
|
||||||
await ctx.invoke(self._issue)
|
await ctx.invoke(self._issue)
|
||||||
|
|
||||||
@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, channel: commands.TextChannelConverter, *, msg: str):
|
async def _echo(self, ctx: commands.Context, channel: commands.TextChannelConverter, *, msg: str):
|
||||||
"""Send a message in a channel as qrm. Only works within a server or DM to server, not between servers."""
|
"""Send a message in a channel as qrm. Only works within a server or DM to server, not between servers."""
|
||||||
|
@ -30,7 +30,7 @@ class FunCog(commands.Cog):
|
|||||||
'''Returns an xkcd about tar.'''
|
'''Returns an xkcd about tar.'''
|
||||||
await ctx.send('http://xkcd.com/1168')
|
await ctx.send('http://xkcd.com/1168')
|
||||||
|
|
||||||
@commands.command(name="xd", hidden=True, category=cmn.cat.fun)
|
@commands.command(name="xd", category=cmn.cat.fun)
|
||||||
async def _xd(self, ctx: commands.Context):
|
async def _xd(self, ctx: commands.Context):
|
||||||
'''ecks dee'''
|
'''ecks dee'''
|
||||||
await ctx.send('ECKS DEE :smirk:')
|
await ctx.send('ECKS DEE :smirk:')
|
||||||
|
18
main.py
18
main.py
@ -50,7 +50,7 @@ bot.qrm.debug_mode = debug_mode
|
|||||||
|
|
||||||
# --- Commands ---
|
# --- Commands ---
|
||||||
|
|
||||||
@bot.command(name="restart", hidden=True)
|
@bot.command(name="restart", 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."""
|
||||||
@ -62,7 +62,7 @@ async def _restart_bot(ctx: commands.Context):
|
|||||||
await bot.logout()
|
await bot.logout()
|
||||||
|
|
||||||
|
|
||||||
@bot.command(name="shutdown", hidden=True)
|
@bot.command(name="shutdown", 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."""
|
||||||
@ -74,7 +74,7 @@ async def _shutdown_bot(ctx: commands.Context):
|
|||||||
await bot.logout()
|
await bot.logout()
|
||||||
|
|
||||||
|
|
||||||
@bot.group(name="extctl", hidden=True)
|
@bot.group(name="extctl", 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.
|
||||||
@ -84,7 +84,8 @@ async def _extctl(ctx: commands.Context):
|
|||||||
await ctx.invoke(cmd)
|
await ctx.invoke(cmd)
|
||||||
|
|
||||||
|
|
||||||
@_extctl.command(name="list")
|
@_extctl.command(name="list", category=cmn.cat.admin)
|
||||||
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _extctl_list(ctx: commands.Context):
|
async def _extctl_list(ctx: commands.Context):
|
||||||
"""Lists Extensions."""
|
"""Lists Extensions."""
|
||||||
embed = cmn.embed_factory(ctx)
|
embed = cmn.embed_factory(ctx)
|
||||||
@ -93,7 +94,8 @@ async def _extctl_list(ctx: commands.Context):
|
|||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@_extctl.command(name="load")
|
@_extctl.command(name="load", category=cmn.cat.admin)
|
||||||
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _extctl_load(ctx: commands.Context, extension: str):
|
async def _extctl_load(ctx: commands.Context, extension: str):
|
||||||
try:
|
try:
|
||||||
bot.load_extension(ext_dir + "." + extension)
|
bot.load_extension(ext_dir + "." + extension)
|
||||||
@ -103,7 +105,8 @@ async def _extctl_load(ctx: commands.Context, extension: str):
|
|||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@_extctl.command(name="reload", aliases=["relaod"])
|
@_extctl.command(name="reload", aliases=["relaod"], category=cmn.cat.admin)
|
||||||
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _extctl_reload(ctx: commands.Context, extension: str):
|
async def _extctl_reload(ctx: commands.Context, extension: str):
|
||||||
if ctx.invoked_with == "relaod":
|
if ctx.invoked_with == "relaod":
|
||||||
pika = bot.get_emoji(opt.pika)
|
pika = bot.get_emoji(opt.pika)
|
||||||
@ -117,7 +120,8 @@ async def _extctl_reload(ctx: commands.Context, extension: str):
|
|||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
@_extctl.command(name="unload")
|
@_extctl.command(name="unload", category=cmn.cat.admin)
|
||||||
|
@commands.check(cmn.check_if_owner)
|
||||||
async def _extctl_unload(ctx: commands.Context, extension: str):
|
async def _extctl_unload(ctx: commands.Context, extension: str):
|
||||||
try:
|
try:
|
||||||
bot.unload_extension(ext_dir + "." + extension)
|
bot.unload_extension(ext_dir + "." + extension)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user