88from collections .abc import Collection
99import datetime
1010import enum
11+ import io
1112import itertools
1213import re
1314import time
@@ -349,11 +350,12 @@ async def thread_triple(thread: discord.Thread):
349350
350351 @staticmethod
351352 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
353354 ):
354355 """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 .
356357 """
358+ deletion_successful = False
357359 try :
358360 await asyncio .sleep (delay ) # allow cancelling during delay
359361 except asyncio .CancelledError :
@@ -363,11 +365,34 @@ async def delete_bad_message_with_thread(
363365 try :
364366 if isinstance (message .channel , discord .Thread ):
365367 await message .channel .delete ()
366-
367368 await message .delete ()
368369 except discord .NotFound :
369370 # don't error here if thread and/or message were already deleted
370371 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+ )
371396
372397 def showcase_message_validity_check (
373398 self ,
0 commit comments