aboutsummaryrefslogtreecommitdiffstats
path: root/bot
diff options
context:
space:
mode:
Diffstat (limited to 'bot')
-rw-r--r--bot/bot.py31
-rw-r--r--bot/exts/events/advent_of_code/_cog.py2
-rw-r--r--bot/exts/utilities/logging.py42
3 files changed, 45 insertions, 30 deletions
diff --git a/bot/bot.py b/bot/bot.py
index 221bfd62..226f9890 100644
--- a/bot/bot.py
+++ b/bot/bot.py
@@ -40,34 +40,11 @@ class Bot(BotBase):
else:
await super().on_command_error(context, exception)
- async def check_channels(self) -> None:
- """Verifies that all channel constants refer to channels which exist."""
- await self.wait_until_guild_available()
-
- if constants.Client.debug:
- log.info("Skipping Channels Check.")
- return
-
- all_channels_ids = [channel.id for channel in self.get_all_channels()]
- for name, channel_id in vars(constants.Channels).items():
- if name.startswith("_"):
- continue
- if channel_id not in all_channels_ids:
- log.error(f'Channel "{name}" with ID {channel_id} missing')
-
- async def send_log(self, title: str, details: str = None, *, icon: str = None) -> None:
- """Send an embed message to the devlog channel."""
+ async def log_to_dev_log(self, title: str, details: str = None, *, icon: str = None) -> None:
+ """Send an embed message to the dev-log channel."""
await self.wait_until_guild_available()
devlog = self.get_channel(constants.Channels.devlog)
- if not devlog:
- log.info(f"Fetching devlog channel as it wasn't found in the cache (ID: {constants.Channels.devlog})")
- try:
- devlog = await self.fetch_channel(constants.Channels.devlog)
- except discord.HTTPException as discord_exc:
- log.exception("Fetch failed", exc_info=discord_exc)
- return
-
if not icon:
icon = self.user.display_avatar.url
@@ -80,10 +57,6 @@ class Bot(BotBase):
"""Default async initialisation method for discord.py."""
await super().setup_hook()
- await self.check_channels()
-
# This is not awaited to avoid a deadlock with any cogs that have
# wait_until_guild_available in their cog_load method.
scheduling.create_task(self.load_extensions(exts))
-
- await self.send_log(self.name, "Connected!")
diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py
index 518841d4..1d8b0ca7 100644
--- a/bot/exts/events/advent_of_code/_cog.py
+++ b/bot/exts/events/advent_of_code/_cog.py
@@ -87,7 +87,7 @@ class AdventOfCode(commands.Cog):
try:
leaderboard = await _helpers.fetch_leaderboard()
except _helpers.FetchingLeaderboardFailedError:
- await self.bot.send_log("Unable to fetch AoC leaderboard during role sync.")
+ await self.bot.log_to_dev_log("Unable to fetch AoC leaderboard during role sync.")
return
placement_leaderboard = json.loads(leaderboard["placement_leaderboard"])
diff --git a/bot/exts/utilities/logging.py b/bot/exts/utilities/logging.py
new file mode 100644
index 00000000..e1d09fdf
--- /dev/null
+++ b/bot/exts/utilities/logging.py
@@ -0,0 +1,42 @@
+from botcore.utils.logging import get_logger
+from discord.ext.commands import Cog
+
+from bot import constants
+from bot.bot import Bot
+
+log = get_logger(__name__)
+
+
+class Logging(Cog):
+ """Debug logging module."""
+
+ def __init__(self, bot: Bot):
+ self.bot = bot
+
+ async def cog_load(self) -> None:
+ """Announce our presence to the configured dev-log channel after checking channel constants."""
+ await self.check_channels()
+ await self.bot.log_to_dev_log(
+ title=self.bot.name,
+ details="Connected!",
+ )
+
+ async def check_channels(self) -> None:
+ """Verifies that all channel constants refer to channels which exist."""
+ await self.bot.wait_until_guild_available()
+
+ if constants.Client.debug:
+ log.info("Skipping Channels Check.")
+ return
+
+ all_channels_ids = [channel.id for channel in self.bot.get_all_channels()]
+ for name, channel_id in vars(constants.Channels).items():
+ if name.startswith("_"):
+ continue
+ if channel_id not in all_channels_ids:
+ log.error(f'Channel "{name}" with ID {channel_id} missing')
+
+
+async def setup(bot: Bot) -> None:
+ """Load the Logging cog."""
+ await bot.add_cog(Logging(bot))