Skip to content

Commit d9ef5a6

Browse files
committed
fix: 无前缀触发bug
1 parent 66a81cd commit d9ef5a6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

channel/wechat/wechat_channel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def startup(self):
105105
# isgroup: 是否是群聊
106106
# receiver: 需要回复的对象
107107
# msg: itchat的原始消息对象
108-
# origin_ctype: 原始消息类型,用于私聊语音消息时,避免匹配前缀
109-
# desire_rtype: 希望回复类型,TEXT类型是文本回复,VOICE类型是语音回复
108+
# origin_ctype: 原始消息类型,语音转文字后,私聊时如果匹配前缀失败,会根据初始消息是否是语音来放宽触发规则
109+
# desire_rtype: 希望回复类型,默认是文本回复,设置为ReplyType.VOICE是语音回复
110110

111111
@time_checker
112112
@_check
@@ -209,6 +209,7 @@ def handle_group_voice(self, msg):
209209
if context:
210210
thread_pool.submit(self.handle, context).add_done_callback(thread_pool_callback)
211211

212+
# 根据消息构造context,消息内容相关的触发项写在这里
212213
def _compose_context(self, ctype: ContextType, content, **kwargs):
213214
context = Context(ctype, content)
214215
context.kwargs = kwargs
@@ -233,9 +234,9 @@ def _compose_context(self, ctype: ContextType, content, **kwargs):
233234
return None
234235
else: # 单聊
235236
match_prefix = check_prefix(content, conf().get('single_chat_prefix'))
236-
if match_prefix: # 判断如果匹配到自定义前缀,则返回过滤掉前缀+空格后的内容
237+
if match_prefix is not None: # 判断如果匹配到自定义前缀,则返回过滤掉前缀+空格后的内容
237238
content = content.replace(match_prefix, '', 1).strip()
238-
elif context["origin_ctype"] == ContextType.VOICE: # 如果源消息是私聊的语音消息,不匹配前缀,直接返回
239+
elif context["origin_ctype"] == ContextType.VOICE: # 如果源消息是私聊的语音消息,允许不匹配前缀,放宽条件
239240
pass
240241
else:
241242
return None

0 commit comments

Comments
 (0)