8
8
from collections .abc import Collection
9
9
import datetime
10
10
import enum
11
+ import io
11
12
import itertools
12
13
import re
13
14
import time
@@ -349,11 +350,12 @@ async def thread_triple(thread: discord.Thread):
349
350
350
351
@staticmethod
351
352
async def delete_bad_message_with_thread (
352
- message : discord .Message , delay : float = 0.0
353
+ message : discord .Message , delay : float = 0.0 , repost_to_dm : bool = True
353
354
):
354
355
"""A function to pardon a bad message and its post/thread (if present) with a grace period. If this coroutine is not cancelled during the
355
- grace period specified in `delay` in seconds, it will delete `thread `, if possible.
356
+ grace period specified in `delay` in seconds, it will delete `message `, if possible, and send the message contents via DM to the affected user .
356
357
"""
358
+ deletion_successful = False
357
359
try :
358
360
await asyncio .sleep (delay ) # allow cancelling during delay
359
361
except asyncio .CancelledError :
@@ -363,11 +365,34 @@ async def delete_bad_message_with_thread(
363
365
try :
364
366
if isinstance (message .channel , discord .Thread ):
365
367
await message .channel .delete ()
366
-
367
368
await message .delete ()
368
369
except discord .NotFound :
369
370
# don't error here if thread and/or message were already deleted
370
371
pass
372
+ else :
373
+ deletion_successful = True
374
+
375
+ if deletion_successful :
376
+ await message .author .send (
377
+ content = "Your showcase message/post was deleted for not meeting the message formatting rules."
378
+ "\n Here is the message content and attachments in case you need to retrieve them:\n "
379
+ + (
380
+ f"**Post title:** `{ message .channel .name } `"
381
+ if isinstance (message .channel , discord .Thread )
382
+ else ""
383
+ ),
384
+ files = [
385
+ discord .File (
386
+ io .StringIO (message .content ), # type: ignore
387
+ filename = "showcase_message_content.txt" ,
388
+ ),
389
+ * [
390
+ await att .to_file (use_cached = True )
391
+ for att in message .attachments
392
+ if att .size < 2 ** 20 * 25
393
+ ],
394
+ ],
395
+ )
371
396
372
397
def showcase_message_validity_check (
373
398
self ,
0 commit comments