mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-20 03:16:14 +00:00
feat: person_message和group_message的事件钩子
This commit is contained in:
@@ -91,3 +91,11 @@ class PluginHost:
|
|||||||
def get_runtime_context(self) -> context:
|
def get_runtime_context(self) -> context:
|
||||||
"""获取运行时上下文"""
|
"""获取运行时上下文"""
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
def get_bot(self):
|
||||||
|
"""获取机器人对象"""
|
||||||
|
return context.get_qqbot_manager().bot
|
||||||
|
|
||||||
|
def notify_admin(self, message):
|
||||||
|
"""通知管理员"""
|
||||||
|
context.get_qqbot_manager().notify_admin(message)
|
||||||
|
|||||||
+28
-2
@@ -1,22 +1,48 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pkg.plugin.host as host
|
import pkg.plugin.host as host
|
||||||
|
import pkg.utils.context
|
||||||
|
|
||||||
__current_registering_plugin__ = ""
|
__current_registering_plugin__ = ""
|
||||||
|
|
||||||
import pkg.utils.context
|
|
||||||
|
|
||||||
PersonMessage = "person_message"
|
PersonMessage = "person_message"
|
||||||
|
"""收到私聊消息时,在判断是否应该响应前触发
|
||||||
|
kwargs:
|
||||||
|
launcher_type: str 发起对象类型(group/person)
|
||||||
|
launcher_id: int 发起对象ID(群号/QQ号)
|
||||||
|
sender_id: int 发送者ID(QQ号)
|
||||||
|
message_chain: mirai.models.message.MessageChain 消息链
|
||||||
|
"""
|
||||||
|
|
||||||
GroupMessage = "group_message"
|
GroupMessage = "group_message"
|
||||||
|
"""收到群聊消息时,在判断是否应该响应前触发(所有群消息)"""
|
||||||
|
|
||||||
PersonNormalMessage = "person_normal_message"
|
PersonNormalMessage = "person_normal_message"
|
||||||
|
"""判断为应该处理的私聊普通消息时触发"""
|
||||||
|
|
||||||
PersonCommand = "person_command"
|
PersonCommand = "person_command"
|
||||||
|
"""判断为应该处理的私聊指令时触发"""
|
||||||
|
|
||||||
GroupNormalMessage = "group_normal_message"
|
GroupNormalMessage = "group_normal_message"
|
||||||
|
"""判断为应该处理的群聊普通消息时触发"""
|
||||||
|
|
||||||
GroupCommand = "group_command"
|
GroupCommand = "group_command"
|
||||||
|
"""判断为应该处理的群聊指令时触发"""
|
||||||
|
|
||||||
SessionFirstMessage = "session_first_message"
|
SessionFirstMessage = "session_first_message"
|
||||||
|
"""会话被第一次交互时触发"""
|
||||||
|
|
||||||
SessionReset = "session_reset"
|
SessionReset = "session_reset"
|
||||||
|
"""会话被用户手动重置时触发"""
|
||||||
|
|
||||||
SessionExpired = "session_expired"
|
SessionExpired = "session_expired"
|
||||||
|
"""会话过期时触发"""
|
||||||
|
|
||||||
KeyExceeded = "key_exceeded"
|
KeyExceeded = "key_exceeded"
|
||||||
|
"""api-key超额时触发"""
|
||||||
|
|
||||||
KeySwitched = "key_switched"
|
KeySwitched = "key_switched"
|
||||||
|
"""api-key超额切换成功时触发"""
|
||||||
|
|
||||||
|
|
||||||
class Plugin:
|
class Plugin:
|
||||||
|
|||||||
+20
-2
@@ -54,7 +54,7 @@ def check_response_rule(text: str) -> (bool, str):
|
|||||||
class QQBotManager:
|
class QQBotManager:
|
||||||
retry = 3
|
retry = 3
|
||||||
|
|
||||||
bot = None
|
bot: Mirai = None
|
||||||
|
|
||||||
reply_filter = None
|
reply_filter = None
|
||||||
|
|
||||||
@@ -158,7 +158,15 @@ class QQBotManager:
|
|||||||
|
|
||||||
# 私聊消息处理
|
# 私聊消息处理
|
||||||
def on_person_message(self, event: MessageEvent):
|
def on_person_message(self, event: MessageEvent):
|
||||||
plugin_host.emit(plugin_models.PersonMessage)
|
|
||||||
|
# 触发事件
|
||||||
|
args = {
|
||||||
|
"launcher_type": "person",
|
||||||
|
"launcher_id": event.sender.id,
|
||||||
|
"sender_id": event.sender.id,
|
||||||
|
"message_chain": event.message_chain,
|
||||||
|
}
|
||||||
|
plugin_host.emit(plugin_models.PersonMessage, **args)
|
||||||
|
|
||||||
reply = ''
|
reply = ''
|
||||||
|
|
||||||
@@ -194,6 +202,16 @@ class QQBotManager:
|
|||||||
|
|
||||||
# 群消息处理
|
# 群消息处理
|
||||||
def on_group_message(self, event: GroupMessage):
|
def on_group_message(self, event: GroupMessage):
|
||||||
|
|
||||||
|
# 触发事件
|
||||||
|
args = {
|
||||||
|
"launcher_type": "group",
|
||||||
|
"launcher_id": event.group.id,
|
||||||
|
"sender_id": event.sender.id,
|
||||||
|
"message_chain": event.message_chain,
|
||||||
|
}
|
||||||
|
plugin_host.emit(plugin_models.GroupMessage, **args)
|
||||||
|
|
||||||
reply = ''
|
reply = ''
|
||||||
|
|
||||||
def process(text=None) -> str:
|
def process(text=None) -> str:
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# 在此处填写的插件仓库将会被自动下载并加载
|
||||||
|
# 支持gitee和github仓库
|
||||||
|
# 这种加载插件的方式是推荐的,便于插件的获取和更新
|
||||||
|
#
|
||||||
|
# 示例:
|
||||||
|
# plugin_repos = [
|
||||||
|
# 'https://github.com/SampleUser/SampleRepo',
|
||||||
|
# 'https://gitee.com/SampleUser/SampleRepo'
|
||||||
|
# ]
|
||||||
|
|
||||||
|
|
||||||
|
remote_repos = [
|
||||||
|
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user