Skip to content

Commit 4333ab1

Browse files
committed
Resend deleted invalid showcase messages to member DMs in info message in 'showcase' extension
1 parent c423d8a commit 4333ab1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

pcbot/exts/showcase/cogs.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections.abc import Collection
99
import datetime
1010
import enum
11+
import io
1112
import itertools
1213
import re
1314
import 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+
"\nHere 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

Comments
 (0)