Merge pull request #451 from LLOneBot/dev

release: 3.33.9
This commit is contained in:
idranme 2024-09-27 16:53:44 +08:00 committed by GitHub
commit d5875c9e5b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 71 additions and 52 deletions

View File

@ -4,7 +4,7 @@
"name": "LLOneBot",
"slug": "LLOneBot",
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
"version": "3.33.8",
"version": "3.33.9",
"icon": "./icon.webp",
"authors": [
{

View File

@ -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',
[
{

View File

@ -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}`)
}
}
}

View File

@ -478,7 +478,7 @@ export interface OnRichMediaDownloadCompleteParams {
userUsedSpacePerDay: unknown
}
export interface OnGroupFileInfoUpdateParams {
export interface GroupFileInfo {
retCode: number
retMsg: string
clientWording: string

View File

@ -34,25 +34,23 @@ export class GetForwardMsg extends BaseAction<Payload, Response> {
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<OB11ForwardMessage>
msg.content = msg.message
delete msg.message
return msg as OB11ForwardMessage
})
return { messages: forwardMessages }
return { messages: filterNullable(messages) }
}
}

View File

@ -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<Payload, Response> {
}
} 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<Payload, Response> {
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
}
}

View File

@ -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<Payload, Response> {
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) {

View File

@ -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<Payload, Response> {
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) {

View File

@ -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))

View File

@ -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<DataType> {

View File

@ -1 +1 @@
export const version = '3.33.8'
export const version = '3.33.9'