Commit 3ba13c8

benny-dou <60535774+benny-dou@users.noreply.github.com>
2025-02-02 09:19:24
fix(asr): fix trigger message parsing
1 parent 43efd33
Changed files (1)
src/asr/voice_recognition.py
@@ -170,7 +170,7 @@ async def voice_to_text(
         # send results
         caption = smart_split(final, CAPTION_LENGTH)[0]
         remaining_texts = final.removeprefix(caption)
-        reply_parameters = get_reply_to(this_info["mid"], trigger_info["mid"])
+        reply_parameters = get_reply_to(trigger_info["mid"], kwargs.get("reply_msg_id", 0))
         target_chat = kwargs["target_chat"] if kwargs.get("target_chat") else this_info["cid"]
         await client.copy_message(chat_id=to_int(target_chat), from_chat_id=trigger_info["cid"], message_id=trigger_info["mid"], caption=caption, reply_parameters=reply_parameters)
         await send_texts(client, target_chat, reply_parameters, texts=remaining_texts)
@@ -202,23 +202,23 @@ def get_trigger_message(
     info = parse_msg(message)
     this_text = info["text"]  # this message
     if info["ctype"].lower() in ["group", "supergroup", "channel", "bot"]:
-        asr_need_prefix = asr_need_prefix or True
+        asr_need_prefix = asr_need_prefix if asr_need_prefix is not None else True
         asr_skip_voice = asr_skip_voice or False
         asr_skip_audio = asr_skip_audio or False
         asr_skip_audio = asr_skip_audio or False
     else:  # private chat
         asr_need_prefix = asr_need_prefix or False
         asr_skip_voice = asr_skip_voice or False
-        asr_skip_audio = asr_skip_audio or True
-        asr_skip_video = asr_skip_video or True
+        asr_skip_audio = asr_skip_audio if asr_skip_audio is not None else True
+        asr_skip_video = asr_skip_video if asr_skip_video is not None else True
 
     # skip no "/asr" prefix message if asr_need_prefix
     if asr_need_prefix and not startswith_prefix(this_text, prefix=[PREFIX.ASR]):
         return None
 
     # treat the reply_to_message as the real message need to be recognized
-    trigger_msg = message.reply_to_message if startswith_prefix(this_text, prefix=[PREFIX.ASR]) else message
-    trigger_info = parse_msg(trigger_msg)
+    trigger_msg = message.reply_to_message if message.reply_to_message and startswith_prefix(this_text, prefix=[PREFIX.ASR]) else message
+    trigger_info = parse_msg(trigger_msg, silent=True)
 
     # skip non voice/audio/video message
     if not trigger_msg: