mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 15:26:03 +00:00
feat: preliminarily implement pipeline invoking
This commit is contained in:
@@ -55,25 +55,25 @@ class RuntimeBot:
|
||||
async def on_friend_message(event: platform_events.FriendMessage, adapter: msadapter.MessagePlatformAdapter):
|
||||
|
||||
await self.ap.query_pool.add_query(
|
||||
bot_uuid=self.bot_entity.uuid,
|
||||
launcher_type=core_entities.LauncherTypes.PERSON,
|
||||
launcher_id=event.sender.id,
|
||||
sender_id=event.sender.id,
|
||||
message_event=event,
|
||||
message_chain=event.message_chain,
|
||||
adapter=adapter,
|
||||
pipeline_uuid=self.bot_entity.use_pipeline_uuid
|
||||
)
|
||||
|
||||
async def on_group_message(event: platform_events.GroupMessage, adapter: msadapter.MessagePlatformAdapter):
|
||||
|
||||
await self.ap.query_pool.add_query(
|
||||
bot_uuid=self.bot_entity.uuid,
|
||||
launcher_type=core_entities.LauncherTypes.GROUP,
|
||||
launcher_id=event.group.id,
|
||||
sender_id=event.sender.id,
|
||||
message_event=event,
|
||||
message_chain=event.message_chain,
|
||||
adapter=adapter,
|
||||
pipeline_uuid=self.bot_entity.use_pipeline_uuid
|
||||
)
|
||||
|
||||
self.adapter.register_listener(
|
||||
@@ -113,14 +113,16 @@ class RuntimeBot:
|
||||
async def shutdown(self):
|
||||
await self.adapter.kill()
|
||||
|
||||
self.ap.task_mgr.cancel_task(self.task_wrapper.id)
|
||||
|
||||
|
||||
# 控制QQ消息输入输出的类
|
||||
class PlatformManager:
|
||||
|
||||
# adapter: msadapter.MessageSourceAdapter = None
|
||||
adapters: list[msadapter.MessagePlatformAdapter] = []
|
||||
adapters: list[msadapter.MessagePlatformAdapter] = [] # deprecated
|
||||
|
||||
message_platform_adapter_components: list[engine.Component] = []
|
||||
message_platform_adapter_components: list[engine.Component] = [] # deprecated
|
||||
|
||||
# ====== 4.0 ======
|
||||
ap: app.Application = None
|
||||
@@ -215,50 +217,36 @@ class PlatformManager:
|
||||
return None
|
||||
|
||||
async def write_back_config(self, adapter_name: str, adapter_inst: msadapter.MessagePlatformAdapter, config: dict):
|
||||
index = -2
|
||||
# index = -2
|
||||
|
||||
for i, adapter in enumerate(self.adapters):
|
||||
if adapter == adapter_inst:
|
||||
index = i
|
||||
break
|
||||
# for i, adapter in enumerate(self.adapters):
|
||||
# if adapter == adapter_inst:
|
||||
# index = i
|
||||
# break
|
||||
|
||||
if index == -2:
|
||||
raise Exception('平台适配器未找到')
|
||||
# if index == -2:
|
||||
# raise Exception('平台适配器未找到')
|
||||
|
||||
# 只修改启用的适配器
|
||||
real_index = -1
|
||||
# # 只修改启用的适配器
|
||||
# real_index = -1
|
||||
|
||||
for i, adapter in enumerate(self.ap.platform_cfg.data['platform-adapters']):
|
||||
if adapter['enable']:
|
||||
index -= 1
|
||||
if index == -1:
|
||||
real_index = i
|
||||
break
|
||||
# for i, adapter in enumerate(self.ap.platform_cfg.data['platform-adapters']):
|
||||
# if adapter['enable']:
|
||||
# index -= 1
|
||||
# if index == -1:
|
||||
# real_index = i
|
||||
# break
|
||||
|
||||
new_cfg = {
|
||||
'adapter': adapter_name,
|
||||
'enable': True,
|
||||
**config
|
||||
}
|
||||
self.ap.platform_cfg.data['platform-adapters'][real_index] = new_cfg
|
||||
await self.ap.platform_cfg.dump_config()
|
||||
# new_cfg = {
|
||||
# 'adapter': adapter_name,
|
||||
# 'enable': True,
|
||||
# **config
|
||||
# }
|
||||
# self.ap.platform_cfg.data['platform-adapters'][real_index] = new_cfg
|
||||
# await self.ap.platform_cfg.dump_config()
|
||||
|
||||
async def send(self, event: platform_events.MessageEvent, msg: platform_message.MessageChain, adapter: msadapter.MessagePlatformAdapter):
|
||||
|
||||
if self.ap.platform_cfg.data['at-sender'] and isinstance(event, platform_events.GroupMessage):
|
||||
|
||||
msg.insert(
|
||||
0,
|
||||
platform_message.At(
|
||||
event.sender.id
|
||||
)
|
||||
)
|
||||
|
||||
await adapter.reply_message(
|
||||
event,
|
||||
msg,
|
||||
quote_origin=True if self.ap.platform_cfg.data['quote-origin'] else False
|
||||
)
|
||||
# TODO implement this
|
||||
pass
|
||||
|
||||
async def run(self):
|
||||
# This method will only be called when the application launching
|
||||
@@ -270,4 +258,4 @@ class PlatformManager:
|
||||
for bot in self.bots:
|
||||
if bot.enable:
|
||||
await bot.shutdown()
|
||||
self.ap.task_mgr.cancel_by_scope(core_entities.LifecycleControlScope.PLATFORM)
|
||||
self.ap.task_mgr.cancel_by_scope(core_entities.LifecycleControlScope.PLATFORM)
|
||||
|
||||
@@ -238,4 +238,6 @@ class AiocqhttpAdapter(adapter.MessagePlatformAdapter):
|
||||
await self.bot._server_app.run_task(**self.config)
|
||||
|
||||
async def kill(self) -> bool:
|
||||
# Current issue: existing connection will not be closed
|
||||
# self.should_shutdown = True
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user