BREAKING: Add channel cleaning and deleted/edited message logging

Please update your config.py before merging this!
This commit is contained in:
Ave Ozkal 2019-01-29 13:51:43 +03:00
parent 2d4c75463e
commit 47a4aeb4f6
No known key found for this signature in database
GPG key ID: 09356ABAA42C842B
3 changed files with 56 additions and 0 deletions

View file

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

View file

@ -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: ```"

View file

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