Skip to content

Commit

Permalink
🐛 修复 event 文本获取错误 #19 (#26)
Browse files Browse the repository at this point in the history
* 🐛 修复 event 文本获取错误 #19

* 🐛 修改 `Message._construct()` 的正则
  • Loading branch information
Autuamn authored May 8, 2024
1 parent 0251686 commit 50e608a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nonebot/adapters/discord/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
SnowflakeType,
TimeStampStyle,
)
from .utils import escape, unescape
from .utils import unescape


class MessageSegment(BaseMessageSegment["Message"]):
Expand Down Expand Up @@ -319,7 +319,7 @@ class TextSegment(MessageSegment):

@override
def __str__(self) -> str:
return escape(self.data["text"])
return self.data["text"]


class EmbedData(TypedDict):
Expand Down Expand Up @@ -395,7 +395,7 @@ def __radd__(
def _construct(msg: str) -> Iterable[MessageSegment]:
text_begin = 0
for embed in re.finditer(
r"<(?P<type>(@!|@&|@|#|/|:|a:|t:))?(?P<param>.+?)>",
r"<(?P<type>(@!|@&|@|#|/|:|a:|t:))(?P<param>[^<]+?)>",
msg,
):
if content := msg[text_begin : embed.pos + embed.start()]:
Expand Down Expand Up @@ -436,7 +436,7 @@ def from_guild_message(cls, message: MessageGet) -> "Message":
if message.mention_everyone:
msg.append(MessageSegment.mention_everyone())
if message.content:
msg.append(MessageSegment.text(message.content))
msg.extend(Message(message.content))
if message.attachments:
msg.extend(
MessageSegment.attachment(
Expand Down

0 comments on commit 50e608a

Please sign in to comment.