From 5ef3c02f6e2dc9cbc70d3a3105c5ec9a6148295d Mon Sep 17 00:00:00 2001 From: Alter-xyz <88554920+alterxyz@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:27:17 -0400 Subject: [PATCH] feat: FxTwitter handler - reply with modified tweet link - edit tweet link only message - by bot repeat modified link - then delete original user message --- handlers/tweet.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 handlers/tweet.py diff --git a/handlers/tweet.py b/handlers/tweet.py new file mode 100644 index 0000000..4b4515b --- /dev/null +++ b/handlers/tweet.py @@ -0,0 +1,30 @@ +from urlextract import URLExtract +from telebot import TeleBot +from telebot.types import Message + +from . import * + + +def tweet_handler(message: Message, bot: TeleBot): + """tweet: /t """ + who = "tweet" + + extractor = URLExtract() + links = extractor.find_urls(message.text) + + only_links = len("".join(links)) == len(message.text.strip()) + if links: + reply_id = bot_reply_first(message, who, bot) + processed_links = [ + link.replace("twitter.com", "fxtwitter.com").replace("x.com", "fixupx.com") + for link in links + ] + bot_reply_markdown(reply_id, who, "\n".join(processed_links), bot) + + if only_links: + bot.delete_message(message.chat.id, message.message_id) + + +def register(bot: TeleBot) -> None: + bot.register_message_handler(tweet_handler, commands=["t"], pass_bot=True) + bot.register_message_handler(tweet_handler, regexp="^t:", pass_bot=True)