Send a reminder message a day before a scheduled run
This commit is contained in:
parent
50f94b284b
commit
503e899f19
3 changed files with 15 additions and 9 deletions
|
@ -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
|
||||
|
|
12
py/matchy.py
12
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"""
|
||||
|
|
11
py/state.py
11
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, []):
|
||||
|
|
Loading…
Add table
Reference in a new issue