Clean improvments#2189
Conversation
The command cleans all public messages from a user. This is a private case that is common enough that it probably deserves a shortcut. Since the `purge` alias is never used for the clean group I repurposed it for this new command.
| def predicate_range(message: Message) -> bool: | ||
| """Check if the message age is between the two limits.""" | ||
| return first_limit <= message.created_at <= second_limit | ||
| return first_limit < message.created_at < second_limit |
There was a problem hiding this comment.
I'm confused how this makes a difference. The messages are fetched using Messageable.history() with the same limits. For history(), those limits are already exclusive. I don't understand why predicate_range and predicate_after are even needed.
There was a problem hiding this comment.
Because the search might go through the cache. If history is indeed exclusive then I guess this predicate could be dropped in those cases, but I don't mind another guarantee if it already exists.
There was a problem hiding this comment.
predicate_after should also be exclusive then.
There was a problem hiding this comment.
Hmm good point. It doesn't cause a bug because the iteration excludes the stopping point.
MarkKoz
left a comment
There was a problem hiding this comment.
This argument can be None, so it should be annotated as such https://github.com/python-discord/bot/blob/0bbcde6af81405380bbae1eca3556338331b03fa/bot/exts/moderation/clean.py#L244=
There is an issue with the annotation, but it's actually different. |
Technically both are optional since they're just passed to |
yeah but this is about how the function is expected to be used, rather than what it can technically accept |
I don't feel strongly about this but if it were me I wouldn't impose artificial constraints on it. |
|
If I write a function which takes a number and adds 1 to it, I could assign a default value of 0 to the number, but I have no reason to. That's not how I want the function to behave. If I don't supply it a number I want it to yell at me, not because of what the function can do in practice if I allow it, but by my choice. |
Co-authored-by: Mark <1515135+MarkKoz@users.noreply.github.com>
clean betweendeleted the last message. Clarified in the appropriate command descriptions that the clean limits are exclusive.purgealias was never used for the clean group I repurposed it for this new command.