From aeda15e33b00b088662853b938835855d0d9918b Mon Sep 17 00:00:00 2001 From: kyb3r Date: Sun, 6 Jan 2019 16:45:05 +1100 Subject: [PATCH] Deleting thread channels is now a valid way to close a thread --- CHANGELOG.md | 8 +++++++- bot.py | 47 +++++++++++++++++++++++++++++++++++++++++++++-- cogs/utility.py | 6 ++++++ 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da62459337..085b9d6780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -#v2.0.4 +# v2.0.5 + +### Changed +- Alias command now checks if you are adding a valid alias - command combo. +- Deleting a channel manually will now correctly close the thread and post logs. + +# v2.0.4 ### Fixed - Fixed a one off bug where the channel topic dissapears, but modmail operations should still continue diff --git a/bot.py b/bot.py index 90951c9514..ec3ea6e20b 100644 --- a/bot.py +++ b/bot.py @@ -22,7 +22,7 @@ SOFTWARE. """ -__version__ = '2.0.4' +__version__ = '2.0.5' import asyncio import textwrap @@ -244,6 +244,48 @@ async def on_message(self, message): message.content = f'{prefix}reply {self.snippets[cmd]}' await self.process_commands(message) + + async def on_guild_channel_delete(self, channel): + if channel.guild != self.modmail_guild: + return + thread = await self.threads.find(channel=channel) + if thread: + del self.threads.cache[thread.id] + + mod = None + + audit_logs = self.modmail_guild.audit_logs() + entry = await audit_logs.find(lambda e: e.target.id == channel.id) + mod = entry.user + + log_data = await self.modmail_api.post_log(channel.id, { + 'open': False, + 'closed_at': str(datetime.datetime.utcnow()), + 'closer': { + 'id': str(mod.id), + 'name': mod.name, + 'discriminator': mod.discriminator, + 'avatar_url': mod.avatar_url, + 'mod': True + }}) + + em = discord.Embed(title='Thread Closed') + em.description = f'{mod.mention} has closed this modmail thread.' + em.color = discord.Color.red() + + try: + await thread.recipient.send(embed=em) + except: + pass + + log_url = f"https://logs.modmail.tk/{log_data['user_id']}/{log_data['key']}" + + user = thread.recipient.mention if thread.recipient else f'`{thread.id}`' + + desc = f"[`{log_data['key']}`]({log_url}) {mod.mention} closed a thread with {user}" + em = discord.Embed(description=desc, color=em.color) + em.set_author(name='Thread closed', url=log_url) + await self.main_category.channels[0].send(embed=em) async def on_message_delete(self, message): """Support for deleting linked messages""" @@ -342,7 +384,7 @@ async def autoupdate_loop(self): if metadata['latest_version'] != self.version: data = await self.modmail_api.update_repository() - print('Updating bot.') + em = discord.Embed(title='Updating bot', color=discord.Color.green()) @@ -357,6 +399,7 @@ async def autoupdate_loop(self): html_url = commit_data["html_url"] short_sha = commit_data['sha'][:6] em.add_field(name='Merge Commit', value=f"[`{short_sha}`]({html_url}) {message} - {user['username']}") + print('Updating bot.') else: await asyncio.sleep(3600) continue diff --git a/cogs/utility.py b/cogs/utility.py index b565770900..eb7bdf81f3 100644 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -453,6 +453,12 @@ async def _add(self, ctx, name: str.lower, *, value): if 'aliases' not in self.bot.config.cache: self.bot.config['aliases'] = {} + if self.bot.get_command(name) or self.bot.config.aliases.get(name): + return await ctx.send(f'A command or alias already exists with the same name: `{name}`') + + if not self.bot.get_command(value.split()[0]): + return await ctx.send(f'The command you are attempting to point to does not exist: `{value.split()[0]}`') + self.bot.config.aliases[name] = value await self.bot.config.update()