From b74274b96b48efa5b291f1f4baa4f7fddfd311d8 Mon Sep 17 00:00:00 2001 From: lanvent Date: Mon, 3 Apr 2023 02:00:33 +0800 Subject: [PATCH] fix: old code in hello plugin --- plugins/README.md | 13 ++++++++----- plugins/hello/hello.py | 7 ++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/README.md b/plugins/README.md index 3db6f2a..0fda3a9 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -101,7 +101,7 @@ PS: 插件目前支持`itchat`和`wechaty` 根据`Context`和回复`Reply`的类型,对回复的内容进行装饰。目前的装饰有以下两种: -- `TEXT`文本回复,根据是否在群聊中来决定是艾特接收方还是添加回复的前缀。 +- `TEXT`文本回复:如果这次消息需要的回复是`VOICE`,进行文字转语音回复之后再次装饰。 否则根据是否在群聊中来决定是艾特接收方还是添加回复的前缀。 - `INFO`或`ERROR`类型,会在消息前添加对应的系统提示字样。 @@ -110,8 +110,11 @@ PS: 插件目前支持`itchat`和`wechaty` ```python if reply.type == ReplyType.TEXT: reply_text = reply.content + if context.get('desire_rtype') == ReplyType.VOICE: + reply = super().build_text_to_voice(reply.content) + return self._decorate_reply(context, reply) if context['isgroup']: - reply_text = '@' + context['msg']['ActualNickName'] + ' ' + reply_text.strip() + reply_text = '@' + context['msg'].actual_user_nickname + ' ' + reply_text.strip() reply_text = conf().get("group_chat_reply_prefix", "")+reply_text else: reply_text = conf().get("single_chat_reply_prefix", "")+reply_text @@ -213,11 +216,11 @@ class Hello(Plugin): if content == "Hello": reply = Reply() reply.type = ReplyType.TEXT - msg = e_context['context']['msg'] + msg:ChatMessage = e_context['context']['msg'] if e_context['context']['isgroup']: - reply.content = "Hello, " + msg['ActualNickName'] + " from " + msg['User'].get('NickName', "Group") + reply.content = f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}" else: - reply.content = "Hello, " + msg['User'].get('NickName', "My friend") + reply.content = f"Hello, {msg.from_user_nickname}" e_context['reply'] = reply e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑 if content == "End": diff --git a/plugins/hello/hello.py b/plugins/hello/hello.py index be4cc05..dc91f16 100644 --- a/plugins/hello/hello.py +++ b/plugins/hello/hello.py @@ -2,6 +2,7 @@ from bridge.context import ContextType from bridge.reply import Reply, ReplyType +from channel.chat_message import ChatMessage import plugins from plugins import * from common.log import logger @@ -24,11 +25,11 @@ class Hello(Plugin): if content == "Hello": reply = Reply() reply.type = ReplyType.TEXT - msg = e_context['context']['msg'] + msg:ChatMessage = e_context['context']['msg'] if e_context['context']['isgroup']: - reply.content = "Hello, " + msg['ActualNickName'] + " from " + msg['User'].get('NickName', "Group") + reply.content = f"Hello, {msg.actual_user_nickname} from {msg.from_user_nickname}" else: - reply.content = "Hello, " + msg['User'].get('NickName', "My friend") + reply.content = f"Hello, {msg.from_user_nickname}" e_context['reply'] = reply e_context.action = EventAction.BREAK_PASS # 事件结束,并跳过处理context的默认逻辑