Compare commits

..
4 Commits
Author SHA1 Message Date
YoursFunny a7d144f2ee fix multiple media forward 2024-03-25 16:54:08 +08:00
YoursFunny 081ee595b1 remove edit reply 2024-03-24 22:54:23 +08:00
YoursFunny 4272454f9a fix url match 2024-03-24 22:33:36 +08:00
YoursFunny 7d289c9db7 fix multiple line substitution 2024-03-24 22:32:22 +08:00
2 changed files with 10 additions and 6 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"\{\w+\}", re.M) message_url_regex = re.compile(r"\{.+\}", re.S)
logging.basicConfig( logging.basicConfig(
level=os.getenv("LOG_LEVEL", "WARNING"), level=os.getenv("LOG_LEVEL", "WARNING"),
+9 -5
View File
@@ -56,7 +56,8 @@ 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="{}"), reply_markup=ForceReply(selective=True, input_field_placeholder="{URL}"),
reply_to_message_id=update.message.message_id,
) )
context.user_data['message_reply'] = message_reply context.user_data['message_reply'] = message_reply
context.user_data['message_to_send'] = message_to_send context.user_data['message_to_send'] = message_to_send
@@ -69,11 +70,13 @@ async def url_media(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
async def forward_message( async def forward_message(
update: Update, update: Update,
context: ContextTypes.DEFAULT_TYPE, context: ContextTypes.DEFAULT_TYPE,
message_sent: tuple[Message, ...], message_to_send: tuple[Message, ...],
) -> None: ) -> None:
try: try:
for i, m in enumerate(message_sent): await update.effective_chat.copy_messages(
await m.copy(context.user_data['forward_channel_id']) context.user_data['forward_channel_id'],
[m.id for m in message_to_send]
)
except Exception as e: except Exception as e:
await update.effective_message.reply_text(str(e)) await update.effective_message.reply_text(str(e))
@@ -84,8 +87,9 @@ async def edit_message(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No
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 = update.message.text
match = common.message_url_regex.search(update_text).span() match = common.message_url_regex.search(update_text)
if match: if match:
match = match.span()
update_text = update_text[:match[0]] + '<a href="{0}">{1}</a>'.format( update_text = update_text[:match[0]] + '<a href="{0}">{1}</a>'.format(
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]:]