Conversation
cmd/gatekeeper/reminders.go
Outdated
| type UserId = string | ||
|
|
||
| var mutex = &sync.Mutex{} | ||
| var reminders = map[UserId]context.CancelFunc{} |
There was a problem hiding this comment.
One problem I see with this approach is that reminders do not survive the bot restart. We should store the reminders in the database. We should also just have a single goroutine that queries the database periodically for fired off reminders.
Maybe the resolution of the duration should be one minute? Querying the database every minute instead of every second is much better plus reminders that fire off within seconds are useless anyway.
What do you think?
UPD. Ah, I see, you mentioned the persistence in the description, sorry. I read it after the code 4Head. I feel persistence is important in this case. Cause people may start adding very long reminders which have very high probability of being lost.
There was a problem hiding this comment.
Thank you for the observations!
I have finalized the integration with the database. Reminders are now stored persistently.
We poll for overdue reminders every minute, send them, and then clean up their entries in the database.
Commands added
We have the main remind command that adds a new reminder based on the delay specified:
- !remind 20m Hello reminder world!
To complement it, i've added these 2 helper functions for managing reminders:
- !reminders: Displays all available reminders, their index in the user's reminder list, and the time remaining until they trigger. Reminders are sorted by the soonest to fire.
- !delreminder: Deletes unwanted reminders based on the index provided by the
!reminderscommand.
Notes
Some decision I took that you might want to reconsider:
- All users can have at max
5reminders - Reminder body size is limited to
256 runes - Reminder pooling interval is
1 minute - The bot sends all reminder messages in
#bot-shrinediscord channel
Thank you for your time reviewing this addition!
749406d to
09b6cf7
Compare
09b6cf7 to
e2e4e34
Compare
Hi
This PR adds a minimal implementation for reminder command.
Usage
Example
Effect
After 30 minutes and 30 seconds the bot will ping the Author with the message.
Known problems
Reminders are lost at server restart, they need to be persisted in the DB.
To keep the scope of this PR small I haven't included this addition yet.