Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bot/cogs/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, bot: Bot):
@with_role(Roles.verified)
async def botinfo_group(self, ctx: Context) -> None:
"""Bot informational commands."""
await ctx.invoke(self.bot.get_command("help"), "bot")
await ctx.send_help(ctx.command)

@botinfo_group.command(name='about', aliases=('info',), hidden=True)
@with_role(Roles.verified)
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def predicate_regex(message: Message) -> bool:
@with_role(*MODERATION_ROLES)
async def clean_group(self, ctx: Context) -> None:
"""Commands for cleaning messages in channels."""
await ctx.invoke(self.bot.get_command("help"), "clean")
await ctx.send_help(ctx.command)

@clean_group.command(name="user", aliases=["users"])
@with_role(*MODERATION_ROLES)
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/defcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ async def on_member_join(self, member: Member) -> None:
@with_role(Roles.admins, Roles.owners)
async def defcon_group(self, ctx: Context) -> None:
"""Check the DEFCON status or run a subcommand."""
await ctx.invoke(self.bot.get_command("help"), "defcon")
await ctx.send_help(ctx.command)

async def _defcon_action(self, ctx: Context, days: int, action: Action) -> None:
"""Providing a structured way to do an defcon action."""
Expand Down
33 changes: 13 additions & 20 deletions bot/cogs/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import typing as t

from discord.ext.commands import Cog, Command, Context, errors
from discord.ext.commands import Cog, Context, errors
from sentry_sdk import push_scope

from bot.api import ResponseCodeError
Expand Down Expand Up @@ -79,19 +79,13 @@ async def on_command_error(self, ctx: Context, e: errors.CommandError) -> None:
f"{e.__class__.__name__}: {e}"
)

async def get_help_command(self, command: t.Optional[Command]) -> t.Tuple:
"""Return the help command invocation args to display help for `command`."""
parent = None
if command is not None:
parent = command.parent

# Retrieve the help command for the invoked command.
if parent and command:
return self.bot.get_command("help"), parent.name, command.name
elif command:
return self.bot.get_command("help"), command.name
else:
return self.bot.get_command("help")
@staticmethod
def get_help_command(ctx: Context) -> t.Coroutine:
"""Return a prepared `help` command invocation coroutine."""
if ctx.command:
return ctx.send_help(ctx.command)

return ctx.send_help()

async def try_silence(self, ctx: Context) -> bool:
"""
Expand Down Expand Up @@ -165,20 +159,19 @@ async def handle_user_input_error(self, ctx: Context, e: errors.UserInputError)
* ArgumentParsingError: send an error message
* Other: send an error message and the help command
"""
# TODO: use ctx.send_help() once PR #519 is merged.
help_command = await self.get_help_command(ctx.command)
prepared_help_command = self.get_help_command(ctx)

if isinstance(e, errors.MissingRequiredArgument):
await ctx.send(f"Missing required argument `{e.param.name}`.")
await ctx.invoke(*help_command)
await prepared_help_command
self.bot.stats.incr("errors.missing_required_argument")
elif isinstance(e, errors.TooManyArguments):
await ctx.send(f"Too many arguments provided.")
await ctx.invoke(*help_command)
await prepared_help_command
self.bot.stats.incr("errors.too_many_arguments")
elif isinstance(e, errors.BadArgument):
await ctx.send(f"Bad argument: {e}\n")
await ctx.invoke(*help_command)
await prepared_help_command
self.bot.stats.incr("errors.bad_argument")
elif isinstance(e, errors.BadUnionArgument):
await ctx.send(f"Bad argument: {e}\n```{e.errors[-1]}```")
Expand All @@ -188,7 +181,7 @@ async def handle_user_input_error(self, ctx: Context, e: errors.UserInputError)
self.bot.stats.incr("errors.argument_parsing_error")
else:
await ctx.send("Something about your input seems off. Check the arguments:")
await ctx.invoke(*help_command)
await prepared_help_command
self.bot.stats.incr("errors.other_user_input_error")

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def func(): # (None,) -> Any
async def internal_group(self, ctx: Context) -> None:
"""Internal commands. Top secret!"""
if not ctx.invoked_subcommand:
await ctx.invoke(self.bot.get_command("help"), "internal")
await ctx.send_help(ctx.command)

@internal_group.command(name='eval', aliases=('e',))
@with_role(Roles.admins, Roles.owners)
Expand Down
8 changes: 4 additions & 4 deletions bot/cogs/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(self, bot: Bot):
@group(name="extensions", aliases=("ext", "exts", "c", "cogs"), invoke_without_command=True)
async def extensions_group(self, ctx: Context) -> None:
"""Load, unload, reload, and list loaded extensions."""
await ctx.invoke(self.bot.get_command("help"), "extensions")
await ctx.send_help(ctx.command)

@extensions_group.command(name="load", aliases=("l",))
async def load_command(self, ctx: Context, *extensions: Extension) -> None:
Expand All @@ -75,7 +75,7 @@ async def load_command(self, ctx: Context, *extensions: Extension) -> None:
If '\*' or '\*\*' is given as the name, all unloaded extensions will be loaded.
""" # noqa: W605
if not extensions:
await ctx.invoke(self.bot.get_command("help"), "extensions load")
await ctx.send_help(ctx.command)
return

if "*" in extensions or "**" in extensions:
Expand All @@ -92,7 +92,7 @@ async def unload_command(self, ctx: Context, *extensions: Extension) -> None:
If '\*' or '\*\*' is given as the name, all loaded extensions will be unloaded.
""" # noqa: W605
if not extensions:
await ctx.invoke(self.bot.get_command("help"), "extensions unload")
await ctx.send_help(ctx.command)
return

blacklisted = "\n".join(UNLOAD_BLACKLIST & set(extensions))
Expand All @@ -118,7 +118,7 @@ async def reload_command(self, ctx: Context, *extensions: Extension) -> None:
If '\*\*' is given as the name, all extensions, including unloaded ones, will be reloaded.
""" # noqa: W605
if not extensions:
await ctx.invoke(self.bot.get_command("help"), "extensions reload")
await ctx.send_help(ctx.command)
return

if "**" in extensions:
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/moderation/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def infractions_cog(self) -> Infractions:
@commands.group(name='infraction', aliases=('infr', 'infractions', 'inf'), invoke_without_command=True)
async def infraction_group(self, ctx: Context) -> None:
"""Infraction manipulation commands."""
await ctx.invoke(self.bot.get_command("help"), "infraction")
await ctx.send_help(ctx.command)

@infraction_group.command(name='edit')
async def infraction_edit(
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/off_topic_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async def init_offtopic_updater(self) -> None:
@with_role(*MODERATION_ROLES)
async def otname_group(self, ctx: Context) -> None:
"""Add or list items from the off-topic channel name rotation."""
await ctx.invoke(self.bot.get_command("help"), "otname")
await ctx.send_help(ctx.command)

@otname_group.command(name='add', aliases=('a',))
@with_role(*MODERATION_ROLES)
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async def top_weekly_posts(self) -> None:
@group(name="reddit", invoke_without_command=True)
async def reddit_group(self, ctx: Context) -> None:
"""View the top posts from various subreddits."""
await ctx.invoke(self.bot.get_command("help"), "reddit")
await ctx.send_help(ctx.command)

@reddit_group.command(name="top")
async def top_command(self, ctx: Context, subreddit: Subreddit = "r/Python") -> None:
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async def list_reminders(self, ctx: Context) -> t.Optional[discord.Message]:
@remind_group.group(name="edit", aliases=("change", "modify"), invoke_without_command=True)
async def edit_reminder_group(self, ctx: Context) -> None:
"""Commands for modifying your current reminders."""
await ctx.invoke(self.bot.get_command("help"), "reminders", "edit")
await ctx.send_help(ctx.command)

@edit_reminder_group.command(name="duration", aliases=("time",))
async def edit_reminder_duration(self, ctx: Context, id_: int, expiration: Duration) -> None:
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, bot: Bot):
@group(name="site", aliases=("s",), invoke_without_command=True)
async def site_group(self, ctx: Context) -> None:
"""Commands for getting info about our website."""
await ctx.invoke(self.bot.get_command("help"), "site")
await ctx.send_help(ctx.command)

@site_group.command(name="home", aliases=("about",))
async def site_main(self, ctx: Context) -> None:
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ async def eval_command(self, ctx: Context, *, code: str = None) -> None:
return

if not code: # None or empty string
await ctx.invoke(self.bot.get_command("help"), "eval")
await ctx.send_help(ctx.command)
return

log.info(f"Received code from {ctx.author} for evaluation:\n{code}")
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def pep_command(self, ctx: Context, pep_number: str) -> None:
if pep_number.isdigit():
pep_number = int(pep_number)
else:
await ctx.invoke(self.bot.get_command("help"), "pep")
await ctx.send_help(ctx.command)
return

# Handle PEP 0 directly because it's not in .rst or .txt so it can't be accessed like other PEPs.
Expand Down
2 changes: 1 addition & 1 deletion bot/cogs/watchchannels/bigbrother.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, bot: Bot) -> None:
@with_role(*MODERATION_ROLES)
async def bigbrother_group(self, ctx: Context) -> None:
"""Monitors users by relaying their messages to the Big Brother watch channel."""
await ctx.invoke(self.bot.get_command("help"), "bigbrother")
await ctx.send_help(ctx.command)

@bigbrother_group.command(name='watched', aliases=('all', 'list'))
@with_role(*MODERATION_ROLES)
Expand Down
4 changes: 2 additions & 2 deletions bot/cogs/watchchannels/talentpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, bot: Bot) -> None:
@with_role(*MODERATION_ROLES)
async def nomination_group(self, ctx: Context) -> None:
"""Highlights the activity of helper nominees by relaying their messages to the talent pool channel."""
await ctx.invoke(self.bot.get_command("help"), "talentpool")
await ctx.send_help(ctx.command)

@nomination_group.command(name='watched', aliases=('all', 'list'))
@with_role(*MODERATION_ROLES)
Expand Down Expand Up @@ -173,7 +173,7 @@ async def unwatch_command(self, ctx: Context, user: FetchedMember, *, reason: st
@with_role(*MODERATION_ROLES)
async def nomination_edit_group(self, ctx: Context) -> None:
"""Commands to edit nominations."""
await ctx.invoke(self.bot.get_command("help"), "talentpool", "edit")
await ctx.send_help(ctx.command)

@nomination_edit_group.command(name='reason')
@with_role(*MODERATION_ROLES)
Expand Down
5 changes: 2 additions & 3 deletions tests/bot/cogs/test_snekbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,9 @@ async def test_eval_command_reject_two_eval_at_the_same_time(self):

async def test_eval_command_call_help(self):
"""Test if the eval command call the help command if no code is provided."""
ctx = MockContext()
ctx.invoke = AsyncMock()
ctx = MockContext(command="sentinel")
await self.cog.eval_command.callback(self.cog, ctx=ctx, code='')
ctx.invoke.assert_called_once_with(self.bot.get_command("help"), "eval")
ctx.send_help.assert_called_once_with("sentinel")

async def test_send_eval(self):
"""Test the send_eval function."""
Expand Down