diff --git a/manifest.json b/manifest.json index 2a25394..83911fc 100644 --- a/manifest.json +++ b/manifest.json @@ -4,7 +4,7 @@ "name": "LLOneBot", "slug": "LLOneBot", "description": "实现 OneBot 11 协议,用于 QQ 机器人开发", - "version": "3.33.8", + "version": "3.33.9", "icon": "./icon.webp", "authors": [ { diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index d6da548..d6507d9 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -6,9 +6,9 @@ import { GroupNotifies, GroupRequestOperateTypes, GetFileListParam, - OnGroupFileInfoUpdateParams, PublishGroupBulletinReq, - GroupAllInfo + GroupAllInfo, + GroupFileInfo } from '../types' import { invoke, NTClass, NTMethod } from '../ntcall' import { GeneralCallResult } from '../services' @@ -274,7 +274,7 @@ export class NTQQGroupApi extends Service { async getGroupFileList(groupId: string, fileListForm: GetFileListParam) { invoke('nodeIKernelMsgListener/onGroupFileInfoUpdate', [], { registerEvent: true }) - const data = await invoke<{ fileInfo: OnGroupFileInfoUpdateParams }>( + const data = await invoke<{ fileInfo: GroupFileInfo }>( 'nodeIKernelRichMediaService/getGroupFileList', [ { diff --git a/src/ntqqapi/ntcall.ts b/src/ntqqapi/ntcall.ts index 58b362e..5ed6ad3 100644 --- a/src/ntqqapi/ntcall.ts +++ b/src/ntqqapi/ntcall.ts @@ -159,9 +159,9 @@ export function invoke< afterFirstCmd && secondCallback() } else { - log('ntqq api call failed,', method, res) + log('ntqq api call failed,', method, args, res) clearTimeout(timeoutId) - reject(`ntqq api call failed, ${method}, ${res.errMsg}`) + reject(`ntqq api call failed, ${method}, ${res?.errMsg}`) } } } diff --git a/src/ntqqapi/types/msg.ts b/src/ntqqapi/types/msg.ts index 46c10f3..a1dda88 100644 --- a/src/ntqqapi/types/msg.ts +++ b/src/ntqqapi/types/msg.ts @@ -478,7 +478,7 @@ export interface OnRichMediaDownloadCompleteParams { userUsedSpacePerDay: unknown } -export interface OnGroupFileInfoUpdateParams { +export interface GroupFileInfo { retCode: number retMsg: string clientWording: string diff --git a/src/onebot11/action/go-cqhttp/GetForwardMsg.ts b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts index 746c77d..f08e805 100644 --- a/src/onebot11/action/go-cqhttp/GetForwardMsg.ts +++ b/src/onebot11/action/go-cqhttp/GetForwardMsg.ts @@ -34,25 +34,23 @@ export class GetForwardMsg extends BaseAction { if (data?.result !== 0) { throw Error('找不到相关的聊天记录' + data?.errMsg) } - const msgList = data.msgList - const messages = await Promise.all( - msgList.map(async (msg) => { - const resMsg = await OB11Entities.message(this.ctx, msg) - if (!resMsg) return - resMsg.message_id = this.ctx.store.createMsgShortId({ - chatType: msg.chatType, - peerUid: msg.peerUid, - }, msg.msgId) - return resMsg + const messages: (OB11ForwardMessage | undefined)[] = await Promise.all( + data.msgList.map(async (msg) => { + const res = await OB11Entities.message(this.ctx, msg) + if (res) { + return { + content: res.message, + sender: { + nickname: res.sender.nickname, + user_id: res.sender.user_id + }, + time: res.time, + message_format: res.message_format, + message_type: res.message_type + } + } }) ) - const forwardMessages = filterNullable(messages) - .map(v => { - const msg = v as Partial - msg.content = msg.message - delete msg.message - return msg as OB11ForwardMessage - }) - return { messages: forwardMessages } + return { messages: filterNullable(messages) } } } diff --git a/src/onebot11/action/go-cqhttp/GetGroupFileUrl.ts b/src/onebot11/action/go-cqhttp/GetGroupFileUrl.ts index e868be4..78942f2 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupFileUrl.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupFileUrl.ts @@ -2,6 +2,7 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { pathToFileURL } from 'node:url' import { ChatType } from '@/ntqqapi/types' +import { GroupFileInfo } from '@/ntqqapi/types' export interface Payload { group_id: number | string @@ -30,23 +31,7 @@ export class GetGroupFileUrl extends BaseAction { } } else { const groupId = payload.group_id.toString() - let modelId: string | undefined - let nextIndex: number | undefined - while (nextIndex !== 0) { - const res = await this.ctx.ntGroupApi.getGroupFileList(groupId, { - sortType: 1, - fileCount: 50, - startIndex: nextIndex ?? 0, - sortOrder: 2, - showOnlinedocFolder: 0, - }) - const file = res.item.find(item => item.fileInfo?.fileId === payload.file_id) - if (file) { - modelId = file.fileInfo?.fileModelId - break - } - nextIndex = res.nextIndex - } + const modelId = await this.search(groupId, payload.file_id) if (modelId) { const peer = { chatType: ChatType.Group, @@ -61,4 +46,37 @@ export class GetGroupFileUrl extends BaseAction { throw new Error('file not found') } } + + private async search(groupId: string, fileId: string, folderId?: string) { + let modelId: string | undefined + let nextIndex: number | undefined + let folders: GroupFileInfo['item'] = [] + while (nextIndex !== 0) { + const res = await this.ctx.ntGroupApi.getGroupFileList(groupId, { + sortType: 1, + fileCount: 100, + startIndex: nextIndex ?? 0, + sortOrder: 2, + showOnlinedocFolder: 0, + folderId + }) + const file = res.item.find(item => item.fileInfo?.fileId === fileId) + if (file) { + modelId = file.fileInfo?.fileModelId + break + } + folders.push(...res.item.filter(item => item.folderInfo?.totalFileCount)) + nextIndex = res.nextIndex + } + if (!modelId) { + for (const item of folders) { + const res = await this.search(groupId, fileId, item.folderInfo?.folderId) + if (res) { + modelId = res + break + } + } + } + return modelId + } } diff --git a/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts b/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts index a9ca570..eca1729 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupFilesByFolder.ts @@ -1,7 +1,7 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { OB11GroupFile, OB11GroupFileFolder } from '@/onebot11/types' -import { OnGroupFileInfoUpdateParams } from '@/ntqqapi/types' +import { GroupFileInfo } from '@/ntqqapi/types' interface Payload { group_id: number | string @@ -22,7 +22,7 @@ export class GetGroupFilesByFolder extends BaseAction { async _handle(payload: Payload) { const groupId = payload.group_id.toString() - const data: OnGroupFileInfoUpdateParams['item'] = [] + const data: GroupFileInfo['item'] = [] let nextIndex: number | undefined while (nextIndex !== 0) { diff --git a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts index f3d4788..6df3b5a 100644 --- a/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts +++ b/src/onebot11/action/go-cqhttp/GetGroupRootFiles.ts @@ -1,7 +1,7 @@ import { BaseAction, Schema } from '../BaseAction' import { ActionName } from '../types' import { OB11GroupFile, OB11GroupFileFolder } from '../../types' -import { OnGroupFileInfoUpdateParams } from '@/ntqqapi/types' +import { GroupFileInfo } from '@/ntqqapi/types' interface Payload { group_id: number | string @@ -20,7 +20,7 @@ export class GetGroupRootFiles extends BaseAction { async _handle(payload: Payload) { const groupId = payload.group_id.toString() - const data: OnGroupFileInfoUpdateParams['item'] = [] + const data: GroupFileInfo['item'] = [] let nextIndex: number | undefined while (nextIndex !== 0) { diff --git a/src/onebot11/cqcode.ts b/src/onebot11/cqcode.ts index de3da4c..43b2299 100644 --- a/src/onebot11/cqcode.ts +++ b/src/onebot11/cqcode.ts @@ -72,7 +72,3 @@ export function encodeCQCode(input: OB11MessageData) { result += ']' return result } - -// const result = parseCQCode("[CQ:at,qq=114514]早上好啊[CQ:image,file=http://baidu.com/1.jpg,type=show,id=40004]") -// const result = parseCQCode("好好好") -// console.log(JSON.stringify(result)) diff --git a/src/onebot11/types.ts b/src/onebot11/types.ts index 0fd169b..fc46fe1 100644 --- a/src/onebot11/types.ts +++ b/src/onebot11/types.ts @@ -98,8 +98,15 @@ export interface OB11Message { temp_source?: 0 | 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 } -export interface OB11ForwardMessage extends OB11Message { +export interface OB11ForwardMessage { content: OB11MessageData[] | string + sender: { + nickname: string + user_id: number + } + time: number + message_format: string //扩展 + message_type: string //扩展 } export interface OB11Return { diff --git a/src/version.ts b/src/version.ts index 3624278..248e835 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export const version = '3.33.8' +export const version = '3.33.9'