mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
* ⬆️ auto update by pre-commit hooks updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.9 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.9...v0.2.0) - [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1) - [github.com/pre-commit/mirrors-eslint: v9.0.0-alpha.0 → v9.0.0-alpha.2](https://github.com/pre-commit/mirrors-eslint/compare/v9.0.0-alpha.0...v9.0.0-alpha.2) * 💄 auto fix by pre-commit hooks * 💄 auto fix by pre-commit hooks * 🐛 fix some merge error --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Azide <rukuy@qq.com>
35 lines
964 B
Python
35 lines
964 B
Python
"""提供获取 Bot 的方法"""
|
|
|
|
from typing import Any
|
|
from collections import defaultdict
|
|
|
|
import nonebot
|
|
from nonebot.adapters import Bot
|
|
from nonebot_plugin_saa import PlatformTarget
|
|
from nonebot.adapters.onebot.v11 import Bot as Ob11Bot
|
|
|
|
GROUP: dict[int, list[Bot]] = {}
|
|
USER: dict[int, list[Bot]] = {}
|
|
BOT_CACHE: dict[PlatformTarget, list[Bot]] = defaultdict(list)
|
|
|
|
|
|
def get_bots() -> list[Bot]:
|
|
"""获取所有 OneBot 11 Bot"""
|
|
# TODO: support ob12
|
|
bots = []
|
|
for bot in nonebot.get_bots().values():
|
|
if isinstance(bot, Ob11Bot):
|
|
bots.append(bot)
|
|
return bots
|
|
|
|
|
|
async def get_groups() -> list[dict[str, Any]]:
|
|
"""获取所有群号"""
|
|
# TODO
|
|
all_groups: dict[int, dict[str, Any]] = {}
|
|
for bot in get_bots():
|
|
groups = await bot.get_group_list()
|
|
all_groups.update({group["group_id"]: group for group in groups if group["group_id"] not in all_groups})
|
|
|
|
return list(all_groups.values())
|