diff --git a/arclet/entari/builtins/echo.py b/arclet/entari/builtins/echo.py index b9925e5..235ae9c 100644 --- a/arclet/entari/builtins/echo.py +++ b/arclet/entari/builtins/echo.py @@ -1,6 +1,6 @@ -from arclet.alconna import Alconna, AllParam, Args, CommandMeta +from arclet.alconna import Arparma -from arclet.entari import MessageChain, Session, command, metadata +from arclet.entari import MessageChain, command, metadata from arclet.entari.command import Match metadata( @@ -10,16 +10,16 @@ ) -cmd = command.mount(Alconna("echo", Args["content?", AllParam], meta=CommandMeta("显示消息", compact=True))) - - -@cmd.handle -async def echo_handle(content: Match[MessageChain], session: Session): - if content.available: - return await session.send(content.result) - - -@cmd.on_execute() -async def echo_exec(content: Match[MessageChain]): - if content.available: +@( + command.command("echo <...content>", "显示消息") + .option("escape", "-e|--escape # 发送转义消息") + .option("unescape", "-E|--unescape # 发送反转义消息") + .config(compact=True) +) +def echo(content: Match[MessageChain], arp: Arparma): + if arp.find("unescape"): + return MessageChain.of(content.result.extract_plain_text()) + elif arp.find("escape"): + return str(content.result) + else: return content.result diff --git a/arclet/entari/command/__init__.py b/arclet/entari/command/__init__.py index bee6e31..94e49b5 100644 --- a/arclet/entari/command/__init__.py +++ b/arclet/entari/command/__init__.py @@ -24,7 +24,7 @@ from .plugin import mount from .provider import AlconnaProviderFactory, AlconnaSuppiler, MessageJudges -TM = TypeVar("TM", str, MessageChain) +TM = TypeVar("TM", bound=Union[str, MessageChain]) def get_cmd(target: Subscriber): diff --git a/arclet/entari/message.py b/arclet/entari/message.py index 553e099..d0e7f72 100644 --- a/arclet/entari/message.py +++ b/arclet/entari/message.py @@ -6,7 +6,8 @@ from typing_extensions import Self, SupportsIndex, TypeAlias from satori import select as satori_select -from satori.element import At, Element, Link, Sharp, Style, Text +from satori.element import At, Element, Link, Sharp, Style, Text, transform +from satori.parser import parse T = TypeVar("T") TE = TypeVar("TE", bound=Element) @@ -615,3 +616,7 @@ def display(self): return "".join( str(elem) if isinstance(elem, (Text, Style, At, Sharp, Link)) else elem.__class__.__name__ for elem in self ) + + @staticmethod + def of(text: str): + return MessageChain(transform(parse(text)))