From c9788c0d81d786da2a68d79a66b7d6d0bc03ac9d Mon Sep 17 00:00:00 2001 From: athphane Date: Sat, 22 Jun 2024 02:10:43 +0500 Subject: [PATCH] - add in auto twitter text updater --- userbot/plugins/subreddit_link.py | 32 --------------- userbot/plugins/text_replacement.py | 63 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 32 deletions(-) delete mode 100644 userbot/plugins/subreddit_link.py create mode 100644 userbot/plugins/text_replacement.py diff --git a/userbot/plugins/subreddit_link.py b/userbot/plugins/subreddit_link.py deleted file mode 100644 index 73d47bb5..00000000 --- a/userbot/plugins/subreddit_link.py +++ /dev/null @@ -1,32 +0,0 @@ -import pyrogram.enums -from pyrogram import filters -from pyrogram.types import Message - -from userbot import UserBot -from userbot.plugins.help import add_command_help - -the_regex = r"^r\/([^\s\/])+" - - -# Generate full Reddit link with subreddit -@UserBot.on_message(filters.regex(the_regex) & filters.me) -async def subreddit_link(bot: UserBot, message: Message): - html = "{string}" - await message.edit( - html.format(link="https://reddit.com/" + message.text, string=message.text), - disable_web_page_preview=True, - parse_mode=pyrogram.enums.ParseMode.HTML, - ) - - -# Command help section -add_command_help( - "reddit", - [ - [ - "r/telegram", - "As long as your message starts with r/, it will automatically generate a subreddit link and " - "hyperlink your message.", - ], - ], -) diff --git a/userbot/plugins/text_replacement.py b/userbot/plugins/text_replacement.py new file mode 100644 index 00000000..62cc3bbf --- /dev/null +++ b/userbot/plugins/text_replacement.py @@ -0,0 +1,63 @@ +import re + +import pyrogram.enums +from pyrogram import filters +from pyrogram.types import Message + +from userbot import UserBot +from userbot.plugins.help import add_command_help + +subreddit_regex = r"^r\/([^\s\/])+" + + +# Generate full Reddit link with subreddit +@UserBot.on_message(filters.regex(subreddit_regex) & filters.me) +async def subreddit_link(bot: UserBot, message: Message): + html = "{string}" + await message.edit( + html.format(link="https://reddit.com/" + message.text, string=message.text), + disable_web_page_preview=True, + parse_mode=pyrogram.enums.ParseMode.HTML, + ) + + +# Assuming UserBot is your Client instance +twitter_regex = r'https?://(www\.)?(twitter\.com|x\.com)/[^\s]+' + + +@UserBot.on_message(filters.regex(twitter_regex) & filters.me) +async def twitter_url_fixer(bot: UserBot, message: Message): + # Extract the text from the message + message_text = message.text + + # Check and replace twitter.com or x.com with fxtwitter.com + modified_text = re.sub(r'(https?://)(twitter\.com|x\.com)', r'\1fxtwitter.com', message_text) + + # Edit the message with the modified link + await message.edit( + modified_text, + disable_web_page_preview=False # Webpage preview enabled + ) + + +# Command help section +add_command_help( + "reddit", + [ + [ + "r/telegram", + "As long as your message starts with r/, it will automatically generate a subreddit link and " + "hyperlink your message.", + ], + ], +) +add_command_help( + "twitter", + [ + [ + "https://twitter.com/username", + "If the message contains a Twitter link, it will automatically replace twitter.com or x.com with " + "fxtwitter.com.", + ], + ], +)