From b2384eb7df0dacc90eec5d3b7ca1ed89772fffe9 Mon Sep 17 00:00:00 2001 From: aikaterna Date: Mon, 6 Aug 2018 20:35:40 -0700 Subject: [PATCH] [V2] Add modclean Thanks sitryk. --- modclean/info.json | 8 ++++++++ modclean/modclean.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 modclean/info.json create mode 100644 modclean/modclean.py diff --git a/modclean/info.json b/modclean/info.json new file mode 100644 index 0000000..5d9847a --- /dev/null +++ b/modclean/info.json @@ -0,0 +1,8 @@ +{ + "AUTHOR" : "aikaterna and sitryk", + "INSTALL_MSG" : "Use `[p]modclean #mod-log` to clean your mod log channel. Edits out Discord invite links from banned or kicked users.", + "NAME" : "modclean", + "SHORT" : "Clean your mod log channel of Discord invite names.", + "DESCRIPTION" : "Clean your mod log channel of Discord invite names.", + "TAGS": ["modlog"] +} diff --git a/modclean/modclean.py b/modclean/modclean.py new file mode 100644 index 0000000..853279b --- /dev/null +++ b/modclean/modclean.py @@ -0,0 +1,40 @@ +import discord +import re +from cogs.utils import checks +from discord.ext import commands + + +class ModClean: + def __init__(self, bot): + self.bot = bot + + @commands.command(no_pm=True, pass_context=True) + @checks.is_owner() + async def modclean(self, ctx, modchannel: discord.Channel = None): + """Clean a v2 mod-log channel of invite names.""" + if not modchannel: + return await self.bot.say( + "Please use the mod channel in the command. ({}modclean #channelname)".format( + ctx.prefix + ) + ) + + IL_raw = r"(discordapp.com/invite|discord.me|discord.gg)(?:/#)?(?:/invite)?/([a-z0-9\-]+)" + InvLink = re.compile(IL_raw, re.I) + + try: + async for m in self.bot.logs_from(modchannel, 100): + if not (m.author == ctx.message.server.me): + continue + elif InvLink.search(m.content) is None: + continue + else: + new_cont = InvLink.sub("[REMOVED LINK]", m.content) + await self.bot.edit_message(m, new_cont) + except discord.errors.Forbidden: + return await self.bot.say("No permissions to read that channel.") + await self.bot.say("Done.") + + +def setup(bot): + bot.add_cog(ModClean(bot))