-
-
Notifications
You must be signed in to change notification settings - Fork 104
Adding /remind command #373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
03d55de to
c4d1417
Compare
|
Silently ignoring the reminder shouldn't happen in my honest opinion. If the channel/guild can't be found we should (try to) DM the user instead. |
Good idea. Will do that. |
Zabuzard
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Send user DM if reminder cant be sent due to unknown guild/channel.
Implemented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this review, check the one below. Keeping for sake of history
I'm not happy with how you ended up handling it.
This ReminderRoute class had me confused for too long, these onErrorMap's into null are unreadable and it resulted in a mess of ternary and logic which should be separated.
Instead, don't map into null resulting in unreadable ternary mess, handle the error separately.
Right now you just throw a IllegalStateException, after adding a lot of logic which makes it severely more complicated, when this can also just be done by handling the error when queueing
and also, if you remove the null mappers and remove the illegal state exception the behaviour stays the same.
The failure consumer runs, but now it's readable with less logic.
I'm sorry, but this isn't gonna cut it for me.
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
Tais993
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After convo and some clearing up in the Discord, new suggestions have come. The old ones have been resolved/deleted by me.
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
2e686d8 to
e0a8edb
Compare
apparently `retrieveUserById` fails instead of giving null when user not found. fortunately, there is `onErrorMap(error -> null)`.
by Tais
CR by Tais
fd2cdae to
f35a82f
Compare
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindCommand.java
Outdated
Show resolved
Hide resolved
CR by tais
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
textblocks with \
marko-radosavljevic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RemindRoutine is much more readable than the last time i glanced over it. Routing logic is still somewhat convoluted tho, possibly extracting it to a new class is something that can be done, since it's not really routine's responsibility to figure out correct channels/users.
Will approve since it's not really worth 10h of combined development effort to go back and forth on naming and such, when this is not an integral feature to our core software.
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindCommand.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindCommand.java
Outdated
Show resolved
Hide resolved
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindCommand.java
Outdated
Show resolved
Hide resolved
|
Oh yeah, how feasible would it be to add a few test cases for this? |
Not for now. We need clock mocking for this - for the database checks to pickup Fortunately, Java is well equipped for clock mocking. Its just that it requires a change on all time usages in the whole code base. Like, instead of The Edit: To not forget I added #396 |
by marko
ee04176 to
dc670b2
Compare
Tais993
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last one I promise :p
application/src/main/java/org/togetherjava/tjbot/commands/reminder/RemindRoutine.java
Outdated
Show resolved
Hide resolved
|
Kudos, SonarCloud Quality Gate passed! |
marko-radosavljevic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.









Overview
Originally from #354 , taken over. Implements and closes #325 .
This adds the
/remindcommand which can be used to automatically send reminders to oneself at a future date.Reminders are sent in the channel the command has been used in (or via DM if something goes wrong).
Details
Technically, reminders are simple saved in a database table, where an automatic routine will pick them up at time, send them and delete them from the table.
Database table
The table is quite straightforward. It has some metadata, data to be able to locate the channel to post to and the actual content and time to fire the reminder.
RemindCommandUXThe user can enter a time period as
amountandunit, which determine when the reminder will be send.amount- an integer between1and1_000unit- dropdown of"minutes", "hours", "days", "weeks", "months", "years"After using the command, it verifies that the time is within reasonable limits (max 3 years) and if the user has not reached the limit of pending reminders per user (100). If not, an error message is send.
Those restrictions are mostly to prevent the database and hence our disk space from overflowing when users are spamming around.
RemindRoutineThe routine is quite trivial. It implements
Routine, with a schedule of 30 seconds. In each run, it gets hands on all pending reminders that are due, sends them and deletes them from the table afterwards.To send them, it locates the corresponding guild and channel, retrieves the original author and builds a slim embed.
Error cases
If the guild and channel could be found, but the author couldnt be retrieved anymore, it sends the message with
Unknown User.If the guild or channel cant be found, the bot attempts to send it via DM to the author instead.
If sending the DM failed as well (user deleted, user disabled DMs, ...), the bot sends a
WARNlog message:Future plans
The command would greatly benefit from JDA/Discord adding a date/time selector. It could then be split into
/remind inand/remind at. A// TODOkeeps track of this.Unfortunately, it is not really possible to add
/remind at(eventhough the use case is very reasonable) as of today without having hands on the users timezone.Checklist