diff options
| author | 2020-03-28 17:38:11 +0200 | |
|---|---|---|
| committer | 2020-03-28 17:38:11 +0200 | |
| commit | e5c41faf826e4a29fd21986fc828034372b18863 (patch) | |
| tree | 09565e7f9129112ec496d205688baaae8f5e6e9a | |
| parent | (Webhook Detection): Added webhook match regex. (diff) | |
(Webhook Detection): Added cog loading to __main__.py, created `scan_message` helper function to detect Webhook URL.
| -rw-r--r-- | bot/__main__.py | 1 | ||||
| -rw-r--r-- | bot/cogs/webhook_remover.py | 9 |
2 files changed, 10 insertions, 0 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index 3df477a6d..9e8b1bdce 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -64,6 +64,7 @@ bot.load_extension("bot.cogs.token_remover") bot.load_extension("bot.cogs.utils") bot.load_extension("bot.cogs.watchchannels") bot.load_extension("bot.cogs.wolfram") +bot.load_extension("bot.cogs.webhook_remover") # Apply `message_edited_at` patch if discord.py did not yet release a bug fix. if not hasattr(discord.message.Message, '_handle_edited_timestamp'): diff --git a/bot/cogs/webhook_remover.py b/bot/cogs/webhook_remover.py index 49cf94de7..a3025f19f 100644 --- a/bot/cogs/webhook_remover.py +++ b/bot/cogs/webhook_remover.py @@ -1,5 +1,6 @@ import re +from discord import Message from discord.ext.commands import Cog from bot.bot import Bot @@ -13,6 +14,14 @@ class WebhookRemover(Cog): def __init__(self, bot: Bot): self.bot = bot + async def scan_message(self, msg: Message) -> bool: + """Scan message content to detect Webhook URLs. Return `bool` about does this have webhook URL.""" + matches = WEBHOOK_URL_RE.search(msg.content) + if matches: + return True + else: + return False + def setup(bot: Bot) -> None: """Load `WebhookRemover` cog.""" |