Skip to content

Commit d0ee121

Browse files
committed
Add Timeout for Automatically Deleting Long Code Snippets
1 parent 682841b commit d0ee121

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

components/callbacks.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ async def compat_warning(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
525525
)
526526

527527

528-
async def long_code_handling(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
528+
async def long_code_handling(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
529529
"""When someone posts a long code snippet:
530530
Reply with the /pastebin taghint.
531531
Because we do the regexing in here rather than in the filter, the corresponding handler
@@ -561,12 +561,20 @@ async def long_code_handling(update: Update, _: ContextTypes.DEFAULT_TYPE) -> No
561561

562562
# the leading ". " is important here since html_markup() splits on whitespaces!
563563
mention = f". {update.effective_user.mention_html()}" if update.effective_user else None
564+
text = f"{hint.html_markup(mention)}\n\n⚠️ Your message will be deleted in 1 minute."
564565

565566
await message.reply_text(
566-
hint.html_markup(mention),
567+
text,
567568
reply_markup=hint.inline_keyboard,
568569
)
569-
await try_to_delete(message)
570+
571+
async def job_callback(_: ContextTypes.DEFAULT_TYPE) -> None:
572+
await try_to_delete(message)
573+
574+
context.job_queue.run_once( # type: ignore[union-attr]
575+
callback=job_callback,
576+
when=60,
577+
)
570578

571579
# We don't want this message to be processed any further
572580
raise ApplicationHandlerStop

0 commit comments

Comments
 (0)