mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-03-19 21:38:18 +08:00
fix: remove prefix match in voice msg
This commit is contained in:
@@ -54,17 +54,23 @@ class WechatChannel(Channel):
|
|||||||
thread_pool.submit(self._do_handle_voice, msg)
|
thread_pool.submit(self._do_handle_voice, msg)
|
||||||
|
|
||||||
def _do_handle_voice(self, msg):
|
def _do_handle_voice(self, msg):
|
||||||
fileName = TmpDir().path() + msg['FileName']
|
from_user_id = msg['FromUserName']
|
||||||
msg.download(fileName)
|
other_user_id = msg['User']['UserName']
|
||||||
content = super().build_voice_to_text(fileName)
|
if from_user_id == other_user_id:
|
||||||
self._handle_single_msg(msg, content, conf().get('voice_reply_voice'))
|
file_name = TmpDir().path() + msg['FileName']
|
||||||
|
msg.download(file_name)
|
||||||
|
query = super().build_voice_to_text(file_name)
|
||||||
|
if conf().get('voice_reply_voice'):
|
||||||
|
self._do_send_voice(query, from_user_id)
|
||||||
|
else:
|
||||||
|
self._do_send_text(query, from_user_id)
|
||||||
|
|
||||||
def handle_text(self, msg):
|
def handle_text(self, msg):
|
||||||
logger.debug("[WX]receive text msg: " + json.dumps(msg, ensure_ascii=False))
|
logger.debug("[WX]receive text msg: " + json.dumps(msg, ensure_ascii=False))
|
||||||
content = msg['Text']
|
content = msg['Text']
|
||||||
self._handle_single_msg(msg, content, False)
|
self._handle_single_msg(msg, content)
|
||||||
|
|
||||||
def _handle_single_msg(self, msg, content, reply_voice=False):
|
def _handle_single_msg(self, msg, content):
|
||||||
from_user_id = msg['FromUserName']
|
from_user_id = msg['FromUserName']
|
||||||
to_user_id = msg['ToUserName'] # 接收人id
|
to_user_id = msg['ToUserName'] # 接收人id
|
||||||
other_user_id = msg['User']['UserName'] # 对手方id
|
other_user_id = msg['User']['UserName'] # 对手方id
|
||||||
@@ -83,8 +89,6 @@ class WechatChannel(Channel):
|
|||||||
if img_match_prefix:
|
if img_match_prefix:
|
||||||
content = content.split(img_match_prefix, 1)[1].strip()
|
content = content.split(img_match_prefix, 1)[1].strip()
|
||||||
thread_pool.submit(self._do_send_img, content, from_user_id)
|
thread_pool.submit(self._do_send_img, content, from_user_id)
|
||||||
elif reply_voice:
|
|
||||||
thread_pool.submit(self._do_send_voice, content, from_user_id)
|
|
||||||
else :
|
else :
|
||||||
thread_pool.submit(self._do_send_text, content, from_user_id)
|
thread_pool.submit(self._do_send_text, content, from_user_id)
|
||||||
elif to_user_id == other_user_id and match_prefix:
|
elif to_user_id == other_user_id and match_prefix:
|
||||||
@@ -96,8 +100,6 @@ class WechatChannel(Channel):
|
|||||||
if img_match_prefix:
|
if img_match_prefix:
|
||||||
content = content.split(img_match_prefix, 1)[1].strip()
|
content = content.split(img_match_prefix, 1)[1].strip()
|
||||||
thread_pool.submit(self._do_send_img, content, to_user_id)
|
thread_pool.submit(self._do_send_img, content, to_user_id)
|
||||||
elif reply_voice:
|
|
||||||
thread_pool.submit(self._do_send_voice, content, to_user_id)
|
|
||||||
else:
|
else:
|
||||||
thread_pool.submit(self._do_send_text, content, to_user_id)
|
thread_pool.submit(self._do_send_text, content, to_user_id)
|
||||||
|
|
||||||
@@ -208,3 +210,4 @@ class WechatChannel(Channel):
|
|||||||
if content.find(ky) != -1:
|
if content.find(ky) != -1:
|
||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,6 @@
|
|||||||
"image_create_prefix": ["画", "看", "找"],
|
"image_create_prefix": ["画", "看", "找"],
|
||||||
"conversation_max_tokens": 1000,
|
"conversation_max_tokens": 1000,
|
||||||
"speech_recognition": false,
|
"speech_recognition": false,
|
||||||
"voice_reply_voice": false,
|
|
||||||
"baidu_app_id": "YOUR BAIDU APP ID",
|
|
||||||
"baidu_api_key": "YOUR BAIDU API KEY",
|
|
||||||
"baidu_secret_key": "YOUR BAIDU SERVICE KEY",
|
|
||||||
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。",
|
"character_desc": "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。",
|
||||||
"expires_in_seconds": 3600
|
"expires_in_seconds": 3600
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user