From 47a4aeb4f6f29d43135e2139dc396afb94ce359b Mon Sep 17 00:00:00 2001 From: Ave Ozkal Date: Tue, 29 Jan 2019 13:51:43 +0300 Subject: [PATCH] BREAKING: Add channel cleaning and deleted/edited message logging Please update your config.py before merging this! --- cogs/logs.py | 23 +++++++++++++++++++++++ cogs/robocronp.py | 26 ++++++++++++++++++++++++++ config_template.py | 7 +++++++ 3 files changed, 56 insertions(+) diff --git a/cogs/logs.py b/cogs/logs.py index fd80204..0bb149b 100644 --- a/cogs/logs.py +++ b/cogs/logs.py @@ -68,6 +68,29 @@ class Logs: except KeyError: # if the user is not in the file await log_channel.send(msg) + async def on_message_edit(self, before, after): + await self.bot.wait_until_ready() + if after.channel.id not in config.spy_channels: + return + + log_channel = self.bot.get_channel(config.log_channel) + msg = "📝 **Message edit**: \n"\ + f"from {self.bot.escape_message(after.author.name)} "\ + f"({after.author.id})\n"\ + f"`{before.clean_content}` → `{after.clean_content}`" + await log_channel.send(msg) + + async def on_message_delete(self, message): + await self.bot.wait_until_ready() + if message.channel.id not in config.spy_channels: + return + + log_channel = self.bot.get_channel(config.log_channel) + msg = "🗑️ **Message delete**: \n"\ + f"from {self.bot.escape_message(message.author.name)} "\ + f"({message.author.id})\n `{message.clean_content}`" + await log_channel.send(msg) + async def on_member_remove(self, member): await self.bot.wait_until_ready() log_channel = self.bot.get_channel(config.log_channel) diff --git a/cogs/robocronp.py b/cogs/robocronp.py index 99cd965..567d939 100644 --- a/cogs/robocronp.py +++ b/cogs/robocronp.py @@ -88,6 +88,24 @@ class Robocronp: await log_channel.send("Crondo has errored, job deleted: ```" f"{traceback.format_exc()}```") + async def clean_channel(self, channel_id): + log_channel = self.bot.get_channel(config.botlog_channel) + channel = self.bot.get_channel(channel_id) + try: + done_cleaning = False + count = 0 + while not done_cleaning: + purge_res = await channel.purge(limit=100) + count += len(purge_res) + if len(purge_res) != 100: + done_cleaning = True + await log_channel.send(f"Wiped {count} messages from " + f"<#{channel.id}> automatically.") + except: + # Don't kill cronjobs if something goes wrong. + await log_channel.send("Cronclean has errored: ```" + f"{traceback.format_exc()}```") + async def minutely(self): await self.bot.wait_until_ready() log_channel = self.bot.get_channel(config.botlog_channel) @@ -99,6 +117,10 @@ class Robocronp: for jobtimestamp in ctab[jobtype]: if timestamp > int(jobtimestamp): await self.do_jobs(ctab, jobtype, jobtimestamp) + + # Handle clean channels + for clean_channel in config.minutely_clean_channels: + await self.clean_channel(clean_channel) except: # Don't kill cronjobs if something goes wrong. await log_channel.send("Cron-minutely has errored: ```" @@ -114,6 +136,10 @@ class Robocronp: await asyncio.sleep(3600) try: await self.send_data() + + # Handle clean channels + for clean_channel in config.hourly_clean_channels: + await self.clean_channel(clean_channel) except: # Don't kill cronjobs if something goes wrong. await log_channel.send("Cron-hourly has errored: ```" diff --git a/config_template.py b/config_template.py index 8ac28fd..5f01639 100644 --- a/config_template.py +++ b/config_template.py @@ -44,3 +44,10 @@ community_channels = [526378423468425236] # Channels requiring community role general_channels = [526372255052201995] # Channels everyone can access mute_role = 526500080879140874 # Mute role in NotSwitched + +# Channels that will be cleaned every minute/hour +minutely_clean_channels = [] +hourly_clean_channels = [539212260350885908] # ReSwitched bot-cmds + +# Edited and deletes messages in these channels will be logged +spy_channels = general_channels