Compare commits

...
5 Commits
Author SHA1 Message Date
YoursFunny 0ca9b55ea8 try edit reply markup 2024-04-28 01:18:35 +08:00
YoursFunny ef17b05c14 fix html escape only message 2024-04-28 01:12:02 +08:00
YoursFunny 85d0257c51 feat: change forward confirm reply markup 2024-04-28 01:08:22 +08:00
YoursFunny 7f90670f1c fix edit message html escape 2024-04-28 01:01:59 +08:00
YoursFunny 755c405196 update ptb version 2024-04-26 15:49:52 +08:00
4 changed files with 11 additions and 9 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ if WEBHOOK:
x_url_regex = re.compile(r"^(?:https?://)(?:www\.|mobile\.|)(?:x|twitter)\.com/(.+)/status/(\d+)") x_url_regex = re.compile(r"^(?:https?://)(?:www\.|mobile\.|)(?:x|twitter)\.com/(.+)/status/(\d+)")
x_media_regex = re.compile(r"^(?:https?://)(pbs|video)\.twimg\.com/(.*)") x_media_regex = re.compile(r"^(?:https?://)(pbs|video)\.twimg\.com/(.*)")
x_tco_regex = re.compile(r"(?:https?://)t\.co/.+$", re.M) x_tco_regex = re.compile(r"(?:https?://)t\.co/.+$", re.M)
message_url_regex = re.compile(r"\{.+\}", re.S) message_url_regex = re.compile(r"\[.+]", re.S)
logging.basicConfig( logging.basicConfig(
level=os.getenv("LOG_LEVEL", "WARNING"), level=os.getenv("LOG_LEVEL", "WARNING"),
+7 -6
View File
@@ -1,3 +1,4 @@
import html
from functools import wraps from functools import wraps
from aiohttp import ClientSession from aiohttp import ClientSession
@@ -56,7 +57,7 @@ async def url_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
if context.user_data.get('edit_before_forward', False): if context.user_data.get('edit_before_forward', False):
message_reply = await update.effective_message.reply_text( message_reply = await update.effective_message.reply_text(
"Reply to edit message.", "Reply to edit message.",
reply_markup=ForceReply(selective=True, input_field_placeholder="{URL}"), reply_markup=ForceReply(selective=True, input_field_placeholder="[URL]"),
reply_to_message_id=update.message.message_id, reply_to_message_id=update.message.message_id,
) )
context.user_data['message_reply'] = message_reply context.user_data['message_reply'] = message_reply
@@ -86,7 +87,7 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
return return
if update.message.reply_to_message != context.user_data['message_reply']: if update.message.reply_to_message != context.user_data['message_reply']:
return return
update_text = update.message.text update_text = html.escape(update.message.text)
match = common.message_url_regex.search(update_text) match = common.message_url_regex.search(update_text)
if match: if match:
match = match.span() match = match.span()
@@ -94,9 +95,9 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
context.user_data['message_url'], update_text[match[0] + 1:match[1] - 1] context.user_data['message_url'], update_text[match[0] + 1:match[1] - 1]
) + update_text[match[1]:] ) + update_text[match[1]:]
message_to_send = context.user_data['message_to_send'] message_to_send = context.user_data['message_to_send']
await message_to_send[0].edit_caption( await message_to_send[0].edit_caption(update_text)
update_text, await context.user_data['message_reply'].edit_reply_markup(
reply_markup=InlineKeyboardMarkup.from_button( InlineKeyboardMarkup.from_button(
InlineKeyboardButton("↩️ Confirm", callback_data="forward") InlineKeyboardButton("↩️ Confirm", callback_data="forward")
) )
) )
@@ -106,7 +107,7 @@ async def query_forward_message(update: Update, context: ContextTypes.DEFAULT_TY
message_to_send = context.user_data['message_to_send'] message_to_send = context.user_data['message_to_send']
await forward_message(update, context, message_to_send) await forward_message(update, context, message_to_send)
await update.callback_query.answer('✅ Forwarded') await update.callback_query.answer('✅ Forwarded')
await update.callback_query.edit_message_reply_markup() await update.callback_query.delete_message()
del context.user_data['message_reply'] del context.user_data['message_reply']
del context.user_data['message_to_send'] del context.user_data['message_to_send']
del context.user_data['message_url'] del context.user_data['message_url']
+1 -1
View File
@@ -1,2 +1,2 @@
python-telegram-bot[webhooks]~=21.0.1 python-telegram-bot[webhooks]~=21.1.1
aiohttp[speedups]~=3.9.3 aiohttp[speedups]~=3.9.3
+2 -1
View File
@@ -190,7 +190,8 @@ class TGTweet(Tweet):
@property @property
def inline_query_generator(self) -> Generator[ def inline_query_generator(self) -> Generator[
InlineQueryResultPhoto | InlineQueryResultVideo | InlineQueryResultMpeg4Gif, None, None]: InlineQueryResultPhoto | InlineQueryResultVideo | InlineQueryResultMpeg4Gif, None, None
]:
for i, tweet_media in enumerate(self.media): for i, tweet_media in enumerate(self.media):
logger.info(str(tweet_media)) logger.info(str(tweet_media))
if tweet_media.type == "image": if tweet_media.type == "image":