22
22
SOFTWARE.
23
23
"""
24
24
25
- __version__ = '2.0.4 '
25
+ __version__ = '2.0.5 '
26
26
27
27
import asyncio
28
28
import textwrap
@@ -244,6 +244,48 @@ async def on_message(self, message):
244
244
message .content = f'{ prefix } reply { self .snippets [cmd ]} '
245
245
246
246
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 )
247
289
248
290
async def on_message_delete (self , message ):
249
291
"""Support for deleting linked messages"""
@@ -342,7 +384,7 @@ async def autoupdate_loop(self):
342
384
343
385
if metadata ['latest_version' ] != self .version :
344
386
data = await self .modmail_api .update_repository ()
345
- print ( 'Updating bot.' )
387
+
346
388
347
389
em = discord .Embed (title = 'Updating bot' , color = discord .Color .green ())
348
390
@@ -357,6 +399,7 @@ async def autoupdate_loop(self):
357
399
html_url = commit_data ["html_url" ]
358
400
short_sha = commit_data ['sha' ][:6 ]
359
401
em .add_field (name = 'Merge Commit' , value = f"[`{ short_sha } `]({ html_url } ) { message } - { user ['username' ]} " )
402
+ print ('Updating bot.' )
360
403
else :
361
404
await asyncio .sleep (3600 )
362
405
continue
0 commit comments