Add HeXi bot codebase: custom plugins, web frontends, tests
- hexi core: message handling, rate limiting, cooldown, plugin manager - Custom plugins: BF stats, daily check-in, quotes, persona cards, etc. - Community plugins vendored under hexi/plugins with local fixes - Web admin frontends (learning-chat, persona-admin), unified hexi/web - Tests for rate_limit/cooldown/memes/persona; poetry.lock Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
"""NoneBot 版 BotManager:管理 OneBot 适配器实例。"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
|
||||
class BotManager:
|
||||
def __init__(self):
|
||||
self._adapters: dict[str, Any] = {}
|
||||
|
||||
def register_adapter(self, adapter: Any, platform_id: str | None = None) -> None:
|
||||
pid = platform_id or getattr(adapter, "platform_id", "onebot") or "onebot"
|
||||
self._adapters[str(pid)] = adapter
|
||||
|
||||
def set_bot_instance(self, bot_instance: Any, platform_id: str | None = None) -> None:
|
||||
"""兼容接口:按平台登记一个适配器。"""
|
||||
pid = platform_id or "onebot"
|
||||
from .adapter import OneBotAdapter
|
||||
self.register_adapter(OneBotAdapter(bot_instance, {"platform_id": pid}), pid)
|
||||
|
||||
def get_adapter(self, platform_id: str | None = None) -> Any | None:
|
||||
if not self._adapters:
|
||||
return None
|
||||
if platform_id and str(platform_id) in self._adapters:
|
||||
return self._adapters[str(platform_id)]
|
||||
return next(iter(self._adapters.values()))
|
||||
|
||||
def get_adapter_platform_id(self, adapter: Any) -> str:
|
||||
return str(getattr(adapter, "platform_id", "onebot"))
|
||||
|
||||
def get_platform_ids(self) -> list[str]:
|
||||
return list(self._adapters.keys())
|
||||
|
||||
def get_platform_count(self) -> int:
|
||||
return len(self._adapters)
|
||||
Reference in New Issue
Block a user