Don't snipe steam codes, fixes #78

(bot commands can be sniped)
This commit is contained in:
Stijn De Clercq 2021-06-30 21:55:17 +02:00
parent ecb7de062b
commit 09cad58f43
6 changed files with 68 additions and 5 deletions

10
data/regexes.py Normal file
View file

@ -0,0 +1,10 @@
import re
STEAM_CODE = {"pattern": "[A-Z0-9]{5}-[A-Z0-9]{5}-[A-Z0-9]{5}", "flags": re.IGNORECASE}
def contains(text: str, pattern: dict) -> bool:
if "flags" in pattern:
return re.search(pattern["pattern"], text, pattern["flags"]) is not None
else:
return re.search(pattern["pattern"], text) is not None

View file

@ -1,6 +1,7 @@
from enum import Enum
from attr import dataclass
from data import regexes
import discord
from enum import Enum
class Action(Enum):
@ -22,3 +23,17 @@ class Snipe:
action: Action
old: str
new: str = None
def should_snipe(message: discord.Message) -> bool:
"""
Check if a message should be sniped or not
This could be a oneliner but that makes it unreadable
"""
if message.guild is None:
return False
if message.author.bot:
return False
return not regexes.contains(message.content, regexes.STEAM_CODE)