aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar GDWR <[email protected]>2022-02-03 19:57:12 +0000
committerGravatar GDWR <[email protected]>2022-02-03 19:57:12 +0000
commite02aee662043888ffcb982af694cea9da07403f2 (patch)
tree72bf55af5c5748a2657680d3a4cefb7b62c71164
parent♻️Move notifications into `_message.py` with predicate (diff)
👌 Remove the need to pass in channel via arguments
-rw-r--r--bot/exts/help_channels/_cog.py11
-rw-r--r--bot/exts/help_channels/_message.py17
2 files changed, 13 insertions, 15 deletions
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index aefa0718e..78b01aa03 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -238,10 +238,7 @@ class HelpChannels(commands.Cog):
if not channel:
log.info("Couldn't create a candidate channel; waiting to get one from the queue.")
- last_notification = await _message.notify_none_remaining(
- self.bot.get_channel(constants.HelpChannels.notify_channel),
- self.last_none_remaining_notification
- )
+ last_notification = await _message.notify_none_remaining(self.last_none_remaining_notification)
if last_notification:
self.last_none_remaining_notification = last_notification
@@ -249,11 +246,7 @@ class HelpChannels(commands.Cog):
channel = await self.wait_for_dormant_channel() # Blocks until a new channel is available
else:
- last_notification = await _message.notify_running_low(
- self.bot.get_channel(constants.HelpChannels.notify_channel),
- self.channel_queue.qsize(),
- self.last_running_low_notification
- )
+ last_notification = await _message.notify_running_low(self.channel_queue.qsize(), self.last_running_low_notification)
if last_notification:
self.last_running_low_notification = last_notification
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index 097e648e0..554aac7b4 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -124,7 +124,7 @@ async def dm_on_open(message: discord.Message) -> None:
)
-async def notify_none_remaining(channel: discord.TextChannel, last_notification: Arrow) -> t.Optional[Arrow]:
+async def notify_none_remaining(last_notification: Arrow) -> t.Optional[Arrow]:
"""
Send a pinging message in `channel` notifying about there being no dormant channels remaining.
@@ -145,6 +145,10 @@ async def notify_none_remaining(channel: discord.TextChannel, last_notification:
mentions = " ".join(f"<@&{role}>" for role in constants.HelpChannels.notify_none_remaining_roles)
allowed_roles = [discord.Object(id_) for id_ in constants.HelpChannels.notify_none_remaining_roles]
+ channel = bot.instance.get_channel(constants.HelpChannels.notify_channel)
+ if channel is None:
+ log.trace("Did not send none_remaining notification as the notification channel couldn't be gathered.")
+
try:
await channel.send(
f"{mentions} A new available help channel is needed but there "
@@ -160,11 +164,7 @@ async def notify_none_remaining(channel: discord.TextChannel, last_notification:
return arrow.utcnow()
-async def notify_running_low(
- channel: discord.TextChannel,
- number_of_channels_left: int,
- last_notification: Arrow
-) -> t.Optional[Arrow]:
+async def notify_running_low(number_of_channels_left: int, last_notification: Arrow) -> t.Optional[Arrow]:
"""
Send a non-pinging message in `channel` notifying about there being a low amount of dormant channels.
@@ -187,6 +187,11 @@ async def notify_running_low(
return None
log.trace("Notifying about getting close to no dormant channels.")
+
+ channel = bot.instance.get_channel(constants.HelpChannels.notify_channel)
+ if channel is None:
+ log.trace("Did not send notify_running notification as the notification channel couldn't be gathered.")
+
try:
await channel.send(
f"There are only {number_of_channels_left} dormant channels left. "