feat: 支持多个事件的返回值

This commit is contained in:
Rock Chin 2023-01-15 20:37:23 +08:00
parent df9e89deb7
commit e582780195
3 changed files with 22 additions and 0 deletions

View File

@ -30,6 +30,9 @@ PersonNormalMessageReceived = "person_normal_message_received"
launcher_id: int 发起对象ID(群号/QQ号)
sender_id: int 发送者ID(QQ号)
text_message: str 消息文本
returns (optional):
alter: str 修改后的消息文本
"""
PersonCommandSent = "person_command_sent"
@ -44,6 +47,7 @@ PersonCommandSent = "person_command_sent"
is_admin: bool 是否为管理员
returns (optional):
alter: str 修改后的完整指令文本
reply: list 回复消息组件列表
"""
@ -54,6 +58,9 @@ GroupNormalMessageReceived = "group_normal_message_received"
launcher_id: int 发起对象ID(群号/QQ号)
sender_id: int 发送者ID(QQ号)
text_message: str 消息文本
returns (optional):
alter: str 修改后的消息文本
"""
GroupCommandSent = "group_command_sent"
@ -66,6 +73,10 @@ GroupCommandSent = "group_command_sent"
params: list[str] 参数列表
text_message: str 完整指令文本
is_admin: bool 是否为管理员
returns (optional):
alter: str 修改后的完整指令文本
reply: list 回复消息组件列表
"""
NormalMessageResponded = "normal_message_responded"
@ -79,6 +90,7 @@ NormalMessageResponded = "normal_message_responded"
response_text: str 响应文本
returns (optional):
prefix: str 修改后的回复文字消息的前缀
reply: list 替换回复消息组件列表
"""

View File

@ -34,6 +34,10 @@ def process_normal_message(text_message: str, mgr, config, launcher_type: str,
}
event = pkg.plugin.host.emit(plugin_models.NormalMessageResponded, **args)
if event.get_return_value("prefix") is not None:
prefix = event.get_return_value("prefix")
if event.get_return_value("reply") is not None:
reply = event.get_return("reply")

View File

@ -81,6 +81,9 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
if launcher_type == 'person'
else plugin_models.GroupCommandSent, **args)
if event.get_return_value("alter") is not None:
text_message = event.get_return_value("alter")
# 取出插件提交的返回值赋值给reply
if event.get_return_value("reply") is not None:
reply.append(event.get_return("reply"))
@ -101,6 +104,9 @@ def process_message(launcher_type: str, launcher_id: int, text_message: str, mes
if launcher_type == 'person'
else plugin_models.GroupNormalMessageReceived, **args)
if event.get_return_value("alter") is not None:
text_message = event.get_return_value("alter")
if not event.is_prevented_default():
reply = pkg.qqbot.message.process_normal_message(text_message,
mgr, config, launcher_type, launcher_id, sender_id)