aboutsummaryrefslogtreecommitdiffstats
path: root/tests/helpers.py (unfollow)
Commit message (Collapse)AuthorLines
2020-05-31Revert message ignore approach.Gravatar Leon Sandøy-10/+9
We're removing the context manager due to async concerns, so we'll go back to the old approach again of ignoring specific messages and iterating history.
2020-05-31Revert "Add a mod_log.ignore_all context manager."Gravatar Leon Sandøy-35/+0
This reverts commit 0737b1a6 This isn't gonna work, because async is a thing.
2020-05-31Fix a bug with invocation deletion.Gravatar Leon Sandøy-21/+14
This command was written to support only a single channel, and with the move to multi-channel purges, we need to rethink the way the invocation deletion happens. We may be invoking this command from a completely different channel, so we can't necessarily look inside the channels we're targeting for the invocation. So, we're solving this by just deleting the invocation by using ctx.message. We do this before we start iterating message history, and then we only need to iterate the number of messages that was passed into the command. A much cleaner approach, which solves the bug reported and identified by @MarkKoz.
2020-05-31Add a mod_log.ignore_all context manager.Gravatar Leon Sandøy-0/+35
This new context manager makes it easier to make the mod_log ignore actions like message deletions. The only existing method is the `ignore()` method, which requires that you pass all the messages you want to ignore into it. This one just ignores everything inside its scope. This isn't the DRYest approach, but it's low-cost and improves the readability of clean.py quite a bit. Ideally we should go through and give modlog a proper cleanup, because it's kinda ugly right now.
2020-05-31Remove unnecessary conditional.Gravatar Leon Sandøy-4/+2
Thanks @MarkKoz!
2020-05-31Better channel mentionsGravatar Leon Sandøy-1/+1
Co-authored-by: Mark <[email protected]>
2020-05-30Oops, add the return back.Gravatar Leon Sandøy-0/+1
We do not wanna process bot messages.
2020-05-30Remove a completely unacceptable newline.Gravatar Leon Sandøy-1/+0
2020-05-30Add multichannel !purge via commands.GreedyGravatar Leon Sandøy-31/+39
We can now pass in as many channel mentions as we want after any !purge command - for example `!purge all 5 #python-general #python-language`
2020-05-30Free tag: link #how-to-get-helpGravatar kwzrd-2/+2
This creates a clickable link in the response embed. Referencing the category is no longer necessary.
2020-05-30Scheduler: Move space from f-string of `ctx.send` to `infr_message`Gravatar ks129-2/+2
2020-05-30Scheduler: Remove line splitting from `ctx.send` after 7f827abGravatar ks129-4/+1
2020-05-30Infr. Tests: Add `apply_infraction` awaiting assertion with argsGravatar ks129-0/+6
2020-05-30Scheduler: Fix spaces for modlog textGravatar ks129-1/+1
Co-authored-by: Mark <[email protected]>
2020-05-30Scheduler: Remove unnecessary `f` before stringGravatar ks129-1/+1
2020-05-30Scheduler: Add try-except to infraction deletionGravatar ks129-1/+6
2020-05-30Scheduler: Remove invalid commentGravatar ks129-1/+0
2020-05-30Scheduler: Move inline f-string if-else statement to normal if statementGravatar ks129-1/+4
2020-05-30Simplify infraction reason truncation testsGravatar ks129-13/+7
2020-05-30Tags: explicitly use UTF-8 to read filesGravatar MarkKoz-1/+1
Not all operating systems use UTF-8 as the default encoding. For systems that don't, reading tag files with Unicode would cause an unhandled exception. (cherry picked from commit adc75ff9bbcf8b905bd78c78f253522ae5e42fc3)
2020-05-30Removing the periodic ping from verification.Gravatar Leon Sandøy-43/+1
It's no longer needed, and causes problems with anti-raid and anti-spam.
2020-05-29Reduce the number of help channel name changesGravatar Sebastiaan Zeeff-29/+3
Discord has introduced a new, strict rate limit for individual channel edits that reduces the number of allow channel name/channel topic changes to 2 per 10 minutes per channel. Unfortunately, our help channel system frequently goes over that rate limit as it edits the name and topic of a channel on all three "move" actions we have: to available, to occupied, and to dormant. In addition, our "unanswered" feature adds another channel name change on top of the move-related edits. That's why I've removed the topic/emoji changing features from the help channel system. This means we now have a generic topic that fits all three categories and no status emojis in the channel names.
2020-05-29Fix `check_for_answer` breaking on missing cacheGravatar Sebastiaan Zeeff-2/+5
The `check_for_answer` method of the HelpChannels cog relies on the channel->claimant cache being available. However, as this cache is (currently) lost during bot restarts, this method may fail with a KeyError exception. I've used `dict.get` with an `if not claimant: return` to circumvent this issue.
2020-05-29Ignore response when posting python newsGravatar Matteo Bertucci-0/+1
Sometimes a mailing list user doesn't press respond correctly to the email, and so a response is sent as a separate thread. To keep only new threads in the channel, we need to ignore those.
2020-05-28Move the `self.redis_closed` into session create.Gravatar Leon Sandøy-1/+1
2020-05-28Prevent a state where a coro could wait forever.Gravatar Leon Sandøy-2/+6
This addresses a review comment by @aeros.
2020-05-28Add custom exceptions for each error state.Gravatar Leon Sandøy-8/+21
The bot can get into trouble in three distinct ways: - It has no Bot instance - It has no namespace - It has no parent instance. These happen only if you're using it wrong. To make the test more precise, and to add a little bit more readability (RuntimeError could be anything!), we'll introduce some custom exceptions for these three states. This addresses a review comment by @aeros.
2020-05-28Make prefix consts private and more precise.Gravatar Leon Sandøy-9/+9
2020-05-28Reduce complexity on some of the typestring stuff.Gravatar Leon Sandøy-31/+9
- Refactor error messages in _to_typestring and _from_typestring to just print the prefix tuples instead of that custom error string. - Create a RedisKeyOrValue type to simplify some annotations. - Simplify partialmethod calls. - Make the signatures for _to_typestring and _from_typestring one-liners - Fix a typo in the errors.
2020-05-27Fix ATROCIOUS comment.Gravatar Leon Sandøy-3/+5
I should be shot.
2020-05-27Refactor typestring converters to partialmethods.Gravatar Leon Sandøy-30/+24
We're using functools.partialmethod to make the code a little cleaner and more readable here. Read more about them here: https://docs.python.org/3/library/functools.html#functools.partial https://docs.python.org/3/library/functools.html#functools.partialmethod
2020-05-27Floats are no longer permitted as RedisCache keys.Gravatar Leon Sandøy-43/+86
Also added a test for this. This is the DRYest approach I could find. It's a little ugly, but I think it's probably good enough.
2020-05-27Add some tests for `in_whitelist_check`.Gravatar Leon Sandøy-0/+48
2020-05-27Remove the now deprecated in_channel_check.Gravatar Leon Sandøy-16/+0
This check was no longer being used anywhere, having been replaced by in_whitelist_check.
2020-05-27Refactor .increment and add lock test.Gravatar Leon Sandøy-65/+109
The way we were doing the asyncio.Lock() stuff for increment was slightly problematic. @aeros has adviced us that it's better to just initialize the lock as None in __init__, and then initialize it inside the first coroutine that uses it instead. This ensures that the correct loop gets attached to the lock, so we don't end up getting errors like this one: RuntimeError: got Future <Future pending> attached to a different loop This happens because the lock and the actual calling coroutines aren't on the same loop. When creating a new test, test_increment_lock, we discovered that we needed a small refactor here and also in the test class to make this new test pass. So, now we're creating a DummyCog for every test method, and this will ensure the loop streams never cross. Cause we all know we must never cross the streams.
2020-05-27Clear cache in asyncSetUp instead of tests.Gravatar Leon Sandøy-6/+1
2020-05-27Fix failing tests related to avatar_hashGravatar Leon Sandøy-5/+0
2020-05-27Remove all sending of avatar_hash.Gravatar Leon Sandøy-6/+2
This is a companion commit to this PR: https://github.com/python-discord/site/pull/356 This PR must be merged before this commit.
2020-05-27Allow some commands to fail checks silently.Gravatar Leon Sandøy-2/+9
For example, we don't want the mod commands to produce any kind of error message when run by ordinary users in regular channels - these should have the perception of being invisible and unavailable.
2020-05-27No redirect for mod management.Gravatar Leon Sandøy-0/+1
2020-05-27Find + change all InWhitelistCheckFailure importsGravatar Leon Sandøy-9/+8
2020-05-27Allow infraction management in modmail categoryGravatar Leon Sandøy-12/+13
2020-05-27Refactor the in_whitelist deco to a check.Gravatar Leon Sandøy-53/+86
We're moving the actual predicate into the `utils.checks` folder, just like we're doing with most of the other decorators. This is to allow us the flexibility to use it as a pure check, not only as a decorator. This commit doesn't actually change any functionality, just moves it around.
2020-05-26Add /r/FlutterDev to the guild invite whitelistGravatar Dennis Pham-0/+1
2020-05-26Add a test for RuntimeErrors.Gravatar Leon Sandøy-0/+22
This just tests that the various RuntimeErrors are reachable - that includes the error about not having a bot instance, the one about not being a class attribute, and the one about not having instantiated the class. This test addresses a concern raised by @MarkKoz in a review. I've decided not to test that actual contents of these RuntimeErrors, because I believe that sort of testing is a bit too brittle. It shouldn't break a test just to change the content of an error string.
2020-05-26Swap the order for the validate_cache checks.Gravatar Leon Sandøy-8/+8
2020-05-26Improve some docstrings for RedisCache.Gravatar Leon Sandøy-5/+3
Thanks @MarkKoz!
2020-05-26Make self.increment_lock private.Gravatar Leon Sandøy-2/+2
2020-05-26Add better docstring for RedisCache.updateGravatar Leon Sandøy-2/+12
2020-05-26Fix edge case where pop might not delete.Gravatar Leon Sandøy-6/+6
If you passed a key for a value that was the same as your optional, it would just return it but not delete it. This edge case isn't worth it, so I'm just removing that condition and letting the extra API call fly.