Skip to content

Commit

Permalink
🐛 version 0.30.5
Browse files Browse the repository at this point in the history
fxxk pydantic
  • Loading branch information
RF-Tar-Railt committed Oct 26, 2023
1 parent 4d03cbe commit a821473
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 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 @@ -89,7 +89,7 @@
from .consts import ALCONNA_EXEC_RESULT as ALCONNA_EXEC_RESULT
from .extension import add_global_extension as add_global_extension

__version__ = "0.30.4"
__version__ = "0.30.5"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
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 @@ -24,7 +24,7 @@
from .params import UniversalMessage as UniversalMessage
from .params import UniversalSegment as UniversalSegment

__version__ = "0.30.4"
__version__ = "0.30.5"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
15 changes: 10 additions & 5 deletions src/nonebot_plugin_alconna/uniseg/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from base64 import b64decode
from datetime import datetime
from typing_extensions import NotRequired
from typing_extensions import NotRequired, TypedDict
from dataclasses import field, asdict, dataclass
from typing import (
TYPE_CHECKING,
Expand All @@ -21,7 +21,6 @@
Callable,
Iterable,
Optional,
TypedDict,
overload,
)

Expand Down Expand Up @@ -60,16 +59,19 @@ def solve(self, seg: MessageSegment) -> Optional[TS]:
raise NotImplementedError


@dataclass
class Segment:
"""基类标注"""

if TYPE_CHECKING:
origin: MessageSegment = field(init=False, repr=False, compare=False)
origin: MessageSegment # = field(init=False, repr=False, compare=False)

def __str__(self):
return f"[{self.__class__.__name__.lower()}]"

def __repr__(self):
attrs = ", ".join(f"{k}={v!r}" for k, v in self.data.items())
return f"{self.__class__.__name__}({attrs})"

@overload
def __add__(self: TS, item: str) -> "UniMessage[Union[TS, Text]]":
...
Expand Down Expand Up @@ -113,7 +115,10 @@ def type(self) -> str:

@property
def data(self) -> Dict[str, Any]:
return asdict(self)
try:
return asdict(self) # type: ignore
except TypeError:
return vars(self)


@dataclass
Expand Down
8 changes: 5 additions & 3 deletions tests/fake.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ class FakeEvent(_Fake):
user: User = User(id="1", name="test")
message: InnerMessage = InnerMessage(id="1", content=[Element(type="text", attrs={"text": "test"})])
to_me: bool = False
_message = field.pop("message", Message("test"))

class Config:
extra = "forbid"
extra = "allow"

return FakeEvent(**field)
_message = field.pop("message", Message("test"))
event = FakeEvent(**field)
event._message = _message
return event


def fake_message_event_guild(**field) -> "MessageCreateEvent":
Expand Down
11 changes: 6 additions & 5 deletions tests/test_satori.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebug import App
from nonebot import get_adapter
from arclet.alconna import Args, Alconna
from nonebot.adapters.satori import Bot, Adapter, Message
from nonebot.adapters.satori import Bot, Adapter, Message, MessageSegment

from tests.fake import fake_message_event_satori

Expand Down Expand Up @@ -37,15 +37,16 @@ def test_satori():
async def test_send(app: App):
from nonebot_plugin_alconna import Text, Image, on_alconna

test_cmd = on_alconna(Alconna("test"))
test_cmd = on_alconna(Alconna("test", Args["img", Image]))

@test_cmd.handle()
async def tt_h():
await test_cmd.send(Text("ok\n") + Image(raw={"data": b"123", "mimetype": "image/png"}))
async def tt_h(img: Image):
await test_cmd.send(Text("ok\n") + img)

async with app.test_matcher(test_cmd) as ctx:
adapter = get_adapter(Adapter)
bot = ctx.create_bot(base=Bot, adapter=adapter, platform="satori", info=None)
event = fake_message_event_satori(message=Message("test"), id=123)
msg = "test" + MessageSegment.image(raw={"data": b"123", "mime": "image/png"})
event = fake_message_event_satori(message=msg, id=123)
ctx.receive_event(bot, event)
ctx.should_call_send(event, Message('ok\n<img src="data:image/png;base64,MTIz" />'))

0 comments on commit a821473

Please sign in to comment.