aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
authorGravatar ks129 <[email protected]>2021-03-13 17:43:55 +0200
committerGravatar GitHub <[email protected]>2021-03-13 17:43:55 +0200
commit0f69e00aa55ca7294e71e19ab41b57bef7a9f977 (patch)
tree7deaf95949693aafc7592dfe7933425ebdc8f6dc /bot
parentMerge pull request #619 from JagTheFriend/master (diff)
parentmake invoke_help_command only take ctx (diff)
Merge pull request #625 from ToxicKidz/no-ctx-send-help
change ctx.send_help to ctx.invoke(help_command)
Diffstat (limited to 'bot')
-rw-r--r--bot/exts/christmas/advent_of_code/_cog.py3
-rw-r--r--bot/exts/evergreen/emoji.py3
-rw-r--r--bot/exts/evergreen/game.py3
-rw-r--r--bot/exts/evergreen/minesweeper.py3
-rw-r--r--bot/exts/evergreen/movie.py3
-rw-r--r--bot/exts/evergreen/snakes/_snakes_cog.py3
-rw-r--r--bot/exts/evergreen/space.py3
-rw-r--r--bot/exts/evergreen/status_codes.py4
-rw-r--r--bot/exts/utils/extensions.py10
-rw-r--r--bot/exts/valentines/be_my_valentine.py3
-rw-r--r--bot/utils/extensions.py10
11 files changed, 34 insertions, 14 deletions
diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py
index 29902306..dc3d7616 100644
--- a/bot/exts/christmas/advent_of_code/_cog.py
+++ b/bot/exts/christmas/advent_of_code/_cog.py
@@ -12,6 +12,7 @@ from bot.constants import (
)
from bot.exts.christmas.advent_of_code import _helpers
from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role
+from bot.utils.extensions import invoke_help_command
log = logging.getLogger(__name__)
@@ -51,7 +52,7 @@ class AdventOfCode(commands.Cog):
async def adventofcode_group(self, ctx: commands.Context) -> None:
"""All of the Advent of Code commands."""
if not ctx.invoked_subcommand:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@adventofcode_group.command(
name="subscribe",
diff --git a/bot/exts/evergreen/emoji.py b/bot/exts/evergreen/emoji.py
index 99f71218..fa3044e3 100644
--- a/bot/exts/evergreen/emoji.py
+++ b/bot/exts/evergreen/emoji.py
@@ -9,6 +9,7 @@ from discord import Color, Embed, Emoji
from discord.ext import commands
from bot.constants import Colours, ERROR_REPLIES
+from bot.utils.extensions import invoke_help_command
from bot.utils.pagination import LinePaginator
from bot.utils.time import time_since
@@ -75,7 +76,7 @@ class Emojis(commands.Cog):
if emoji is not None:
await ctx.invoke(self.info_command, emoji)
else:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@emoji_group.command(name="count", aliases=("c",))
async def count_command(self, ctx: commands.Context, *, category_query: str = None) -> None:
diff --git a/bot/exts/evergreen/game.py b/bot/exts/evergreen/game.py
index d37be0e2..068d3f68 100644
--- a/bot/exts/evergreen/game.py
+++ b/bot/exts/evergreen/game.py
@@ -15,6 +15,7 @@ from discord.ext.commands import Cog, Context, group
from bot.bot import Bot
from bot.constants import STAFF_ROLES, Tokens
from bot.utils.decorators import with_role
+from bot.utils.extensions import invoke_help_command
from bot.utils.pagination import ImagePaginator, LinePaginator
# Base URL of IGDB API
@@ -234,7 +235,7 @@ class Games(Cog):
"""
# When user didn't specified genre, send help message
if genre is None:
- await ctx.send_help("games")
+ await invoke_help_command(ctx)
return
# Capitalize genre for check
diff --git a/bot/exts/evergreen/minesweeper.py b/bot/exts/evergreen/minesweeper.py
index 286ac7a5..3031debc 100644
--- a/bot/exts/evergreen/minesweeper.py
+++ b/bot/exts/evergreen/minesweeper.py
@@ -8,6 +8,7 @@ from discord.ext import commands
from bot.constants import Client
from bot.utils.exceptions import UserNotPlayingError
+from bot.utils.extensions import invoke_help_command
MESSAGE_MAPPING = {
0: ":stop_button:",
@@ -83,7 +84,7 @@ class Minesweeper(commands.Cog):
@commands.group(name='minesweeper', aliases=('ms',), invoke_without_command=True)
async def minesweeper_group(self, ctx: commands.Context) -> None:
"""Commands for Playing Minesweeper."""
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@staticmethod
def get_neighbours(x: int, y: int) -> typing.Generator[typing.Tuple[int, int], None, None]:
diff --git a/bot/exts/evergreen/movie.py b/bot/exts/evergreen/movie.py
index 340a5724..b3bfe998 100644
--- a/bot/exts/evergreen/movie.py
+++ b/bot/exts/evergreen/movie.py
@@ -9,6 +9,7 @@ from discord import Embed
from discord.ext.commands import Bot, Cog, Context, group
from bot.constants import Tokens
+from bot.utils.extensions import invoke_help_command
from bot.utils.pagination import ImagePaginator
# Define base URL of TMDB
@@ -73,7 +74,7 @@ class Movie(Cog):
try:
result = await self.get_movies_list(self.http_session, MovieGenres[genre].value, 1)
except KeyError:
- await ctx.send_help('movies')
+ await invoke_help_command(ctx)
return
# Check if "results" is in result. If not, throw error.
diff --git a/bot/exts/evergreen/snakes/_snakes_cog.py b/bot/exts/evergreen/snakes/_snakes_cog.py
index d5e4f206..3732b559 100644
--- a/bot/exts/evergreen/snakes/_snakes_cog.py
+++ b/bot/exts/evergreen/snakes/_snakes_cog.py
@@ -22,6 +22,7 @@ from bot.constants import ERROR_REPLIES, Tokens
from bot.exts.evergreen.snakes import _utils as utils
from bot.exts.evergreen.snakes._converter import Snake
from bot.utils.decorators import locked
+from bot.utils.extensions import invoke_help_command
log = logging.getLogger(__name__)
@@ -440,7 +441,7 @@ class Snakes(Cog):
@group(name='snakes', aliases=('snake',), invoke_without_command=True)
async def snakes_group(self, ctx: Context) -> None:
"""Commands from our first code jam."""
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@bot_has_permissions(manage_messages=True)
@snakes_group.command(name='antidote')
diff --git a/bot/exts/evergreen/space.py b/bot/exts/evergreen/space.py
index bc8e3118..323ff659 100644
--- a/bot/exts/evergreen/space.py
+++ b/bot/exts/evergreen/space.py
@@ -10,6 +10,7 @@ from discord.ext.commands import BadArgument, Cog, Context, Converter, group
from bot.bot import Bot
from bot.constants import Tokens
+from bot.utils.extensions import invoke_help_command
logger = logging.getLogger(__name__)
@@ -63,7 +64,7 @@ class Space(Cog):
@group(name="space", invoke_without_command=True)
async def space(self, ctx: Context) -> None:
"""Head command that contains commands about space."""
- await ctx.send_help("space")
+ await invoke_help_command(ctx)
@space.command(name="apod")
async def apod(self, ctx: Context, date: Optional[str] = None) -> None:
diff --git a/bot/exts/evergreen/status_codes.py b/bot/exts/evergreen/status_codes.py
index 874c87eb..7c00fe20 100644
--- a/bot/exts/evergreen/status_codes.py
+++ b/bot/exts/evergreen/status_codes.py
@@ -3,6 +3,8 @@ from http import HTTPStatus
import discord
from discord.ext import commands
+from bot.utils.extensions import invoke_help_command
+
HTTP_DOG_URL = "https://httpstatusdogs.com/img/{code}.jpg"
HTTP_CAT_URL = "https://http.cat/{code}.jpg"
@@ -17,7 +19,7 @@ class HTTPStatusCodes(commands.Cog):
async def http_status_group(self, ctx: commands.Context) -> None:
"""Group containing dog and cat http status code commands."""
if not ctx.invoked_subcommand:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@http_status_group.command(name='cat')
async def http_cat(self, ctx: commands.Context, code: int) -> None:
diff --git a/bot/exts/utils/extensions.py b/bot/exts/utils/extensions.py
index bb22c353..64e404d2 100644
--- a/bot/exts/utils/extensions.py
+++ b/bot/exts/utils/extensions.py
@@ -11,7 +11,7 @@ from bot import exts
from bot.bot import Bot
from bot.constants import Client, Emojis, MODERATION_ROLES, Roles
from bot.utils.checks import with_role_check
-from bot.utils.extensions import EXTENSIONS, unqualify
+from bot.utils.extensions import EXTENSIONS, invoke_help_command, unqualify
from bot.utils.pagination import LinePaginator
log = logging.getLogger(__name__)
@@ -77,7 +77,7 @@ class Extensions(commands.Cog):
@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.send_help(ctx.command)
+ await invoke_help_command(ctx)
@extensions_group.command(name="load", aliases=("l",))
async def load_command(self, ctx: Context, *extensions: Extension) -> None:
@@ -87,7 +87,7 @@ class Extensions(commands.Cog):
If '\*' or '\*\*' is given as the name, all unloaded extensions will be loaded.
""" # noqa: W605
if not extensions:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
return
if "*" in extensions or "**" in extensions:
@@ -104,7 +104,7 @@ class Extensions(commands.Cog):
If '\*' or '\*\*' is given as the name, all loaded extensions will be unloaded.
""" # noqa: W605
if not extensions:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
return
blacklisted = "\n".join(UNLOAD_BLACKLIST & set(extensions))
@@ -130,7 +130,7 @@ class Extensions(commands.Cog):
If '\*\*' is given as the name, all extensions, including unloaded ones, will be reloaded.
""" # noqa: W605
if not extensions:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
return
if "**" in extensions:
diff --git a/bot/exts/valentines/be_my_valentine.py b/bot/exts/valentines/be_my_valentine.py
index f3392bcb..09591cf8 100644
--- a/bot/exts/valentines/be_my_valentine.py
+++ b/bot/exts/valentines/be_my_valentine.py
@@ -10,6 +10,7 @@ from discord.ext.commands.cooldowns import BucketType
from bot.constants import Channels, Colours, Lovefest, Month
from bot.utils.decorators import in_month
+from bot.utils.extensions import invoke_help_command
log = logging.getLogger(__name__)
@@ -43,7 +44,7 @@ class BeMyValentine(commands.Cog):
2) use the command \".lovefest unsub\" to get rid of the lovefest role.
"""
if not ctx.invoked_subcommand:
- await ctx.send_help(ctx.command)
+ await invoke_help_command(ctx)
@lovefest_role.command(name="sub")
async def add_role(self, ctx: commands.Context) -> None:
diff --git a/bot/utils/extensions.py b/bot/utils/extensions.py
index 50350ea8..459588a1 100644
--- a/bot/utils/extensions.py
+++ b/bot/utils/extensions.py
@@ -3,6 +3,8 @@ import inspect
import pkgutil
from typing import Iterator, NoReturn
+from discord.ext.commands import Context
+
from bot import exts
@@ -31,4 +33,12 @@ def walk_extensions() -> Iterator[str]:
yield module.name
+async def invoke_help_command(ctx: Context) -> None:
+ """Invoke the help command or default help command if help extensions is not loaded."""
+ if 'bot.exts.evergreen.help' in ctx.bot.extensions:
+ help_command = ctx.bot.get_command('help')
+ await ctx.invoke(help_command, ctx.command.qualified_name)
+ return
+ await ctx.send_help(ctx.command)
+
EXTENSIONS = frozenset(walk_extensions())