2222SOFTWARE.
2323"""
2424
25- __version__ = '2.0.4 '
25+ __version__ = '2.0.5 '
2626
2727import asyncio
2828import 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
0 commit comments