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.0.292 → v0.1.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.292...v0.1.9) - [github.com/pycqa/isort: 5.12.0 → 5.13.2](https://github.com/pycqa/isort/compare/5.12.0...5.13.2) - [github.com/psf/black: 23.9.1 → 23.12.1](https://github.com/psf/black/compare/23.9.1...23.12.1) - [github.com/pre-commit/mirrors-prettier: v3.0.3 → v4.0.0-alpha.8](https://github.com/pre-commit/mirrors-prettier/compare/v3.0.3...v4.0.0-alpha.8) - [github.com/pre-commit/mirrors-eslint: v8.50.0 → v9.0.0-alpha.0](https://github.com/pre-commit/mirrors-eslint/compare/v8.50.0...v9.0.0-alpha.0) * 💄 auto fix by pre-commit hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
35 lines
966 B
Python
35 lines
966 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())
|