Skip to content

Commit

Permalink
✨ version 0.31.4
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 4, 2023
1 parent 2ddf1e7 commit 8e84559
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .consts import log
from .config import Config
from .uniseg import At as At
from .uniseg import Card as Card
from .uniseg import File as File
from .uniseg import Text as Text
from .model import Match as Match
Expand All @@ -62,6 +63,7 @@
from .matcher import Command as Command
from .params import AlcResult as AlcResult
from .uniseg import MessageId as MessageId
from .uniseg import MsgTarget as MsgTarget
from .uniseg import Reference as Reference
from .argv import MessageArgv as MessageArgv
from .params import AlcMatches as AlcMatches
Expand All @@ -80,6 +82,7 @@
from .model import CommandResult as CommandResult
from .params import AlcExecResult as AlcExecResult
from .params import AlconnaResult as AlconnaResult
from .uniseg import MessageTarget as MessageTarget
from .consts import ALCONNA_RESULT as ALCONNA_RESULT
from .params import AlconnaMatches as AlconnaMatches
from .matcher import AlconnaMatcher as AlconnaMatcher
Expand All @@ -93,7 +96,7 @@
from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT
from .extension import add_global_extension as add_global_extension

__version__ = "0.31.3"
__version__ = "0.31.4"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
Expand Down
5 changes: 4 additions & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from nonebot.plugin import PluginMetadata

from .segment import At as At
from .segment import Card as Card
from .segment import File as File
from .segment import Text as Text
from .params import MsgId as MsgId
Expand All @@ -19,17 +20,19 @@
from .segment import RefNode as RefNode
from .segment import Segment as Segment
from .params import MessageId as MessageId
from .params import MsgTarget as MsgTarget
from .segment import Reference as Reference
from .message import UniMessage as UniMessage
from .segment import CustomNode as CustomNode
from .tools import image_fetch as image_fetch
from .params import MessageTarget as MessageTarget
from .export import SerializeFailed as SerializeFailed
from .fallback import FallbackMessage as FallbackMessage
from .fallback import FallbackSegment as FallbackSegment
from .params import UniversalMessage as UniversalMessage
from .params import UniversalSegment as UniversalSegment

__version__ = "0.31.3"
__version__ = "0.31.4"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
13 changes: 13 additions & 0 deletions src/nonebot_plugin_alconna/uniseg/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,19 @@ def get_message_id(event: Event, bot: Optional[Bot] = None) -> str:
return fn.get_message_id(event)
raise SerializeFailed(lang.require("nbp-uniseg", "unsupported").format(adapter=adapter_name))

@staticmethod
def get_target(event: Event, bot: Optional[Bot] = None) -> Target:
if not bot:
try:
bot = current_bot.get()
except LookupError as e:
raise SerializeFailed(lang.require("nbp-uniseg", "bot_missing")) from e
adapter = bot.adapter
adapter_name = adapter.get_name()
if fn := MAPPING.get(adapter_name):
return fn.get_target(event)
raise SerializeFailed(lang.require("nbp-uniseg", "unsupported").format(adapter=adapter_name))

async def export(self, bot: Optional[Bot] = None, fallback: bool = True) -> Message:
if not bot:
try:
Expand Down
10 changes: 10 additions & 0 deletions src/nonebot_plugin_alconna/uniseg/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
from nonebot.internal.params import Depends
from nonebot.internal.adapter import Bot, Event

from .export import Target
from .message import TS, UniMessage


async def _uni_msg(bot: Bot, event: Event) -> UniMessage:
return await UniMessage.generate(event=event, bot=bot)


def _target(bot: Bot, event: Event) -> Target:
return UniMessage.get_target(event=event, bot=bot)


def _msg_id(bot: Bot, event: Event) -> str:
return UniMessage.get_message_id(event=event, bot=bot)


def MessageTarget() -> Target:
return Depends(_target, use_cache=True)


def UniversalMessage() -> UniMessage:
return Depends(_uni_msg, use_cache=True)

Expand All @@ -32,3 +41,4 @@ async def _uni_seg(bot: Bot, event: Event) -> TS:

UniMsg = Annotated[UniMessage, UniversalMessage()]
MsgId = Annotated[str, MessageId()]
MsgTarget = Annotated[Target, MessageTarget()]

0 comments on commit 8e84559

Please sign in to comment.