aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/core
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/core')
-rw-r--r--bot/exts/core/error_handler.py7
-rw-r--r--bot/exts/core/extensions.py44
-rw-r--r--bot/exts/core/help.py6
-rw-r--r--bot/exts/core/internal_eval/__init__.py4
-rw-r--r--bot/exts/core/internal_eval/_internal_eval.py3
-rw-r--r--bot/exts/core/ping.py4
-rw-r--r--bot/exts/core/source.py4
7 files changed, 35 insertions, 37 deletions
diff --git a/bot/exts/core/error_handler.py b/bot/exts/core/error_handler.py
index 4578f734..f62b3d4e 100644
--- a/bot/exts/core/error_handler.py
+++ b/bot/exts/core/error_handler.py
@@ -171,9 +171,8 @@ class CommandErrorHandler(commands.Cog):
if not await similar_command.can_run(ctx):
log.debug(log_msg)
continue
- except commands.errors.CommandError as cmd_error:
+ except commands.errors.CommandError:
log.debug(log_msg)
- await self.on_command_error(ctx, cmd_error)
continue
command_suggestions.append(similar_command_name)
@@ -187,6 +186,6 @@ class CommandErrorHandler(commands.Cog):
await ctx.send(embed=e, delete_after=RedirectOutput.delete_delay)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the ErrorHandler cog."""
- bot.add_cog(CommandErrorHandler(bot))
+ await bot.add_cog(CommandErrorHandler(bot))
diff --git a/bot/exts/core/extensions.py b/bot/exts/core/extensions.py
index d809d2b9..5b958c02 100644
--- a/bot/exts/core/extensions.py
+++ b/bot/exts/core/extensions.py
@@ -4,6 +4,7 @@ from collections.abc import Mapping
from enum import Enum
from typing import Optional
+from botcore.utils._extensions import unqualify
from discord import Colour, Embed
from discord.ext import commands
from discord.ext.commands import Context, group
@@ -12,7 +13,6 @@ 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, invoke_help_command, unqualify
from bot.utils.pagination import LinePaginator
log = logging.getLogger(__name__)
@@ -46,13 +46,13 @@ class Extension(commands.Converter):
argument = argument.lower()
- if argument in EXTENSIONS:
+ if argument in ctx.bot.all_extensions:
return argument
- elif (qualified_arg := f"{exts.__name__}.{argument}") in EXTENSIONS:
+ elif (qualified_arg := f"{exts.__name__}.{argument}") in ctx.bot.all_extensions:
return qualified_arg
matches = []
- for ext in EXTENSIONS:
+ for ext in ctx.bot.all_extensions:
if argument == unqualify(ext):
matches.append(ext)
@@ -78,7 +78,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 invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@extensions_group.command(name="load", aliases=("l",))
async def load_command(self, ctx: Context, *extensions: Extension) -> None:
@@ -88,13 +88,13 @@ class Extensions(commands.Cog):
If '\*' or '\*\*' is given as the name, all unloaded extensions will be loaded.
""" # noqa: W605
if not extensions:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
return
if "*" in extensions or "**" in extensions:
- extensions = set(EXTENSIONS) - set(self.bot.extensions.keys())
+ extensions = set(self.bot.all_extensions) - set(self.bot.extensions.keys())
- msg = self.batch_manage(Action.LOAD, *extensions)
+ msg = await self.batch_manage(Action.LOAD, *extensions)
await ctx.send(msg)
@extensions_group.command(name="unload", aliases=("ul",))
@@ -105,7 +105,7 @@ class Extensions(commands.Cog):
If '\*' or '\*\*' is given as the name, all loaded extensions will be unloaded.
""" # noqa: W605
if not extensions:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
return
blacklisted = "\n".join(UNLOAD_BLACKLIST & set(extensions))
@@ -116,7 +116,7 @@ class Extensions(commands.Cog):
if "*" in extensions or "**" in extensions:
extensions = set(self.bot.extensions.keys()) - UNLOAD_BLACKLIST
- msg = self.batch_manage(Action.UNLOAD, *extensions)
+ msg = await self.batch_manage(Action.UNLOAD, *extensions)
await ctx.send(msg)
@@ -131,16 +131,16 @@ class Extensions(commands.Cog):
If '\*\*' is given as the name, all extensions, including unloaded ones, will be reloaded.
""" # noqa: W605
if not extensions:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
return
if "**" in extensions:
- extensions = EXTENSIONS
+ extensions = self.bot.all_extensions
elif "*" in extensions:
extensions = set(self.bot.extensions.keys()) | set(extensions)
extensions.remove("*")
- msg = self.batch_manage(Action.RELOAD, *extensions)
+ msg = await self.batch_manage(Action.RELOAD, *extensions)
await ctx.send(msg)
@@ -175,7 +175,7 @@ class Extensions(commands.Cog):
"""Return a mapping of extension names and statuses to their categories."""
categories = {}
- for ext in EXTENSIONS:
+ for ext in self.bot.all_extensions:
if ext in self.bot.extensions:
status = Emojis.status_online
else:
@@ -191,21 +191,21 @@ class Extensions(commands.Cog):
return categories
- def batch_manage(self, action: Action, *extensions: str) -> str:
+ async def batch_manage(self, action: Action, *extensions: str) -> str:
"""
Apply an action to multiple extensions and return a message with the results.
If only one extension is given, it is deferred to `manage()`.
"""
if len(extensions) == 1:
- msg, _ = self.manage(action, extensions[0])
+ msg, _ = await self.manage(action, extensions[0])
return msg
verb = action.name.lower()
failures = {}
for extension in extensions:
- _, error = self.manage(action, extension)
+ _, error = await self.manage(action, extension)
if error:
failures[extension] = error
@@ -220,17 +220,17 @@ class Extensions(commands.Cog):
return msg
- def manage(self, action: Action, ext: str) -> tuple[str, Optional[str]]:
+ async def manage(self, action: Action, ext: str) -> tuple[str, Optional[str]]:
"""Apply an action to an extension and return the status message and any error message."""
verb = action.name.lower()
error_msg = None
try:
- action.value(self.bot, ext)
+ await action.value(self.bot, ext)
except (commands.ExtensionAlreadyLoaded, commands.ExtensionNotLoaded):
if action is Action.RELOAD:
# When reloading, just load the extension if it was not loaded.
- return self.manage(Action.LOAD, ext)
+ return await self.manage(Action.LOAD, ext)
msg = f":x: Extension `{ext}` is already {verb}ed."
log.debug(msg[4:])
@@ -261,6 +261,6 @@ class Extensions(commands.Cog):
error.handled = True
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Extensions cog."""
- bot.add_cog(Extensions(bot))
+ await bot.add_cog(Extensions(bot))
diff --git a/bot/exts/core/help.py b/bot/exts/core/help.py
index eb7a9762..30deaff4 100644
--- a/bot/exts/core/help.py
+++ b/bot/exts/core/help.py
@@ -220,11 +220,11 @@ class HelpSession:
async def prepare(self) -> None:
"""Sets up the help session pages, events, message and reactions."""
await self.build_pages()
+ await self.update_page()
self._bot.add_listener(self.on_reaction_add)
self._bot.add_listener(self.on_message_delete)
- await self.update_page()
self.add_reactions()
def add_reactions(self) -> None:
@@ -547,7 +547,7 @@ def unload(bot: Bot) -> None:
bot.add_command(bot._old_help)
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""
The setup for the help extension.
@@ -562,7 +562,7 @@ def setup(bot: Bot) -> None:
bot.remove_command("help")
try:
- bot.add_cog(Help())
+ await bot.add_cog(Help())
except Exception:
unload(bot)
raise
diff --git a/bot/exts/core/internal_eval/__init__.py b/bot/exts/core/internal_eval/__init__.py
index 695fa74d..258f7fd8 100644
--- a/bot/exts/core/internal_eval/__init__.py
+++ b/bot/exts/core/internal_eval/__init__.py
@@ -1,10 +1,10 @@
from bot.bot import Bot
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Set up the Internal Eval extension."""
# Import the Cog at runtime to prevent side effects like defining
# RedisCache instances too early.
from ._internal_eval import InternalEval
- bot.add_cog(InternalEval(bot))
+ await bot.add_cog(InternalEval(bot))
diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py
index 190a15ec..2daf8ef9 100644
--- a/bot/exts/core/internal_eval/_internal_eval.py
+++ b/bot/exts/core/internal_eval/_internal_eval.py
@@ -9,7 +9,6 @@ from discord.ext import commands
from bot.bot import Bot
from bot.constants import Client, Roles
from bot.utils.decorators import with_role
-from bot.utils.extensions import invoke_help_command
from ._helpers import EvalContext
@@ -154,7 +153,7 @@ class InternalEval(commands.Cog):
async def internal_group(self, ctx: commands.Context) -> None:
"""Internal commands. Top secret!"""
if not ctx.invoked_subcommand:
- await invoke_help_command(ctx)
+ await self.bot.invoke_help_command(ctx)
@internal_group.command(name="eval", aliases=("e",))
@with_role(Roles.admins)
diff --git a/bot/exts/core/ping.py b/bot/exts/core/ping.py
index 6be78117..cb32398e 100644
--- a/bot/exts/core/ping.py
+++ b/bot/exts/core/ping.py
@@ -40,6 +40,6 @@ class Ping(commands.Cog):
await ctx.send(f"I started up {uptime_string}.")
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the Ping cog."""
- bot.add_cog(Ping(bot))
+ await bot.add_cog(Ping(bot))
diff --git a/bot/exts/core/source.py b/bot/exts/core/source.py
index 2801be0f..f771eaca 100644
--- a/bot/exts/core/source.py
+++ b/bot/exts/core/source.py
@@ -82,6 +82,6 @@ class BotSource(commands.Cog):
return embed
-def setup(bot: Bot) -> None:
+async def setup(bot: Bot) -> None:
"""Load the BotSource cog."""
- bot.add_cog(BotSource())
+ await bot.add_cog(BotSource())