compatible for voice

This commit is contained in:
lanvent
2023-03-13 00:12:34 +08:00
parent cee57e4ffc
commit 8d2e81815c
6 changed files with 64 additions and 40 deletions

View File

@@ -100,11 +100,15 @@ class Godcmd(Plugin):
def on_handle_context(self, e_context: EventContext):
content = e_context['context']['content']
context_type = e_context['context']['type']
logger.debug("[Godcmd] on_handle_context. content: %s" % content)
if context_type != "TEXT":
if not self.isrunning:
e_context.action = EventAction.BREAK_PASS
return
if content.startswith("#") and context_type == "TEXT":
content = e_context['context']['content']
logger.debug("[Godcmd] on_handle_context. content: %s" % content)
if content.startswith("#"):
# msg = e_context['context']['msg']
user = e_context['context']['receiver']
session_id = e_context['context']['session_id']
@@ -176,8 +180,6 @@ class Godcmd(Plugin):
e_context.action = EventAction.BREAK_PASS # 事件结束并跳过处理context的默认逻辑
elif not self.isrunning:
e_context.action = EventAction.BREAK_PASS
else:
e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
def authenticate(self, userid, args, isadmin, isgroup) -> Tuple[bool,str] :
if isgroup:

View File

@@ -14,26 +14,31 @@ class Hello(Plugin):
def on_handle_context(self, e_context: EventContext):
logger.debug("[Hello] on_handle_context. content: %s" % e_context['context']['content'])
if e_context['context']['content'] == "Hello":
e_context['reply']['type'] = "TEXT"
if e_context['context']['type'] != "TEXT":
return
content = e_context['context']['content']
logger.debug("[Hello] on_handle_context. content: %s" % content)
if content == "Hello":
reply = {}
reply['type'] = "TEXT"
msg = e_context['context']['msg']
if e_context['context']['isgroup']:
e_context['reply']['content'] = "Hello, " + msg['ActualNickName'] + " from " + msg['User'].get('NickName', "Group")
reply['content'] = "Hello, " + msg['ActualNickName'] + " from " + msg['User'].get('NickName', "Group")
else:
e_context['reply']['content'] = "Hello, " + msg['User'].get('NickName', "My friend")
reply['content'] = "Hello, " + msg['User'].get('NickName', "My friend")
e_context['reply'] = reply
e_context.action = EventAction.BREAK_PASS # 事件结束并跳过处理context的默认逻辑
if e_context['context']['content'] == "Hi":
e_context['reply']['type'] = "TEXT"
e_context['reply']['content'] = "Hi"
if content == "Hi":
reply={}
reply['type'] = "TEXT"
reply['content'] = "Hi"
e_context['reply'] = reply
e_context.action = EventAction.BREAK # 事件结束进入默认处理逻辑一般会覆写reply
if e_context['context']['content'] == "End":
if content == "End":
# 如果是文本消息"End",将请求转换成"IMAGE_CREATE"并将content设置为"The World"
if e_context['context']['type'] == "TEXT":
e_context['context']['type'] = "IMAGE_CREATE"
e_context['context']['content'] = "The World"
e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
e_context['context']['type'] = "IMAGE_CREATE"
content = "The World"
e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑