From d486c9df79014c01ba1ff5322ad5ae65bd288276 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 29 Nov 2025 00:05:05 +0800 Subject: [PATCH] =?UTF-8?q?(client-protocol):=20=E8=A1=A5=E5=85=A8?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=BE=97=E5=88=B0=E7=9A=84=20=E9=99=84?= =?UTF-8?q?=E4=BB=B6=20=E5=92=8C=20=E6=8F=90=E5=8F=8A=20=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E6=96=87=E6=9C=AC=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client-protocol/Message.ts | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/client-protocol/Message.ts b/client-protocol/Message.ts index 336e147..205475c 100644 --- a/client-protocol/Message.ts +++ b/client-protocol/Message.ts @@ -11,16 +11,20 @@ import marked from 'marked' class ChatMention extends BaseClientObject { declare chat_id?: string declare user_id?: string + declare text?: string constructor(client: LingChairClient, { user_id, chat_id, + text, }: { user_id?: string, chat_id?: string, + text: string, }) { super(client) this.user_id = user_id this.chat_id = chat_id + this.text = text } async getChat() { return await Chat.getById(this.client, this.chat_id as string) @@ -28,6 +32,9 @@ class ChatMention extends BaseClientObject { async getUser() { return await User.getById(this.client, this.user_id as string) } + getText() { + return this.text + } } type FileType = 'Video' | 'Image' | 'File' @@ -35,8 +42,16 @@ type MentionType = 'ChatMention' | 'UserMention' class ChatAttachment extends BaseClientObject { declare file_hash: string - constructor(client: LingChairClient, file_hash: string) { + declare file_name: string + constructor(client: LingChairClient, { + file_hash, + file_name + }: { + file_hash: string, + file_name: string + }) { super(client) + this.file_name = file_name this.file_hash = file_hash } async blob() { @@ -59,6 +74,9 @@ class ChatAttachment extends BaseClientObject { getFileHash() { return this.file_hash } + getFileName() { + return this.file_name + } } export default class Message extends BaseClientObject { @@ -102,17 +120,21 @@ export default class Message extends BaseClientObject { if (fileType != null && /tws:\/\/file\?hash=[A-Za-z0-9]+$/.test(href)) { const file_hash = /^tws:\/\/file\?hash=(.*)/.exec(href)?.[1]! - return attachment ? attachment({ text: text, attachment: new ChatAttachment(this.client, file_hash), fileType: fileType, }) : text + let file_name: string = /^Video|File|Image=(.*)/.exec(text)?.[1] || text + file_name.trim() == '' && (file_name = 'Unnamed File') + return attachment ? attachment({ text: text, attachment: new ChatAttachment(this.client, { file_hash, file_name }), fileType: fileType, }) : text } if (mentionType != null && /^tws:\/\/chat\?id=[A-Za-z0-9]+/.test(href)) { const id = /^tws:\/\/chat\?id=(.*)/.exec(href)?.[1]! + const label = /^(User|Chat)Mention=(.*)/.exec(text)?.[2] || '' return mention ? mention({ text: text, mention: new ChatMention(this.client, { [({ ChatMention: 'chat_id', UserMention: 'user_id', - })[mentionType]]: id + })[mentionType]]: id, + text: label, }), mentionType: mentionType, }) : text