mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
fix(botmgr): ref errors
This commit is contained in:
@@ -23,3 +23,18 @@ class AdaptersRouterGroup(group.RouterGroup):
|
||||
return self.success(data={
|
||||
'adapter': adapter_info
|
||||
})
|
||||
|
||||
@self.route('/<adapter_name>/icon', methods=['GET'])
|
||||
async def _(adapter_name: str) -> quart.Response:
|
||||
|
||||
adapter_manifest = self.ap.platform_mgr.get_available_adapter_manifest_by_name(adapter_name)
|
||||
|
||||
if adapter_manifest is None:
|
||||
return self.http_status(404, -1, 'adapter not found')
|
||||
|
||||
icon_path = adapter_manifest.icon_rel_path
|
||||
|
||||
if icon_path is None:
|
||||
return self.http_status(404, -1, 'icon not found')
|
||||
|
||||
return await quart.send_file(icon_path)
|
||||
@@ -16,7 +16,7 @@ class SystemRouterGroup(group.RouterGroup):
|
||||
data={
|
||||
"version": constants.semantic_version,
|
||||
"debug": constants.debug_mode,
|
||||
"enabled_platform_count": len(self.ap.platform_mgr.adapters)
|
||||
"enabled_platform_count": len(self.ap.platform_mgr.get_running_adapters())
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -118,11 +118,6 @@ class RuntimeBot:
|
||||
|
||||
# 控制QQ消息输入输出的类
|
||||
class PlatformManager:
|
||||
|
||||
# adapter: msadapter.MessageSourceAdapter = None
|
||||
adapters: list[msadapter.MessagePlatformAdapter] = [] # deprecated
|
||||
|
||||
message_platform_adapter_components: list[engine.Component] = [] # deprecated
|
||||
|
||||
# ====== 4.0 ======
|
||||
ap: app.Application = None
|
||||
@@ -136,7 +131,6 @@ class PlatformManager:
|
||||
def __init__(self, ap: app.Application = None):
|
||||
|
||||
self.ap = ap
|
||||
self.adapters = []
|
||||
self.bots = []
|
||||
self.adapter_components = []
|
||||
self.adapter_dict = {}
|
||||
@@ -151,6 +145,9 @@ class PlatformManager:
|
||||
|
||||
await self.load_bots_from_db()
|
||||
|
||||
def get_running_adapters(self) -> list[msadapter.MessagePlatformAdapter]:
|
||||
return [bot.adapter for bot in self.bots if bot.enable]
|
||||
|
||||
async def load_bots_from_db(self):
|
||||
self.ap.logger.info('Loading bots from db...')
|
||||
|
||||
@@ -207,14 +204,20 @@ class PlatformManager:
|
||||
def get_available_adapters_info(self) -> list[dict]:
|
||||
return [
|
||||
component.to_plain_dict()
|
||||
for component in self.message_platform_adapter_components
|
||||
for component in self.adapter_components
|
||||
]
|
||||
|
||||
def get_available_adapter_info_by_name(self, name: str) -> dict | None:
|
||||
for component in self.message_platform_adapter_components:
|
||||
for component in self.adapter_components:
|
||||
if component.metadata.name == name:
|
||||
return component.to_plain_dict()
|
||||
return None
|
||||
|
||||
def get_available_adapter_manifest_by_name(self, name: str) -> engine.Component | None:
|
||||
for component in self.adapter_components:
|
||||
if component.metadata.name == name:
|
||||
return component
|
||||
return None
|
||||
|
||||
async def write_back_config(self, adapter_name: str, adapter_inst: msadapter.MessagePlatformAdapter, config: dict):
|
||||
# index = -2
|
||||
|
||||
@@ -127,7 +127,7 @@ class APIHost:
|
||||
Returns:
|
||||
list[platform.adapter.MessageSourceAdapter]: 已启用的消息平台适配器列表
|
||||
"""
|
||||
return self.ap.platform_mgr.adapters
|
||||
return self.ap.platform_mgr.get_running_adapters()
|
||||
|
||||
async def send_active_message(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user