From e39c89a4410acee2c311605653c8211b12d40e5f Mon Sep 17 00:00:00 2001 From: idranme Date: Mon, 16 Sep 2024 19:01:59 +0800 Subject: [PATCH] fix --- src/main/log.ts | 3 +- src/ntqqapi/api/msg.ts | 2 +- src/ntqqapi/core.ts | 2 +- src/ntqqapi/types/msg.ts | 53 ++++++++--------------------- src/onebot11/action/file/GetFile.ts | 2 +- src/onebot11/entities.ts | 44 +++++++++++------------- 6 files changed, 39 insertions(+), 67 deletions(-) diff --git a/src/main/log.ts b/src/main/log.ts index a955da6..6347564 100644 --- a/src/main/log.ts +++ b/src/main/log.ts @@ -23,8 +23,7 @@ export default class Log { return } const dateTime = new Date(record.timestamp).toLocaleString() - const userInfo = selfInfo.uin ? `${selfInfo.nick}(${selfInfo.uin})` : '' - const content = `${dateTime} [${record.type}] ${userInfo} | ${record.name} ${record.content}\n\n` + const content = `${dateTime} [${record.type}] ${selfInfo.nick}(${selfInfo.uin}) | ${record.name} ${record.content}\n\n` appendFile(file, content, noop) }, } diff --git a/src/ntqqapi/api/msg.ts b/src/ntqqapi/api/msg.ts index 3698ac8..c478826 100644 --- a/src/ntqqapi/api/msg.ts +++ b/src/ntqqapi/api/msg.ts @@ -183,7 +183,7 @@ export class NTQQMsgApi extends Service { if (!arkElement) { continue } - const forwardData = JSON.parse(arkElement.arkElement.bytesData) + const forwardData = JSON.parse(arkElement.arkElement!.bytesData) if (forwardData.app != 'com.tencent.multimsg') { continue } diff --git a/src/ntqqapi/core.ts b/src/ntqqapi/core.ts index 2d32bc4..b2c34a2 100644 --- a/src/ntqqapi/core.ts +++ b/src/ntqqapi/core.ts @@ -96,7 +96,7 @@ class Core extends Service { } for (const path of pathList) { if (path) { - fs.unlink(picPath, () => { + fs.unlink(path, () => { this.ctx.logger.info('删除文件成功', path) }) } diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index 977c16b..666a755 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -102,7 +102,7 @@ export interface SendPicElement { export interface SendReplyElement { elementType: ElementType.REPLY elementId: '' - replyElement: ReplyElement + replyElement: Partial } export interface SendFaceElement { @@ -129,6 +129,12 @@ export interface ReplyElement { replayMsgId: string senderUin: string senderUinStr: string + sourceMsgIdInRecords: string + senderUid: string + senderUidStr: string + sourceMsgIsIncPic: boolean // 原消息是否有图片 + sourceMsgText: string + replyMsgTime: string } export interface FileElement { @@ -303,7 +309,7 @@ export enum GrayTipElementSubType { export interface GrayTipElement { subElementType: GrayTipElementSubType - revokeElement: { + revokeElement?: { operatorRole: string operatorUid: string operatorNick: string @@ -313,14 +319,14 @@ export interface GrayTipElement { isSelfOperate?: boolean wording: string // 自定义的撤回提示语 } - aioOpGrayTipElement: TipAioOpGrayTipElement - groupElement: TipGroupElement - xmlElement: { + aioOpGrayTipElement?: TipAioOpGrayTipElement + groupElement?: TipGroupElement + xmlElement?: { templId: string content: string } - jsonGrayTipElement: { - busiId: number + jsonGrayTipElement?: { + busiId: string jsonStr: string } } @@ -485,36 +491,7 @@ export interface RawMessage { sendStatus?: number // 消息状态,别人发的2是已撤回,自己发的2是已发送 recallTime: string // 撤回时间, "0"是没有撤回 records: RawMessage[] - elements: { - elementId: string - elementType: ElementType - replyElement: { - sourceMsgIdInRecords: string - senderUid: string // 原消息发送者QQ号 - sourceMsgIsIncPic: boolean // 原消息是否有图片 - sourceMsgText: string - replayMsgSeq: string // 源消息的msgSeq,可以通过这个找到源消息的msgId - senderUidStr: string - replyMsgTime: string - } - textElement: { - atType: AtType - atUid: string // QQ号 - content: string - atNtUid: string // uid号 - } - picElement: PicElement - pttElement: PttElement - arkElement: ArkElement - grayTipElement: GrayTipElement - faceElement: FaceElement - videoElement: VideoElement - fileElement: FileElement - marketFaceElement: MarketFaceElement - inlineKeyboardElement: InlineKeyboardElement - markdownElement: MarkdownElement - multiForwardMsgElement: MultiForwardMsgElement - }[] + elements: MessageElement[] } export interface Peer { @@ -529,7 +506,7 @@ export interface MessageElement { extBufForUI: string //"0x" textElement?: TextElement faceElement?: FaceElement - marketFaceElement?: MarkdownElement + marketFaceElement?: MarketFaceElement replyElement?: ReplyElement picElement?: PicElement pttElement?: PttElement diff --git a/src/onebot11/action/file/GetFile.ts b/src/onebot11/action/file/GetFile.ts index 07c37e8..d8bdb56 100644 --- a/src/onebot11/action/file/GetFile.ts +++ b/src/onebot11/action/file/GetFile.ts @@ -59,7 +59,7 @@ export abstract class GetFileBase extends BaseAction item.uid) - if (poke_uid.length == 2) { - return new OB11FriendPokeEvent( - parseInt(await ctx.ntUserApi.getUinByUid(poke_uid[0].uid)), - parseInt(await ctx.ntUserApi.getUinByUid(poke_uid[1].uid)), - pokedetail - ) - } + const pokedetail: Dict[] = json.items + //筛选item带有uid的元素 + const poke_uid = pokedetail.filter(item => item.uid) + if (poke_uid.length === 2) { + return new OB11FriendPokeEvent( + Number(await ctx.ntUserApi.getUinByUid(poke_uid[0].uid)), + Number(await ctx.ntUserApi.getUinByUid(poke_uid[1].uid)), + pokedetail + ) } } + if (grayTipElement.xmlElement?.templId === '10229') { + const uin = +msg.peerUin || +(await ctx.ntUserApi.getUinByUid(msg.peerUid)) + return new OB11FriendAddNoticeEvent(uin) + } } } - // 好友增加事件 - if (msg.msgType === 5 && msg.subMsgType === 12) { - const uin = +msg.peerUin || +(await ctx.ntUserApi.getUinByUid(msg.peerUid)) - const event = new OB11FriendAddNoticeEvent(uin) - return event - } } export async function groupEvent(ctx: Context, msg: RawMessage): Promise { @@ -564,8 +560,8 @@ export namespace OB11Entities { } } else if (grayTipElement.subElementType == GrayTipElementSubType.JSON) { - const json = JSON.parse(grayTipElement.jsonGrayTipElement.jsonStr) - if (grayTipElement.jsonGrayTipElement.busiId == 1061) { + const json = JSON.parse(grayTipElement.jsonGrayTipElement!.jsonStr) + if (grayTipElement.jsonGrayTipElement?.busiId === '1061') { const pokedetail: Dict[] = json.items //筛选item带有uid的元素 const poke_uid = pokedetail.filter(item => item.uid) @@ -578,7 +574,7 @@ export namespace OB11Entities { ) } } - if (grayTipElement.jsonGrayTipElement.busiId == 2401) { + if (grayTipElement.jsonGrayTipElement?.busiId === '2401') { ctx.logger.info('收到群精华消息', json) const searchParams = new URL(json.items[0].jp).searchParams const msgSeq = searchParams.get('msgSeq')! @@ -605,7 +601,7 @@ export namespace OB11Entities { ) // 获取MsgSeq+Peer可获取具体消息 } - if (grayTipElement.jsonGrayTipElement.busiId == 2407) { + if (grayTipElement.jsonGrayTipElement?.busiId === '2407') { const memberUin = json.items[1].param[0] const title = json.items[3].txt ctx.logger.info('收到群成员新头衔消息', json) @@ -632,9 +628,9 @@ export namespace OB11Entities { if (!msgElement) { return } - const revokeElement = msgElement.grayTipElement.revokeElement + const revokeElement = msgElement.grayTipElement!.revokeElement if (msg.chatType === ChatType.group) { - const operator = await ctx.ntGroupApi.getGroupMember(msg.peerUid, revokeElement.operatorUid) + const operator = await ctx.ntGroupApi.getGroupMember(msg.peerUid, revokeElement!.operatorUid) return new OB11GroupRecallNoticeEvent( parseInt(msg.peerUid), parseInt(msg.senderUin!),