Skip to content

Commit

Permalink
Improve bot message creation error handling in 'showcase' extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Mega-JC committed Jul 27, 2024
1 parent f2d1fc0 commit 5ebbb9f
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions pcbot/exts/showcase/cogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,18 @@ async def on_thread_create(self, thread: discord.Thread):
deletion_datetime = datetime.datetime.now(
datetime.timezone.utc
) + datetime.timedelta(minutes=5)
warn_msg = await message.reply(
"### Invalid showcase message\n\n"
f"{reason}\n\n"
" If no changes are made, your message (and its thread/post) will be "
f"deleted {snakecore.utils.create_markdown_timestamp(deletion_datetime, 'R')}."
)

try:
warn_msg = await message.reply(
"### Invalid showcase message\n\n"
f"{reason}\n\n"
" If no changes are made, your message (and its thread/post) will be "
f"deleted {snakecore.utils.create_markdown_timestamp(deletion_datetime, 'R')}."
)
except discord.HTTPException as e:
if e.status == 400:
return

self.entry_message_deletion_dict[message.id] = (
asyncio.create_task(
self.delete_bad_message_with_thread(message, delay=300)
Expand All @@ -432,11 +438,15 @@ async def prompt_author_for_feedback_thread(self, message: discord.Message):
datetime.timezone.utc
) + datetime.timedelta(minutes=1)

alert_msg = await message.reply(
content=f"Need a feedback thread?\n\n-# This message will be deleted "
+ snakecore.utils.create_markdown_timestamp(deletion_datetime, "R")
+ ".",
)
try:
alert_msg = await message.reply(
content=f"Need a feedback thread?\n\n-# This message will be deleted "
+ snakecore.utils.create_markdown_timestamp(deletion_datetime, "R")
+ ".",
)
except discord.HTTPException as e:
if e.status == 400:
return

await alert_msg.add_reaction("✅")
await alert_msg.add_reaction("❌")
Expand Down Expand Up @@ -522,12 +532,18 @@ async def on_message(self, message: discord.Message):
deletion_datetime = datetime.datetime.now(
datetime.timezone.utc
) + datetime.timedelta(minutes=5)
warn_msg = await message.reply(
"### Invalid showcase message\n\n"
f"{reason}\n\n"
" If no changes are made, your message (and its thread/post) will be "
f"deleted {snakecore.utils.create_markdown_timestamp(deletion_datetime, 'R')}."
)

try:
warn_msg = await message.reply(
"### Invalid showcase message\n\n"
f"{reason}\n\n"
" If no changes are made, your message (and its thread/post) will be "
f"deleted {snakecore.utils.create_markdown_timestamp(deletion_datetime, 'R')}."
)
except discord.HTTPException as e:
if e.status == 400:
return

self.entry_message_deletion_dict[message.id] = (
asyncio.create_task(
self.delete_bad_message_with_thread(message, delay=300)
Expand Down

0 comments on commit 5ebbb9f

Please sign in to comment.