Skip to content

Commit

Permalink
✨ escape & unescape in echo
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Jan 10, 2025
1 parent d6c74ba commit 33a68b3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
28 changes: 14 additions & 14 deletions arclet/entari/builtins/echo.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
2 changes: 1 addition & 1 deletion arclet/entari/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion arclet/entari/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))

0 comments on commit 33a68b3

Please sign in to comment.