From ed2f554d4e12dfd87fc6fa384800d9280ffe6edd Mon Sep 17 00:00:00 2001 From: idranme Date: Sat, 28 Sep 2024 21:54:25 +0800 Subject: [PATCH] refactor --- src/main/main.ts | 4 +- src/main/store.ts | 33 ++- src/ntqqapi/core.ts | 52 ++-- src/ntqqapi/entities.ts | 4 +- src/ntqqapi/types/notify.ts | 18 +- .../action/go-cqhttp/UploadGroupFile.ts | 4 +- .../action/go-cqhttp/UploadPrivateFile.ts | 4 +- src/onebot11/action/msg/GetMsg.ts | 2 +- src/onebot11/action/types.ts | 2 +- src/onebot11/adapter.ts | 245 +++++++----------- src/onebot11/entities.ts | 1 - src/onebot11/helper/createMessage.ts | 34 +-- 12 files changed, 195 insertions(+), 208 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index 5ce2a50..6079a29 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -191,7 +191,9 @@ function onLoad() { ctx.plugin(SQLiteDriver, { path: path.join(dbDir, `${selfInfo.uin}.db`) }) - ctx.plugin(Store) + ctx.plugin(Store, { + msgCacheExpire: config.msgCacheExpire! * 1000 + }) ctx.start() ipcMain.on(CHANNEL_SET_CONFIG_CONFIRMED, (event, config: LLOBConfig) => { ctx.parallel('llonebot/config-updated', config) diff --git a/src/main/store.ts b/src/main/store.ts index 3b1a6ee..aa8d7c9 100644 --- a/src/main/store.ts +++ b/src/main/store.ts @@ -1,4 +1,4 @@ -import { Peer } from '@/ntqqapi/types' +import { Peer, RawMessage } from '@/ntqqapi/types' import { createHash } from 'node:crypto' import { LimitedHashTable } from '@/common/utils/table' import { FileCacheV2 } from '@/common/types' @@ -24,13 +24,15 @@ interface MsgInfo { peer: Peer } -export default class Store extends Service { +class Store extends Service { static inject = ['database', 'model'] private cache: LimitedHashTable + private messages: Map - constructor(protected ctx: Context) { + constructor(protected ctx: Context, public config: Store.Config) { super(ctx, 'store', true) this.cache = new LimitedHashTable(1000) + this.messages = new Map() this.initDatabase() } @@ -123,4 +125,29 @@ export default class Store extends Service { getFileCacheById(fileUuid: string) { return this.ctx.database.get('file_v2', { fileUuid }) } + + async addMsgCache(msg: RawMessage) { + const expire = this.config.msgCacheExpire + if (expire === 0) { + return + } + const id = msg.msgId + this.messages.set(id, msg) + setTimeout(() => { + this.messages.delete(id) + }, expire) + } + + getMsgCache(msgId: string) { + return this.messages.get(msgId) + } } + +namespace Store { + export interface Config { + /** 单位为毫秒 */ + msgCacheExpire: number + } +} + +export default Store diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index 4a703f7..a5496fa 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -2,7 +2,6 @@ import { unlink } from 'node:fs/promises' import { Service, Context } from 'cordis' import { registerCallHook, registerReceiveHook, ReceiveCmdS } from './hook' import { Config as LLOBConfig } from '../common/types' -import { llonebotError } from '../common/globalVars' import { isNumeric } from '../common/utils/misc' import { NTMethod } from './ntcall' import { @@ -13,7 +12,8 @@ import { GroupMember, CategoryFriend, SimpleInfo, - ChatType + ChatType, + BuddyReqType } from './types' import { selfInfo } from '../common/globalVars' import { version } from '../version' @@ -24,25 +24,26 @@ declare module 'cordis' { app: Core } interface Events { - 'nt/message-created': (input: RawMessage[]) => void + 'nt/message-created': (input: RawMessage) => void 'nt/message-deleted': (input: RawMessage) => void 'nt/message-sent': (input: RawMessage) => void - 'nt/group-notify': (input: GroupNotify[]) => void - 'nt/friend-request': (input: FriendRequest[]) => void + 'nt/group-notify': (input: GroupNotify) => void + 'nt/friend-request': (input: FriendRequest) => void 'nt/group-member-info-updated': (input: { groupCode: string, members: GroupMember[] }) => void 'nt/system-message-created': (input: Uint8Array) => void } } class Core extends Service { - static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi'] + static inject = ['ntMsgApi', 'ntFriendApi', 'ntGroupApi', 'store'] + public startTime = 0 constructor(protected ctx: Context, public config: Core.Config) { super(ctx, 'app', true) } public start() { - llonebotError.otherError = '' + this.startTime = Date.now() this.registerListener() this.ctx.logger.info(`LLOneBot/${version}`) this.ctx.on('llonebot/config-updated', input => { @@ -121,7 +122,7 @@ class Core extends Service { this.ctx.ntMsgApi.getMsgHistory(peer, '', 20).then(({ msgList }) => { const lastTempMsg = msgList.at(-1) if (Date.now() / 1000 - Number(lastTempMsg?.msgTime) < 5) { - this.ctx.parallel('nt/message-created', [lastTempMsg!]) + this.ctx.parallel('nt/message-created', lastTempMsg!) } }) }) @@ -161,7 +162,16 @@ class Core extends Service { }) registerReceiveHook<{ msgList: RawMessage[] }>([ReceiveCmdS.NEW_MSG, ReceiveCmdS.NEW_ACTIVE_MSG], payload => { - this.ctx.parallel('nt/message-created', payload.msgList) + for (const message of payload.msgList) { + // 过滤启动之前的消息 + if (parseInt(message.msgTime) < this.startTime / 1000) { + continue + } + if (message.senderUin && message.senderUin !== '0') { + this.ctx.store.addMsgCache(message) + } + this.ctx.parallel('nt/message-created', message) + } }) const sentMsgIds = new Map() @@ -199,20 +209,28 @@ class Core extends Service { } catch (e) { return } - const list = notifies.filter(v => { - const flag = v.group.groupCode + '|' + v.seq + '|' + v.type - if (groupNotifyFlags.includes(flag)) { - return false + for (const notify of notifies) { + const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type + const notifyTime = parseInt(notify.seq) / 1000 + if (groupNotifyFlags.includes(flag) || notifyTime < this.startTime) { + continue } groupNotifyFlags.push(flag) - return true - }) - this.ctx.parallel('nt/group-notify', list) + this.ctx.parallel('nt/group-notify', notify) + } } }) registerReceiveHook(ReceiveCmdS.FRIEND_REQUEST, payload => { - this.ctx.parallel('nt/friend-request', payload.data.buddyReqs) + for (const req of payload.data.buddyReqs) { + if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.MeInitiatorWaitPeerConfirm)) { + continue + } + if (+req.reqTime < this.startTime / 1000) { + continue + } + this.ctx.parallel('nt/friend-request', req) + } }) invoke('nodeIKernelMsgListener/onRecvSysMsg', [], { registerEvent: true }) diff --git a/src/ntqqapi/entities.ts b/src/ntqqapi/entities.ts index ef0671b..64d0bd2 100644 --- a/src/ntqqapi/entities.ts +++ b/src/ntqqapi/entities.ts @@ -23,9 +23,7 @@ import { encodeSilk } from '../common/utils/audio' import { Context } from 'cordis' import { isNullable } from 'cosmokit' -//export const mFaceCache = new Map() // emojiId -> faceName - -export namespace SendElementEntities { +export namespace SendElement { export function text(content: string): SendTextElement { return { elementType: ElementType.Text, diff --git a/src/ntqqapi/types/notify.ts b/src/ntqqapi/types/notify.ts index 3d8362f..cdf5189 100644 --- a/src/ntqqapi/types/notify.ts +++ b/src/ntqqapi/types/notify.ts @@ -56,20 +56,8 @@ export enum GroupRequestOperateTypes { } export enum BuddyReqType { - KMEINITIATOR, - KPEERINITIATOR, - KMEAGREED, - KMEAGREEDANDADDED, - KPEERAGREED, - KPEERAGREEDANDADDED, - KPEERREFUSED, - KMEREFUSED, - KMEIGNORED, - KMEAGREEANYONE, - KMESETQUESTION, - KMEAGREEANDADDFAILED, - KMSGINFO, - KMEINITIATORWAITPEERCONFIRM + MsgInfo = 12, + MeInitiatorWaitPeerConfirm = 13, } export interface FriendRequest { @@ -128,4 +116,4 @@ export interface GroupExtParam { memberIcon: number memberInfoSeq: number } -} \ No newline at end of file +} diff --git a/src/onebot11/action/go-cqhttp/UploadGroupFile.ts b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts index 10ba0e5..72cc3ad 100644 --- a/src/onebot11/action/go-cqhttp/UploadGroupFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadGroupFile.ts @@ -1,6 +1,6 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { SendElementEntities } from '@/ntqqapi/entities' +import { SendElement } from '@/ntqqapi/entities' import { uri2local } from '@/common/utils' import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage' @@ -27,7 +27,7 @@ export class UploadGroupFile extends BaseAction { if (!success) { throw new Error(errMsg) } - const file = await SendElementEntities.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id) + const file = await SendElement.file(this.ctx, path, payload.name || fileName, payload.folder ?? payload.folder_id) const peer = await createPeer(this.ctx, payload, CreatePeerMode.Group) await sendMsg(this.ctx, peer, [file], []) return null diff --git a/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts b/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts index 667b791..7c1c07c 100644 --- a/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts +++ b/src/onebot11/action/go-cqhttp/UploadPrivateFile.ts @@ -1,6 +1,6 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' -import { SendElementEntities } from '@/ntqqapi/entities' +import { SendElement } from '@/ntqqapi/entities' import { uri2local } from '@/common/utils' import { sendMsg, createPeer, CreatePeerMode } from '../../helper/createMessage' @@ -23,7 +23,7 @@ export class UploadPrivateFile extends BaseAction { peerUid: msgInfo.peer.peerUid, chatType: msgInfo.peer.chatType } - const msg = this.adapter.getMsgCache(msgInfo.msgId) ?? (await this.ctx.ntMsgApi.getMsgsByMsgId(peer, [msgInfo.msgId])).msgList[0] + const msg = this.ctx.store.getMsgCache(msgInfo.msgId) ?? (await this.ctx.ntMsgApi.getMsgsByMsgId(peer, [msgInfo.msgId])).msgList[0] const retMsg = await OB11Entities.message(this.ctx, msg) if (!retMsg) { throw new Error('消息为空') diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 2cb911f..6a5321b 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -58,7 +58,7 @@ export enum ActionName { GetCookies = 'get_cookies', ForwardFriendSingleMsg = 'forward_friend_single_msg', ForwardGroupSingleMsg = 'forward_group_single_msg', - // 以下为go-cqhttp api + // go-cqhttp GoCQHTTP_SendGroupForwardMsg = 'send_group_forward_msg', GoCQHTTP_SendPrivateForwardMsg = 'send_private_forward_msg', GoCQHTTP_GetStrangerInfo = 'get_stranger_info', diff --git a/src/onebot11/adapter.ts b/src/onebot11/adapter.ts index 5e2b38c..1c60dcd 100644 --- a/src/onebot11/adapter.ts +++ b/src/onebot11/adapter.ts @@ -37,8 +37,6 @@ declare module 'cordis' { class OneBot11Adapter extends Service { static inject = ['ntMsgApi', 'ntFileApi', 'ntFileCacheApi', 'ntFriendApi', 'ntGroupApi', 'ntUserApi', 'ntWindowApi', 'ntWebApi', 'store'] - public messages: Map = new Map() - public startTime = 0 private ob11WebSocket: OB11WebSocket private ob11WebSocketReverseManager: OB11WebSocketReverseManager private ob11Http: OB11Http @@ -74,24 +72,6 @@ class OneBot11Adapter extends Service { }) } - /** 缓存近期消息内容 */ - public async addMsgCache(msg: RawMessage) { - const expire = this.config.msgCacheExpire * 1000 - if (expire === 0) { - return - } - const id = msg.msgId - this.messages.set(id, msg) - setTimeout(() => { - this.messages.delete(id) - }, expire) - } - - /** 获取近期消息内容 */ - public getMsgCache(msgId: string) { - return this.messages.get(msgId) - } - public dispatch(event: OB11BaseEvent | OB11Message) { if (this.config.enableWs) { this.ob11WebSocket.emitEvent(event) @@ -108,115 +88,99 @@ class OneBot11Adapter extends Service { } } - private async handleGroupNotify(notifies: GroupNotify[]) { - for (const notify of notifies) { - try { - const notifyTime = parseInt(notify.seq) / 1000 - if (notifyTime < this.startTime) { - continue - } - const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type - if ([GroupNotifyType.MEMBER_LEAVE_NOTIFY_ADMIN, GroupNotifyType.KICK_MEMBER_NOTIFY_ADMIN].includes(notify.type)) { - this.ctx.logger.info('有成员退出通知', notify) - const member1Uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) - let operatorId = member1Uin - let subType: GroupDecreaseSubType = 'leave' - if (notify.user2.uid) { - // 是被踢的 - const member2Uin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) - if (member2Uin) { - operatorId = member2Uin - } - subType = 'kick' + private async handleGroupNotify(notify: GroupNotify) { + try { + const flag = notify.group.groupCode + '|' + notify.seq + '|' + notify.type + if ([GroupNotifyType.MEMBER_LEAVE_NOTIFY_ADMIN, GroupNotifyType.KICK_MEMBER_NOTIFY_ADMIN].includes(notify.type)) { + this.ctx.logger.info('有成员退出通知', notify) + const member1Uin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) + let operatorId = member1Uin + let subType: GroupDecreaseSubType = 'leave' + if (notify.user2.uid) { + // 是被踢的 + const member2Uin = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) + if (member2Uin) { + operatorId = member2Uin } - const event = new OB11GroupDecreaseEvent( - parseInt(notify.group.groupCode), - parseInt(member1Uin), - parseInt(operatorId), - subType, - ) - this.dispatch(event) + subType = 'kick' } - else if (notify.type === GroupNotifyType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS && notify.status === GroupNotifyStatus.KUNHANDLE) { - this.ctx.logger.info('有加群请求') - const requestUin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) - const event = new OB11GroupRequestEvent( - parseInt(notify.group.groupCode), - parseInt(requestUin) || 0, - flag, - notify.postscript, - ) - this.dispatch(event) - } - else if (notify.type === GroupNotifyType.INVITED_BY_MEMBER && notify.status === GroupNotifyStatus.KUNHANDLE) { - this.ctx.logger.info('收到邀请我加群通知') - const userId = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) - const event = new OB11GroupRequestEvent( - parseInt(notify.group.groupCode), - parseInt(userId) || 0, - flag, - notify.postscript, - undefined, - 'invite' - ) - this.dispatch(event) - } - else if (notify.type === GroupNotifyType.INVITED_NEED_ADMINI_STRATOR_PASS && notify.status === GroupNotifyStatus.KUNHANDLE) { - this.ctx.logger.info('收到群员邀请加群通知') - const userId = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) - const event = new OB11GroupRequestEvent( - parseInt(notify.group.groupCode), - parseInt(userId) || 0, - flag, - notify.postscript - ) - this.dispatch(event) - } - } catch (e) { - this.ctx.logger.error('解析群通知失败', (e as Error).stack) + const event = new OB11GroupDecreaseEvent( + parseInt(notify.group.groupCode), + parseInt(member1Uin), + parseInt(operatorId), + subType, + ) + this.dispatch(event) } + else if (notify.type === GroupNotifyType.REQUEST_JOIN_NEED_ADMINI_STRATOR_PASS && notify.status === GroupNotifyStatus.KUNHANDLE) { + this.ctx.logger.info('有加群请求') + const requestUin = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) + const event = new OB11GroupRequestEvent( + parseInt(notify.group.groupCode), + parseInt(requestUin) || 0, + flag, + notify.postscript, + ) + this.dispatch(event) + } + else if (notify.type === GroupNotifyType.INVITED_BY_MEMBER && notify.status === GroupNotifyStatus.KUNHANDLE) { + this.ctx.logger.info('收到邀请我加群通知') + const userId = await this.ctx.ntUserApi.getUinByUid(notify.user2.uid) + const event = new OB11GroupRequestEvent( + parseInt(notify.group.groupCode), + parseInt(userId) || 0, + flag, + notify.postscript, + undefined, + 'invite' + ) + this.dispatch(event) + } + else if (notify.type === GroupNotifyType.INVITED_NEED_ADMINI_STRATOR_PASS && notify.status === GroupNotifyStatus.KUNHANDLE) { + this.ctx.logger.info('收到群员邀请加群通知') + const userId = await this.ctx.ntUserApi.getUinByUid(notify.user1.uid) + const event = new OB11GroupRequestEvent( + parseInt(notify.group.groupCode), + parseInt(userId) || 0, + flag, + notify.postscript + ) + this.dispatch(event) + } + } catch (e) { + this.ctx.logger.error('解析群通知失败', (e as Error).stack) } } - private handleMsg(msgList: RawMessage[]) { - for (const message of msgList) { - // 过滤启动之前的消息 - if (parseInt(message.msgTime) < this.startTime / 1000) { - continue + private handleMsg(message: RawMessage) { + OB11Entities.message(this.ctx, message).then(msg => { + if (!msg) { + return } - this.addMsgCache(message) + if (!this.config.debug && msg.message.length === 0) { + return + } + const isSelfMsg = msg.user_id.toString() === selfInfo.uin + if (isSelfMsg && !this.config.reportSelfMessage) { + return + } + if (isSelfMsg) { + msg.target_id = parseInt(message.peerUin) + } + this.dispatch(msg) + }).catch(e => this.ctx.logger.error('constructMessage error: ', e.stack.toString())) - OB11Entities.message(this.ctx, message) - .then((msg) => { - if (!msg) { - return - } - if (!this.config.debug && msg.message.length === 0) { - return - } - const isSelfMsg = msg.user_id.toString() === selfInfo.uin - if (isSelfMsg && !this.config.reportSelfMessage) { - return - } - if (isSelfMsg) { - msg.target_id = parseInt(message.peerUin) - } - this.dispatch(msg) - }) - .catch((e) => this.ctx.logger.error('constructMessage error: ', e.stack.toString())) + OB11Entities.groupEvent(this.ctx, message).then(groupEvent => { + if (groupEvent) { + this.dispatch(groupEvent) + } + }) - OB11Entities.groupEvent(this.ctx, message).then((groupEvent) => { - if (groupEvent) { - this.dispatch(groupEvent) - } - }) - - OB11Entities.privateEvent(this.ctx, message).then((privateEvent) => { - if (privateEvent) { - this.dispatch(privateEvent) - } - }) - } + OB11Entities.privateEvent(this.ctx, message).then(privateEvent => { + if (privateEvent) { + this.dispatch(privateEvent) + } + }) } private handleRecallMsg(message: RawMessage) { @@ -235,30 +199,22 @@ class OneBot11Adapter extends Service { }) } - private async handleFriendRequest(buddyReqs: FriendRequest[]) { - for (const req of buddyReqs) { - if (!!req.isInitiator || (req.isDecide && req.reqType !== BuddyReqType.KMEINITIATORWAITPEERCONFIRM)) { - continue - } - if (+req.reqTime < this.startTime / 1000) { - continue - } - let userId = 0 - try { - const requesterUin = await this.ctx.ntUserApi.getUinByUid(req.friendUid) - userId = parseInt(requesterUin) - } catch (e) { - this.ctx.logger.error('获取加好友者QQ号失败', e) - } - const flag = req.friendUid + '|' + req.reqTime - const comment = req.extWords - const friendRequestEvent = new OB11FriendRequestEvent( - userId, - comment, - flag - ) - this.dispatch(friendRequestEvent) + private async handleFriendRequest(req: FriendRequest) { + let userId = 0 + try { + const requesterUin = await this.ctx.ntUserApi.getUinByUid(req.friendUid) + userId = parseInt(requesterUin) + } catch (e) { + this.ctx.logger.error('获取加好友者QQ号失败', e) } + const flag = req.friendUid + '|' + req.reqTime + const comment = req.extWords + const friendRequestEvent = new OB11FriendRequestEvent( + userId, + comment, + flag + ) + this.dispatch(friendRequestEvent) } private async handleConfigUpdated(config: LLOBConfig) { @@ -374,7 +330,6 @@ class OneBot11Adapter extends Service { } public start() { - this.startTime = Date.now() if (this.config.enableWs) { this.ob11WebSocket.start() } @@ -397,7 +352,7 @@ class OneBot11Adapter extends Service { this.handleRecallMsg(input) }) this.ctx.on('nt/message-sent', input => { - this.handleMsg([input]) + this.handleMsg(input) }) this.ctx.on('nt/group-notify', input => { this.handleGroupNotify(input) diff --git a/src/onebot11/entities.ts b/src/onebot11/entities.ts index daffca6..499ca76 100644 --- a/src/onebot11/entities.ts +++ b/src/onebot11/entities.ts @@ -338,7 +338,6 @@ export namespace OB11Entities { key: marketFaceElement.key } } - //mFaceCache.set(emojiId, element.marketFaceElement.faceName!) } else if (element.markdownElement) { const { markdownElement } = element diff --git a/src/onebot11/helper/createMessage.ts b/src/onebot11/helper/createMessage.ts index b8b08c6..7bbb6a3 100644 --- a/src/onebot11/helper/createMessage.ts +++ b/src/onebot11/helper/createMessage.ts @@ -15,7 +15,7 @@ import { } from '../types' import { decodeCQCode } from '../cqcode' import { Peer } from '@/ntqqapi/types/msg' -import { SendElementEntities } from '@/ntqqapi/entities' +import { SendElement } from '@/ntqqapi/entities' import { selfInfo } from '@/common/globalVars' import { uri2local } from '@/common/utils' import { Context } from 'cordis' @@ -36,7 +36,7 @@ export async function createSendElements( case OB11MessageDataType.text: { const text = sendMsg.data?.text if (text) { - sendElements.push(SendElementEntities.text(sendMsg.data!.text)) + sendElements.push(SendElement.text(sendMsg.data!.text)) } } break @@ -62,7 +62,7 @@ export async function createSendElements( } } if (isAdmin && remainAtAllCount > 0) { - sendElements.push(SendElementEntities.at(atQQ, atQQ, AtType.All, '@全体成员')) + sendElements.push(SendElement.at(atQQ, atQQ, AtType.All, '@全体成员')) } } else if (peer.chatType === ChatType.Group) { @@ -70,14 +70,14 @@ export async function createSendElements( if (atMember) { const display = `@${atMember.cardName || atMember.nick}` sendElements.push( - SendElementEntities.at(atQQ, atMember.uid, AtType.One, display), + SendElement.at(atQQ, atMember.uid, AtType.One, display), ) } else { const atNmae = sendMsg.data?.name const uid = await ctx.ntUserApi.getUidByUin(atQQ) || '' const display = atNmae ? `@${atNmae}` : '' sendElements.push( - SendElementEntities.at(atQQ, uid, AtType.One, display), + SendElement.at(atQQ, uid, AtType.One, display), ) } } @@ -97,7 +97,7 @@ export async function createSendElements( )).msgList[0] if (replyMsg) { sendElements.push( - SendElementEntities.reply( + SendElement.reply( replyMsg.msgSeq, replyMsg.msgId, replyMsg.senderUin!, @@ -111,13 +111,13 @@ export async function createSendElements( case OB11MessageDataType.face: { const faceId = sendMsg.data?.id if (faceId) { - sendElements.push(SendElementEntities.face(parseInt(faceId))) + sendElements.push(SendElement.face(parseInt(faceId))) } } break case OB11MessageDataType.mface: { sendElements.push( - SendElementEntities.mface( + SendElement.mface( +sendMsg.data.emoji_package_id, sendMsg.data.emoji_id, sendMsg.data.key, @@ -127,7 +127,7 @@ export async function createSendElements( } break case OB11MessageDataType.image: { - const res = await SendElementEntities.pic( + const res = await SendElement.pic( ctx, (await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles })).path, sendMsg.data.summary || '', @@ -140,7 +140,7 @@ export async function createSendElements( break case OB11MessageDataType.file: { const { path, fileName } = await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles }) - sendElements.push(await SendElementEntities.file(ctx, path, fileName)) + sendElements.push(await SendElement.file(ctx, path, fileName)) } break case OB11MessageDataType.video: { @@ -150,38 +150,38 @@ export async function createSendElements( const uri2LocalRes = await uri2local(thumb) if (uri2LocalRes.success) thumb = uri2LocalRes.path } - const res = await SendElementEntities.video(ctx, path, fileName, thumb) + const res = await SendElement.video(ctx, path, fileName, thumb) deleteAfterSentFiles.push(res.videoElement.filePath) sendElements.push(res) } break case OB11MessageDataType.voice: { const { path } = await handleOb11FileLikeMessage(ctx, sendMsg, { deleteAfterSentFiles }) - sendElements.push(await SendElementEntities.ptt(ctx, path)) + sendElements.push(await SendElement.ptt(ctx, path)) } break case OB11MessageDataType.json: { - sendElements.push(SendElementEntities.ark(sendMsg.data.data)) + sendElements.push(SendElement.ark(sendMsg.data.data)) } break case OB11MessageDataType.dice: { const resultId = sendMsg.data?.result - sendElements.push(SendElementEntities.dice(resultId)) + sendElements.push(SendElement.dice(resultId)) } break case OB11MessageDataType.RPS: { const resultId = sendMsg.data?.result - sendElements.push(SendElementEntities.rps(resultId)) + sendElements.push(SendElement.rps(resultId)) } break case OB11MessageDataType.contact: { const { type, id } = sendMsg.data const data = type === 'qq' ? ctx.ntFriendApi.getBuddyRecommendContact(id) : ctx.ntGroupApi.getGroupRecommendContact(id) - sendElements.push(SendElementEntities.ark(await data)) + sendElements.push(SendElement.ark(await data)) } break case OB11MessageDataType.shake: { - sendElements.push(SendElementEntities.shake()) + sendElements.push(SendElement.shake()) } break }