From 503e899f19b0a9ea066cc4a394e04667bc3fc15a Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Mon, 12 Aug 2024 23:29:40 +0100 Subject: [PATCH] Send a reminder message a day before a scheduled run --- README.md | 1 - py/matchy.py | 12 +++++++++--- py/state.py | 11 ++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6b5993c..a157e04 100644 --- a/README.md +++ b/README.md @@ -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)?) * Implement a .json file upgrade test * Track if meets were sucessful -* Send reminder messages * Improve the weirdo diff --git a/py/matchy.py b/py/matchy.py index 14693e3..8061c08 100755 --- a/py/matchy.py +++ b/py/matchy.py @@ -5,7 +5,7 @@ import logging import discord from discord import app_commands from discord.ext import commands, tasks -import datetime +from datetime import datetime, timedelta, time import matching import state 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)) -@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(): """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) msg_channel = bot.get_channel(int(channel)) 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): """Fetches the matchees in a channel""" diff --git a/py/state.py b/py/state.py index 50d556d..0b9f0a0 100644 --- a/py/state.py +++ b/py/state.py @@ -285,14 +285,15 @@ class State(): if reactivate and datetime.now() > ts_to_datetime(reactivate): 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 """ - now = datetime.now() - weekday = now.weekday() - hour = now.hour + if not time: + time = datetime.now() + weekday = time.weekday() + hour = time.hour for channel, tasks in self._tasks.items(): for match in tasks.get(_Key.MATCH_TASKS, []):