|
1 | 1 | importasyncio
|
2 | 2 | importcontextlib
|
| 3 | +importhtml |
| 4 | +importjson |
3 | 5 | importlogging
|
4 | 6 | importrandom
|
5 | 7 | importre
|
|
8 | 10 | fromcopyimportdeepcopy
|
9 | 11 | fromtypingimportDict,List,Match,Tuple,cast
|
10 | 12 |
|
| 13 | +fromhttpximportcodes |
11 | 14 | fromtelegramimport (
|
12 | 15 | CallbackQuery,
|
13 | 16 | Chat,
|
@@ -576,7 +579,39 @@ async def long_code_handling(update: Update, context: ContextTypes.DEFAULT_TYPE)
|
576 | 579 |
|
577 | 580 | # the leading ". " is important here since html_markup() splits on whitespaces!
|
578 | 581 | mention=f".{update.effective_user.mention_html()}"ifupdate.effective_userelseNone
|
579 |
| -text=f"{hint.html_markup(mention)}\n\n⚠️ Your message will be deleted in 1 minute." |
| 582 | + |
| 583 | +text= ( |
| 584 | +f"Hi{hint.html_markup(mention)}, we like to keep our groups readable and thus" |
| 585 | +f" require long code to be in a pastebin.\n\n⚠️ Your message will be deleted in 1 minute." |
| 586 | + ) |
| 587 | + |
| 588 | +# check if pastebin was setup |
| 589 | +ifpastebin_client:=context.bot_data.get("pastebin_client"): |
| 590 | +# if there are code formatted snippets we only move those |
| 591 | +ifparsed_entities: |
| 592 | +content="\n\n".join(parsed_entities.values()) |
| 593 | +beginning="⚠️ The code snippet(s) in your message have" |
| 594 | +else: |
| 595 | +content=text |
| 596 | +beginning="⚠️ Your message has" |
| 597 | +r=awaitpastebin_client.post(const.PASTEBIN_URL,content=content) |
| 598 | +# if the request was successful we put the link in the message |
| 599 | +ifr.status_code==codes.OK: |
| 600 | +text= ( |
| 601 | +f"Hi{hint.html_markup(mention)}, we like to keep our groups readable and thus " |
| 602 | +f"require long code to be in a pastebin.\n\n{beginning} been moved to " |
| 603 | +f"{const.PASTEBIN_URL}{r.text}.py. Your original message will be deleted in a " |
| 604 | +f"minute, please reply to this message with your query." |
| 605 | + ) |
| 606 | +else: |
| 607 | +logging.info( |
| 608 | +"The pastebin request failed with the status code %s and the text %s. The " |
| 609 | +"triggering update: %s", |
| 610 | +r.status_code, |
| 611 | +r.text, |
| 612 | +html.escape(json.dumps(update.to_dict(),indent=2,ensure_ascii=False)), |
| 613 | +exc_info=True, |
| 614 | + ) |
580 | 615 |
|
581 | 616 | awaitmessage.reply_text(
|
582 | 617 | text,
|
|