Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持选择特定 Bot 的 PlatformTarget #116

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion nonebot_plugin_saa/auto_select_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import asyncio
from typing import Set, Dict, List, Callable, Awaitable

import nonebot
from nonebot.adapters import Bot
from nonebot import logger, get_bots

from .registries import PlatformTarget, TargetQQGuildDirect
from .utils import NoBotFound, SupportedAdapters, extract_adapter_type
from .registries import BotSpecifier, PlatformTarget, TargetQQGuildDirect

BOT_CACHE: Dict[Bot, Set[PlatformTarget]] = {}
BOT_CACHE_LOCK = asyncio.Lock()
Expand Down Expand Up @@ -98,6 +99,9 @@
"\n参见:https://send-anything-anywhere.felinae98.cn/usage/send#发送时自动选择bot"
)

if isinstance(target, BotSpecifier):
return nonebot.get_bot(target.bot_id)

Check warning on line 103 in nonebot_plugin_saa/auto_select_bot.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_saa/auto_select_bot.py#L103

Added line #L103 was not covered by tests

# TODO: 通过更方便的方式判断当前 Target 是否支持
if isinstance(target, TargetQQGuildDirect):
raise NotImplementedError("暂不支持私聊")
Expand Down
1 change: 1 addition & 0 deletions nonebot_plugin_saa/registries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .platform_send_target import SaaTarget as SaaTarget
from .platform_send_target import get_target as get_target
from .platform_send_target import sender_map as sender_map
from .platform_send_target import BotSpecifier as BotSpecifier
from .platform_send_target import TargetQQGroup as TargetQQGroup
from .platform_send_target import PlatformTarget as PlatformTarget
from .platform_send_target import extract_target as extract_target
Expand Down
5 changes: 5 additions & 0 deletions nonebot_plugin_saa/registries/platform_send_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Awaitable,
)

from pydantic import BaseModel
from nonebot.params import Depends
from nonebot.adapters import Bot, Event

Expand Down Expand Up @@ -42,6 +43,10 @@ def arg_dict(self, bot: Bot):
return convert_to_arg_map[(self.platform_type, adapter_type)](self)


class BotSpecifier(BaseModel):
bot_id: str


class TargetQQGroup(PlatformTarget):
"""QQ群

Expand Down