aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Eivind Teig <[email protected]>2020-03-09 09:13:09 +0100
committerGravatar GitHub <[email protected]>2020-03-09 09:13:09 +0100
commitbaa72096968e367a2e1f3547679f5bdd567df39b (patch)
tree549091de781de1d7603e19a97c254dbcdd98926c
parentMerge pull request #826 from python-discord/vote (diff)
parentMerge branch 'master' into token-detection-fix (diff)
Merge pull request #825 from python-discord/token-detection-fix
Refactor token detection to check all potential substrings in message
-rw-r--r--bot/cogs/token_remover.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/bot/cogs/token_remover.py b/bot/cogs/token_remover.py
index 82c01ae96..547ba8da0 100644
--- a/bot/cogs/token_remover.py
+++ b/bot/cogs/token_remover.py
@@ -96,12 +96,19 @@ class TokenRemover(Cog):
if msg.author.bot:
return False
- maybe_match = TOKEN_RE.search(msg.content)
- if maybe_match is None:
+ # Use findall 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)
+ if not maybe_matches:
return False
+ return any(cls.is_maybe_token(substr) for substr in maybe_matches)
+
+ @classmethod
+ def is_maybe_token(cls, test_str: str) -> bool:
+ """Check the provided string to see if it is a seemingly valid token."""
try:
- user_id, creation_timestamp, hmac = maybe_match.group(0).split('.')
+ user_id, creation_timestamp, hmac = test_str.split('.')
except ValueError:
return False