(client-protocol): 补全解析得到的 附件 和 提及 缺失的文本字段
This commit is contained in:
@@ -11,16 +11,20 @@ import marked from 'marked'
|
|||||||
class ChatMention extends BaseClientObject {
|
class ChatMention extends BaseClientObject {
|
||||||
declare chat_id?: string
|
declare chat_id?: string
|
||||||
declare user_id?: string
|
declare user_id?: string
|
||||||
|
declare text?: string
|
||||||
constructor(client: LingChairClient, {
|
constructor(client: LingChairClient, {
|
||||||
user_id,
|
user_id,
|
||||||
chat_id,
|
chat_id,
|
||||||
|
text,
|
||||||
}: {
|
}: {
|
||||||
user_id?: string,
|
user_id?: string,
|
||||||
chat_id?: string,
|
chat_id?: string,
|
||||||
|
text: string,
|
||||||
}) {
|
}) {
|
||||||
super(client)
|
super(client)
|
||||||
this.user_id = user_id
|
this.user_id = user_id
|
||||||
this.chat_id = chat_id
|
this.chat_id = chat_id
|
||||||
|
this.text = text
|
||||||
}
|
}
|
||||||
async getChat() {
|
async getChat() {
|
||||||
return await Chat.getById(this.client, this.chat_id as string)
|
return await Chat.getById(this.client, this.chat_id as string)
|
||||||
@@ -28,6 +32,9 @@ class ChatMention extends BaseClientObject {
|
|||||||
async getUser() {
|
async getUser() {
|
||||||
return await User.getById(this.client, this.user_id as string)
|
return await User.getById(this.client, this.user_id as string)
|
||||||
}
|
}
|
||||||
|
getText() {
|
||||||
|
return this.text
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type FileType = 'Video' | 'Image' | 'File'
|
type FileType = 'Video' | 'Image' | 'File'
|
||||||
@@ -35,8 +42,16 @@ type MentionType = 'ChatMention' | 'UserMention'
|
|||||||
|
|
||||||
class ChatAttachment extends BaseClientObject {
|
class ChatAttachment extends BaseClientObject {
|
||||||
declare file_hash: string
|
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)
|
super(client)
|
||||||
|
this.file_name = file_name
|
||||||
this.file_hash = file_hash
|
this.file_hash = file_hash
|
||||||
}
|
}
|
||||||
async blob() {
|
async blob() {
|
||||||
@@ -59,6 +74,9 @@ class ChatAttachment extends BaseClientObject {
|
|||||||
getFileHash() {
|
getFileHash() {
|
||||||
return this.file_hash
|
return this.file_hash
|
||||||
}
|
}
|
||||||
|
getFileName() {
|
||||||
|
return this.file_name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Message extends BaseClientObject {
|
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)) {
|
if (fileType != null && /tws:\/\/file\?hash=[A-Za-z0-9]+$/.test(href)) {
|
||||||
const file_hash = /^tws:\/\/file\?hash=(.*)/.exec(href)?.[1]!
|
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)) {
|
if (mentionType != null && /^tws:\/\/chat\?id=[A-Za-z0-9]+/.test(href)) {
|
||||||
const id = /^tws:\/\/chat\?id=(.*)/.exec(href)?.[1]!
|
const id = /^tws:\/\/chat\?id=(.*)/.exec(href)?.[1]!
|
||||||
|
const label = /^(User|Chat)Mention=(.*)/.exec(text)?.[2] || ''
|
||||||
return mention ? mention({
|
return mention ? mention({
|
||||||
text: text,
|
text: text,
|
||||||
mention: new ChatMention(this.client, {
|
mention: new ChatMention(this.client, {
|
||||||
[({
|
[({
|
||||||
ChatMention: 'chat_id',
|
ChatMention: 'chat_id',
|
||||||
UserMention: 'user_id',
|
UserMention: 'user_id',
|
||||||
})[mentionType]]: id
|
})[mentionType]]: id,
|
||||||
|
text: label,
|
||||||
}),
|
}),
|
||||||
mentionType: mentionType,
|
mentionType: mentionType,
|
||||||
}) : text
|
}) : text
|
||||||
|
|||||||
Reference in New Issue
Block a user