diff options
| author | 2020-05-25 19:46:51 -0700 | |
|---|---|---|
| committer | 2020-05-25 19:46:51 -0700 | |
| commit | bfe79efdfe699bf7289cba9db95d5637a7fb965a (patch) | |
| tree | 0847ce04124976970c34724141ca16c4b278bdec | |
| parent | Token remover: use regex groups and pass the token as a NamedTuple (diff) | |
Token remover: use finditer instead of findall
It makes more sense to use the lazy function when the loop is already
short-circuiting on the first valid token it finds.
| -rw-r--r-- | bot/cogs/token_remover.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/bot/cogs/token_remover.py b/bot/cogs/token_remover.py index e5d0ae838..8913ca64d 100644 --- a/bot/cogs/token_remover.py +++ b/bot/cogs/token_remover.py @@ -120,11 +120,10 @@ class TokenRemover(Cog): if msg.author.bot: return - # Use findall rather than search to guard against method calls prematurely returning the + # Use finditer rather than search to guard against method calls prematurely returning the # token check (e.g. `message.channel.send` also matches our token pattern) - maybe_matches = TOKEN_RE.findall(msg.content) - for match_groups in maybe_matches: - token = Token(*match_groups) + for match in TOKEN_RE.finditer(msg.content): + token = Token(*match.groups()) if cls.is_valid_user_id(token.user_id) and cls.is_valid_timestamp(token.timestamp): # Short-circuit on first match return token |