Send a reminder message a day before a scheduled run

This commit is contained in:
Marc Di Luzio 2024-08-12 23:29:40 +01:00
parent 50f94b284b
commit 503e899f19
3 changed files with 15 additions and 9 deletions

View file

@ -56,5 +56,4 @@ Only token and version are required. See [`py/config.py`](py/config.py) for expl
* Write integration tests (maybe with [dpytest](https://dpytest.readthedocs.io/en/latest/tutorials/getting_started.html)?) * Write integration tests (maybe with [dpytest](https://dpytest.readthedocs.io/en/latest/tutorials/getting_started.html)?)
* Implement a .json file upgrade test * Implement a .json file upgrade test
* Track if meets were sucessful * Track if meets were sucessful
* Send reminder messages
* Improve the weirdo * Improve the weirdo

View file

@ -5,7 +5,7 @@ import logging
import discord import discord
from discord import app_commands from discord import app_commands
from discord.ext import commands, tasks from discord.ext import commands, tasks
import datetime from datetime import datetime, timedelta, time
import matching import matching
import state import state
import config import config
@ -289,14 +289,20 @@ async def match_groups_in_channel(channel: discord.channel, min: int):
logger.info("Done! Matched into %s groups.", len(groups)) logger.info("Done! Matched into %s groups.", len(groups))
@tasks.loop(time=[datetime.time(hour=h) for h in range(24)]) @tasks.loop(time=[time(hour=h) for h in range(24)])
async def run_hourly_tasks(): async def run_hourly_tasks():
"""Run any hourly tasks we have""" """Run any hourly tasks we have"""
for (channel, min) in State.get_active_channel_match_tasks(): for (channel, min) in State.get_active_match_tasks():
logger.info("Scheduled match task triggered in %s", channel) logger.info("Scheduled match task triggered in %s", channel)
msg_channel = bot.get_channel(int(channel)) msg_channel = bot.get_channel(int(channel))
await match_groups_in_channel(msg_channel, min) await match_groups_in_channel(msg_channel, min)
for (channel, _) in State.get_active_match_tasks(datetime.now() + timedelta(days=1)):
logger.info("Reminding about scheduled task in %s", channel)
msg_channel = bot.get_channel(int(channel))
await msg_channel.send("Arf arf! just a reminder I'll be doin a matcherino in here in T-24hrs!"
+ "\nUse /join if you haven't already, or /pause if you want to skip a week :)")
def get_matchees_in_channel(channel: discord.channel): def get_matchees_in_channel(channel: discord.channel):
"""Fetches the matchees in a channel""" """Fetches the matchees in a channel"""

View file

@ -285,14 +285,15 @@ class State():
if reactivate and datetime.now() > ts_to_datetime(reactivate): if reactivate and datetime.now() > ts_to_datetime(reactivate):
channel[_Key.ACTIVE] = True channel[_Key.ACTIVE] = True
def get_active_channel_match_tasks(self) -> Generator[str, int]: def get_active_match_tasks(self, time: datetime | None = None) -> Generator[str, int]:
""" """
Get any currently active match tasks Get any active match tasks at the given time
returns list of channel,members_min pairs returns list of channel,members_min pairs
""" """
now = datetime.now() if not time:
weekday = now.weekday() time = datetime.now()
hour = now.hour weekday = time.weekday()
hour = time.hour
for channel, tasks in self._tasks.items(): for channel, tasks in self._tasks.items():
for match in tasks.get(_Key.MATCH_TASKS, []): for match in tasks.get(_Key.MATCH_TASKS, []):