Skip to content

Commit

Permalink
✨ version 0.31.5
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Nov 4, 2023
1 parent 3534434 commit 2611d69
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,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.4"
__version__ = "0.31.5"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
Expand Down
18 changes: 12 additions & 6 deletions src/nonebot_plugin_alconna/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ def _decorator(func: T_Handler) -> T_Handler:
if TYPE_CHECKING:

@classmethod
def set_path_arg(cls_or_self, path: str, content: Any) -> None:
def set_path_arg(cls_or_self, path: str, content: Any) -> None: # type: ignore
...

@classmethod
def get_path_arg(self, path: str, default: Any) -> Any:
def get_path_arg(cls_or_self, path: str, default: Any) -> Any: # type: ignore
...

else:
Expand Down Expand Up @@ -376,11 +376,17 @@ def convert(cls, message: _M) -> Message | UniMessage | str:
event = current_event.get()
state = current_matcher.get().state
if isinstance(message, MessageTemplate):
return message.format(**state, **state[ALCONNA_RESULT].result.all_matched_args)
return message.format(**state[ALCONNA_RESULT].result.all_matched_args, **state)
if isinstance(message, UniMessageTemplate):
return message.format(
**state, **state[ALCONNA_RESULT].result.all_matched_args, **{"$event": event, "$bot": bot}
)
extra = {"$event": event, "$bot": bot}
extra["$target"] = UniMessage.get_target(event, bot)
try:
msg_id = UniMessage.get_message_id(event, bot)
except Exception:
pass
else:
extra["$message_id"] = msg_id
return message.format(**state[ALCONNA_RESULT].result.all_matched_args, **state, **extra)
if isinstance(message, Segment):
return UniMessage(message)
if isinstance(message, MessageSegment):
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from .params import UniversalMessage as UniversalMessage
from .params import UniversalSegment as UniversalSegment

__version__ = "0.31.4"
__version__ = "0.31.5"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _vformat(
def format_field(self, value: Any, format_spec: str) -> Any:
formatter: Optional[FormatSpecFunc] = self.format_specs.get(format_spec)
if formatter is None and format_spec in _MAPPING:
formatter = _MAPPING[format_spec]
formatter = _MAPPING[format_spec] # type: ignore
return super().format_field(value, format_spec) if formatter is None else formatter(value)

def _add(self, a: Any, b: Any) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_uniseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ async def test_unimsg_template(app: App):

@matcher.handle()
async def handle():
await matcher.finish(UniMessage.template("{:At(user, $event.get_user_id())}"))
await matcher.finish(UniMessage.template("{:Reply($message_id)}{:At(user, $event.get_user_id())}"))

async with app.test_matcher(matcher) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter)
event = fake_group_message_event_v11(message=Message("test_unimsg_template"), user_id=123)
ctx.receive_event(bot, event)
ctx.should_call_send(event, Message(MessageSegment.at(123)))
ctx.should_call_send(event, MessageSegment.reply(1) + MessageSegment.at(123))
ctx.should_finished(matcher)


Expand Down

0 comments on commit 2611d69

Please sign in to comment.