aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar GDWR <[email protected]>2022-02-01 00:24:12 +0000
committerGravatar GDWR <[email protected]>2022-02-01 00:24:12 +0000
commit554e520aa0fbd928c02e90b3d263d64e3a4f6daf (patch)
tree29e0f405b2a33b1f98b96977824b8c856b57991e
parent💡 Update docstrings (diff)
✨ Notify running low on channels
-rw-r--r--bot/exts/help_channels/_cog.py19
-rw-r--r--bot/exts/help_channels/_message.py38
-rw-r--r--config-default.yml2
3 files changed, 29 insertions, 30 deletions
diff --git a/bot/exts/help_channels/_cog.py b/bot/exts/help_channels/_cog.py
index 46f09f29a..85799516c 100644
--- a/bot/exts/help_channels/_cog.py
+++ b/bot/exts/help_channels/_cog.py
@@ -78,7 +78,10 @@ class HelpChannels(commands.Cog):
self.channel_queue: asyncio.Queue[discord.TextChannel] = None
self.name_queue: t.Deque[str] = None
- self.last_notification: t.Optional[arrow.Arrow] = None
+ # Notifications
+ self.notify_interval_seconds = (constants.HelpChannels.notify_minutes * 60)
+ self.last_none_remaining_notification = arrow.get('1815-12-10T18:00:00.00000+00:00')
+ self.last_running_low_notification = arrow.get('1815-12-10T18:00:00.00000+00:00')
self.dynamic_message: t.Optional[int] = None
self.available_help_channels: t.Set[discord.TextChannel] = set()
@@ -229,16 +232,22 @@ class HelpChannels(commands.Cog):
try:
channel = self.channel_queue.get_nowait()
+
+ within_interval = (arrow.utcnow() - self.last_running_low_notification).seconds >= self.notify_interval_seconds
+ if within_interval and self.channel_queue.qsize() <= constants.HelpChannels.notify_running_low_threshold:
+ await _message.notify_running_low(self.bot.get_channel(constants.HelpChannels.notify_channel), self.channel_queue.qsize())
+ self.last_running_low_notification = arrow.utcnow()
+
except asyncio.QueueEmpty:
log.info("No candidate channels in the queue; creating a new channel.")
channel = await self.create_dormant()
if not channel:
log.info("Couldn't create a candidate channel; waiting to get one from the queue.")
- notify_channel = self.bot.get_channel(constants.HelpChannels.notify_channel)
- last_notification = await _message.notify_none_remaining(notify_channel, self.last_notification)
- if last_notification:
- self.last_notification = last_notification
+
+ if (arrow.utcnow() - self.last_none_remaining_notification).seconds >= self.notify_interval_seconds:
+ await _message.notify_none_remaining(self.bot.get_channel(constants.HelpChannels.notify_channel))
+ self.last_none_remaining_notification = arrow.utcnow()
self.bot.stats.incr("help.out_of_channel_alerts")
channel = await self.wait_for_dormant_channel()
diff --git a/bot/exts/help_channels/_message.py b/bot/exts/help_channels/_message.py
index b6b172e77..d53a03b77 100644
--- a/bot/exts/help_channels/_message.py
+++ b/bot/exts/help_channels/_message.py
@@ -124,13 +124,10 @@ async def dm_on_open(message: discord.Message) -> None:
)
-async def notify_none_remaining(channel: discord.TextChannel, last_notification: t.Optional[Arrow]) -> t.Optional[Arrow]:
+async def notify_none_remaining(channel: discord.TextChannel) -> None:
"""
Send a pinging message in `channel` notifying about there being no dormant channels remaining.
- If a notification was sent, return the time at which the message was sent.
- Otherwise, return None.
-
Configuration:
* `HelpChannels.notify_minutes` - minimum interval between notifications
* `HelpChannels.notify_none_remaining` - toggle none_remaining notifications
@@ -141,49 +138,42 @@ async def notify_none_remaining(channel: discord.TextChannel, last_notification:
log.trace("Notifying about lack of channels.")
- if last_notification:
- elapsed = (arrow.utcnow() - last_notification).seconds
- minimum_interval = constants.HelpChannels.notify_minutes * 60
- should_send = elapsed >= minimum_interval
- else:
- should_send = True
-
- if not should_send:
- log.trace("Notification not sent because it's too recent since the previous one.")
- return
-
try:
log.trace("Sending notification message.")
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]
- message = await channel.send(
+ await channel.send(
f"{mentions} A new available help channel is needed but there "
- f"are no more dormant ones. Consider freeing up some in-use channels manually by "
+ "are no more dormant ones. Consider freeing up some in-use channels manually by "
f"using the `{constants.Bot.prefix}dormant` command within the channels.",
allowed_mentions=discord.AllowedMentions(everyone=False, roles=allowed_roles)
)
-
- return Arrow.fromdatetime(message.created_at)
except Exception:
# Handle it here cause this feature isn't critical for the functionality of the system.
log.exception("Failed to send notification about lack of dormant channels!")
-async def notify_running_low():
+async def notify_running_low(channel: discord.TextChannel, number_of_channels_left: int) -> None:
"""
Send a non-pinging message in `channel` notifying about there being a low amount of dormant channels.
-
- If a notification was sent, return the time at which the message was sent.
- Otherwise, return None.
+ Including the amount of channels left in dormant.
Configuration:
* `HelpChannels.notify_minutes` - minimum interval between notifications
* `HelpChannels.notify_running_low` - toggle running_low notifications
* `HelpChannels.notify_running_low_threshold` - minimum amount of channels to trigger running_low notifications
"""
- ...
+ if not constants.HelpChannels.notify_running_low:
+ return
+
+ log.trace("Notifying about getting close to no dormant channels.")
+
+ await channel.send(
+ f"There are only {number_of_channels_left} dormant channels left. "
+ "Consider participating in some help channels so that we don't run out."
+ )
async def pin(message: discord.Message) -> None:
diff --git a/config-default.yml b/config-default.yml
index fcb1583a8..6ad471cbd 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -514,7 +514,7 @@ help_channels:
name_prefix: 'help-'
notify_channel: *HELPERS # Channel in which to send notifications messages
- notify_minutes: 15 # Minimum interval between helper notifications, used by both none_remaining and running_low
+ notify_minutes: 15 # Minimum interval between none_remaining or running_low notifications
notify_none_remaining: true # Pinging notification for the Helper role when no dormant channels remain
notify_none_remaining_roles: # Mention these roles in the non_remaining notification