Fix off-by-one errors and silent reminder deletion in reminders.py#3509
Open
oliveman-au wants to merge 1 commit intopython-discord:mainfrom
Open
Fix off-by-one errors and silent reminder deletion in reminders.py#3509oliveman-au wants to merge 1 commit intopython-discord:mainfrom
oliveman-au wants to merge 1 commit intopython-discord:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found a few bugs in
bot/exts/utils/reminders.pywhile going through the reminders codebase. Two off-by-one errors and a silent deletion issue when the bot loses channel cache.1. Off-by-one — users could create 6 reminders despite a limit of 5
The check was using
>instead of>=, so the 6th reminder always slipped through before the denial fired.2. Off-by-one — users could delete 6 reminders at once despite a limit of 5
Same mistake in
delete_reminder, which also directly contradicted the docstring saying "up to and including 5".3. Reminders silently deleted with no user notification when channel cache is lost
get_channel()only checks the local cache, so after a bot restart the channel returnsNoneand the reminder gets permanently deleted with no DM, no message, nothing to the user. Switched toget_or_fetch_channel()as suggested by wookie184, and added a DM to the user if the channel truly can't be found so they at least get their reminder content back. Also updated both call sites toawaitthe method since it's now async.