From d246e2f6ec1c0e592dbd04aa18eb6e62122dafb3 Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Tue, 26 Feb 2019 16:03:21 +0300 Subject: [PATCH] Implement #22 --- cogs/logs.py | 26 ++++++++++++++++++++++++++ helpers/errcodes.py | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/cogs/logs.py b/cogs/logs.py index 3e18a24..1f9c39a 100644 --- a/cogs/logs.py +++ b/cogs/logs.py @@ -1,5 +1,6 @@ import discord import json +import re import config from helpers.restrictions import get_user_restrictions @@ -11,6 +12,8 @@ class Logs: def __init__(self, bot): self.bot = bot + self.invite_re = re.compile(r"((discord\.gg|discordapp\.com/" + r"+invite)/+[a-zA-Z0-9-]+)") async def on_member_join(self, member): await self.bot.wait_until_ready() @@ -68,6 +71,27 @@ class Logs: except KeyError: # if the user is not in the file await log_channel.send(msg) + async def do_spy(self, message): + alert = False + msg = f"Suspicious message by {message.author.mention} "\ + f"({message.author.id}):" + + invites = self.invite_re.search(message.lower()) + for invite in invites: + msg += f"\n- Has invite: https://{invite[0]}" + alert = True + + if alert: + spy_channel = self.bot.get_channel(548304839294189579) + await spy_channel.send(msg) + + async def on_message(self, message): + await self.bot.wait_until_ready() + if message.channel.id not in config.spy_channels: + return + + await self.do_spy(message) + async def on_message_edit(self, before, after): await self.bot.wait_until_ready() if after.channel.id not in config.spy_channels or after.author.bot: @@ -78,6 +102,8 @@ class Logs: if before.clean_content == after.clean_content: return + await self.do_spy(after) + log_channel = self.bot.get_channel(config.log_channel) msg = "📝 **Message edit**: \n"\ f"from {self.bot.escape_message(after.author.name)} "\ diff --git a/helpers/errcodes.py b/helpers/errcodes.py index 4ac150c..7a4b9ca 100644 --- a/helpers/errcodes.py +++ b/helpers/errcodes.py @@ -707,7 +707,7 @@ switch_known_errcodes = { # By Ave - 0x0: "Thrown when you downgrade between major/key versions (7.0.x -> 6.2.0, 6.2.0 -> 6.1.0 etc) without initialization ( deleting system save files).\n\nTo recover from this issue: Delete system all save files except 80...120. Keep in mind that this will effectively be a factory reset.", + 0x0: "Thrown when you downgrade between major/key versions (7.0.x -> 6.2.0, 6.2.0 -> 6.1.0 etc) without initialization (deleting system save files).\n\nTo recover from this issue: Delete system all save files except 80...120. Keep in mind that this will effectively be a factory reset.", } switch_known_errcode_ranges = {