Skip to content

Commit aeda15e

Browse files
committed
Deleting thread channels is now a valid way to close a thread
1 parent 6488a80 commit aeda15e

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

Diff for: CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
#v2.0.4
7+
# v2.0.5
8+
9+
### Changed
10+
- Alias command now checks if you are adding a valid alias - command combo.
11+
- Deleting a channel manually will now correctly close the thread and post logs.
12+
13+
# v2.0.4
814

915
### Fixed
1016
- Fixed a one off bug where the channel topic dissapears, but modmail operations should still continue

Diff for: bot.py

+45-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
SOFTWARE.
2323
"""
2424

25-
__version__ = '2.0.4'
25+
__version__ = '2.0.5'
2626

2727
import asyncio
2828
import textwrap
@@ -244,6 +244,48 @@ async def on_message(self, message):
244244
message.content = f'{prefix}reply {self.snippets[cmd]}'
245245

246246
await self.process_commands(message)
247+
248+
async def on_guild_channel_delete(self, channel):
249+
if channel.guild != self.modmail_guild:
250+
return
251+
thread = await self.threads.find(channel=channel)
252+
if thread:
253+
del self.threads.cache[thread.id]
254+
255+
mod = None
256+
257+
audit_logs = self.modmail_guild.audit_logs()
258+
entry = await audit_logs.find(lambda e: e.target.id == channel.id)
259+
mod = entry.user
260+
261+
log_data = await self.modmail_api.post_log(channel.id, {
262+
'open': False,
263+
'closed_at': str(datetime.datetime.utcnow()),
264+
'closer': {
265+
'id': str(mod.id),
266+
'name': mod.name,
267+
'discriminator': mod.discriminator,
268+
'avatar_url': mod.avatar_url,
269+
'mod': True
270+
}})
271+
272+
em = discord.Embed(title='Thread Closed')
273+
em.description = f'{mod.mention} has closed this modmail thread.'
274+
em.color = discord.Color.red()
275+
276+
try:
277+
await thread.recipient.send(embed=em)
278+
except:
279+
pass
280+
281+
log_url = f"https://logs.modmail.tk/{log_data['user_id']}/{log_data['key']}"
282+
283+
user = thread.recipient.mention if thread.recipient else f'`{thread.id}`'
284+
285+
desc = f"[`{log_data['key']}`]({log_url}) {mod.mention} closed a thread with {user}"
286+
em = discord.Embed(description=desc, color=em.color)
287+
em.set_author(name='Thread closed', url=log_url)
288+
await self.main_category.channels[0].send(embed=em)
247289

248290
async def on_message_delete(self, message):
249291
"""Support for deleting linked messages"""
@@ -342,7 +384,7 @@ async def autoupdate_loop(self):
342384

343385
if metadata['latest_version'] != self.version:
344386
data = await self.modmail_api.update_repository()
345-
print('Updating bot.')
387+
346388

347389
em = discord.Embed(title='Updating bot', color=discord.Color.green())
348390

@@ -357,6 +399,7 @@ async def autoupdate_loop(self):
357399
html_url = commit_data["html_url"]
358400
short_sha = commit_data['sha'][:6]
359401
em.add_field(name='Merge Commit', value=f"[`{short_sha}`]({html_url}) {message} - {user['username']}")
402+
print('Updating bot.')
360403
else:
361404
await asyncio.sleep(3600)
362405
continue

Diff for: cogs/utility.py

+6
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ async def _add(self, ctx, name: str.lower, *, value):
453453
if 'aliases' not in self.bot.config.cache:
454454
self.bot.config['aliases'] = {}
455455

456+
if self.bot.get_command(name) or self.bot.config.aliases.get(name):
457+
return await ctx.send(f'A command or alias already exists with the same name: `{name}`')
458+
459+
if not self.bot.get_command(value.split()[0]):
460+
return await ctx.send(f'The command you are attempting to point to does not exist: `{value.split()[0]}`')
461+
456462
self.bot.config.aliases[name] = value
457463
await self.bot.config.update()
458464

0 commit comments

Comments
 (0)