Skip to content

Commit 6581f3e

Browse files
committed
feat(album): 支持 LLBot 群相册接口
1 parent d36bf49 commit 6581f3e

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/infrastructure/platform/adapters/onebot_adapter.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,30 @@ def __init__(self, bot_instance: Any, config: dict | None = None):
6262
if not self.bot_self_ids and config:
6363
self.bot_self_ids = [str(id) for id in config.get("bot_qq_ids", [])]
6464

65+
# LLBot 探测标志
66+
self._is_llbot = False
67+
self._llbot_checked = False
68+
6569
def _init_capabilities(self) -> PlatformCapabilities:
6670
"""返回预定义的 OneBot v11 能力集。"""
6771
return ONEBOT_V11_CAPABILITIES
6872

73+
async def _detect_llbot(self):
74+
"""探测是否为 LLBot"""
75+
if self._llbot_checked:
76+
return
77+
try:
78+
# 避免在一些不支持 get_version_info 的老版本上卡死
79+
result = await self.bot.call_action("get_version_info")
80+
if isinstance(result, dict):
81+
app_name = result.get("app_name", "")
82+
self._is_llbot = app_name == "LLOneBot"
83+
if self._is_llbot:
84+
logger.info("[OneBot] 探测到当前协议端为 LLBot")
85+
except Exception:
86+
self._is_llbot = False
87+
self._llbot_checked = True
88+
6989
def _get_nearest_size(self, requested_size: int) -> int:
7090
"""从支持的尺寸列表中找到最接近请求尺寸的一个。"""
7191
return min(self.AVAILABLE_SIZES, key=lambda x: abs(x - requested_size))
@@ -959,6 +979,27 @@ async def upload_group_album(
959979
return False
960980

961981
async def do_upload(content: str, label: str):
982+
await self._detect_llbot()
983+
984+
if self._is_llbot:
985+
# LLBot 模式:使用 files 参数 (列表)
986+
# 根据参考插件,LLBot 的 upload_group_album 接收 files 作为数组
987+
llbot_params = {
988+
"group_id": int(group_id),
989+
"album_id": str(album_id),
990+
"files": [content],
991+
}
992+
try:
993+
await self.bot.call_action("upload_group_album", **llbot_params)
994+
logger.debug(
995+
f"[群分析相册] 上传成功 (LLBot, {label}): 群 {group_id}"
996+
)
997+
return
998+
except Exception as e:
999+
logger.warning(
1000+
f"[群分析相册] LLBot 上传接口调用失败: {e},尝试 NapCat 模式..."
1001+
)
1002+
9621003
params = {
9631004
"group_id": int(group_id),
9641005
"file": content,

0 commit comments

Comments
 (0)