Skip to content

Commit

Permalink
🔖 version 0.31.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Oct 29, 2023
1 parent dac51b4 commit 27310fa
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .uniseg import UniMsg as UniMsg
from .uniseg import RefNode as RefNode
from .uniseg import Segment as Segment
from .uniseg import get_bot as get_bot
from .matcher import Command as Command
from .params import AlcResult as AlcResult
from .uniseg import Reference as Reference
Expand Down Expand Up @@ -90,7 +91,7 @@
from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT
from .extension import add_global_extension as add_global_extension

__version__ = "0.30.8"
__version__ = "0.31.0"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
Expand Down
3 changes: 2 additions & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .const import log # noqa: F401
from .export import Target as Target
from .params import UniMsg as UniMsg
from .tools import get_bot as get_bot
from .segment import RefNode as RefNode
from .segment import Segment as Segment
from .segment import Reference as Reference
Expand All @@ -26,7 +27,7 @@
from .params import UniversalMessage as UniversalMessage
from .params import UniversalSegment as UniversalSegment

__version__ = "0.30.8"
__version__ = "0.31.0"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
39 changes: 36 additions & 3 deletions src/nonebot_plugin_alconna/uniseg/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from base64 import b64decode
from typing import TYPE_CHECKING, List, Type, Union, Optional, overload
from typing import TYPE_CHECKING, List, Type, Union, Literal, Optional, overload

from yarl import URL
from nonebot import get_bots
Expand Down Expand Up @@ -65,7 +66,12 @@ async def image_fetch(event: Event, bot: Bot, state: T_State, img: Image):


@overload
def get_bot(*, adapter: Union[Type[Adapter], str]) -> List[Bot]:
def get_bot(*, index: int) -> Bot:
...


@overload
def get_bot(*, rand: Literal[True]) -> Bot:
...


Expand All @@ -74,15 +80,38 @@ def get_bot(*, bot_id: str) -> Bot:
...


@overload
def get_bot(*, adapter: Union[Type[Adapter], str]) -> List[Bot]:
...


@overload
def get_bot(*, adapter: Union[Type[Adapter], str], index: int) -> Bot:
...


@overload
def get_bot(*, adapter: Union[Type[Adapter], str], rand: Literal[True]) -> Bot:
...


@overload
def get_bot(*, adapter: Union[Type[Adapter], str], bot_id: str) -> Bot:
...


def get_bot(
*, adapter: Union[Type[Adapter], str, None] = None, bot_id: Optional[str] = None
*,
adapter: Union[Type[Adapter], str, None] = None,
bot_id: Optional[str] = None,
index: Optional[int] = None,
rand: bool = False,
) -> Union[List[Bot], Bot]:
if not adapter:
if rand:
return random.choice(list(get_bots().values()))
if index is not None:
return list(get_bots().values())[index]
return _get_bot(bot_id)
bots = []
for bot in get_bots().values():
Expand All @@ -93,5 +122,9 @@ def get_bot(
elif isinstance(_adapter, adapter):
bots.append(bot)
if not bot_id:
if rand:
return random.choice(bots)
if index is not None:
return bots[index]
return bots
return next(bot for bot in bots if bot.self_id == bot_id)

0 comments on commit 27310fa

Please sign in to comment.