[V2] Add modclean

Thanks sitryk.
This commit is contained in:
aikaterna
2018-08-06 20:35:40 -07:00
parent 4d66912fa2
commit b2384eb7df
2 changed files with 48 additions and 0 deletions

8
modclean/info.json Normal file
View File

@@ -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"]
}

40
modclean/modclean.py Normal file
View File

@@ -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))