Skip to content

Commit

Permalink
支持 discord.channel
Browse files Browse the repository at this point in the history
  • Loading branch information
This-is-XiaoDeng committed Oct 15, 2023
1 parent 1f42f59 commit 480e016
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ def parse_message(message: list) -> dict:
)
if segment["type"] == "voice":
logger.warning("OneDisc 暂不支持 voice 消息段,将以 audio 消息段发送")
case "dc.emoji":
case "discord.emoji":
message_data[
"content"
] += f'<:{segment["data"]["name"]}:{segment["data"]["id"]}>'
case "discord.channel":
message_data["content"] += f"<#{segment['data']['channel_id']}>"
case "reply":
for msg in client.cached_messages:
if msg.id == int(segment["data"]["message_id"]):
Expand Down Expand Up @@ -88,6 +90,13 @@ def parse_string(string: str) -> list:
message.append({"type": "mention_all", "data": {}})
case "text":
message.append({"type": "text", "data": {"text": token[1]}})
case "channel":
message.append({
"type": "discord.channel",
"data": {
"channel_id": token[1][2:-1]
}
})
case "emoji":
message.append(
{
Expand Down
3 changes: 2 additions & 1 deletion message_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
('mention', '<@[0-9]+>'),
('mention_all', '@everyone'),
('emoji', '<:.+?:[0-9]+>'),
('text', '<(?![@:]).*?(?=<|$)|[^<@:]+') # 使用正向否定断言来匹配不后跟@或:的<
('channel', '<#[0-9]+>'),
('text', '<(?![@:#]).*?(?=<|$)|[^<@:#]+') # 使用正向否定断言来匹配不后跟@或:的<
]

def tokenizer(code):
Expand Down

0 comments on commit 480e016

Please sign in to comment.