feat: add action get_group_file_url

This commit is contained in:
pk5ls20 2024-10-19 04:14:01 +08:00
parent f3033ce732
commit 83bced82b1
No known key found for this signature in database
GPG Key ID: 6370ED7A169F493A
5 changed files with 57 additions and 5 deletions

View File

@ -8,9 +8,10 @@ import { NapProtoMsg } from '@/core/packet/proto/NapProto';
import { OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '@/core/packet/proto/oidb/Oidb.0x9067_202'; import { OidbSvcTrpcTcp0X9067_202_Rsp_Body } from '@/core/packet/proto/oidb/Oidb.0x9067_202';
import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '@/core/packet/proto/oidb/OidbBase'; import { OidbSvcTrpcTcpBase, OidbSvcTrpcTcpBaseRsp } from '@/core/packet/proto/oidb/OidbBase';
import { OidbSvcTrpcTcp0XFE1_2RSP } from '@/core/packet/proto/oidb/Oidb.0XFE1_2'; import { OidbSvcTrpcTcp0XFE1_2RSP } from '@/core/packet/proto/oidb/Oidb.0XFE1_2';
import {LogWrapper} from "@/common/log"; import { LogWrapper } from "@/common/log";
import {SendLongMsgResp} from "@/core/packet/proto/message/action"; import { SendLongMsgResp } from "@/core/packet/proto/message/action";
import {PacketMsg} from "@/core/packet/msg/message"; import { PacketMsg } from "@/core/packet/msg/message";
import { OidbSvcTrpcTcp0x6D6Response } from "@/core/packet/proto/oidb/Oidb.0x6D6";
interface OffsetType { interface OffsetType {
[key: string]: { [key: string]: {
@ -112,4 +113,15 @@ export class NTQQPacketApi {
const resp = new NapProtoMsg(SendLongMsgResp).decode(Buffer.from(ret.hex_data, 'hex')); const resp = new NapProtoMsg(SendLongMsgResp).decode(Buffer.from(ret.hex_data, 'hex'));
return resp.result.resId; return resp.result.resId;
} }
async sendGroupFileDownloadReq(groupUin: number, fileUUID: string) {
const data = this.packetPacker.packGroupFileDownloadReq(groupUin, fileUUID);
const ret = await this.sendPacket('OidbSvcTrpcTcp.0x6d6_2', data, true);
const body = new NapProtoMsg(OidbSvcTrpcTcpBaseRsp).decode(Buffer.from(ret.hex_data, 'hex')).body;
const resp = new NapProtoMsg(OidbSvcTrpcTcp0x6D6Response).decode(body);
if (resp.download.retCode !== 0){
throw new Error(`sendGroupFileDownloadReq error: ${resp.download.clientWording}`);
}
return `https://${resp.download.downloadDns}/ftn_handler/${Buffer.from(resp.download.downloadUrl).toString('hex')}/?fname=`
}
} }

View File

@ -288,14 +288,14 @@ export class PacketPacker {
packGroupFileDownloadReq(groupUin: number, fileUUID: string): PacketHexStr { packGroupFileDownloadReq(groupUin: number, fileUUID: string): PacketHexStr {
return this.toHexStr( return this.toHexStr(
new NapProtoMsg(OidbSvcTrpcTcp0x6D6).encode({ this.packOidbPacket(0x6D6, 2, new NapProtoMsg(OidbSvcTrpcTcp0x6D6).encode({
download: { download: {
groupUin: groupUin, groupUin: groupUin,
appId: 7, appId: 7,
busId: 102, busId: 102,
fileId: fileUUID fileId: fileUUID
} }
}) }), true, false)
) )
} }

View File

@ -0,0 +1,37 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import {FileNapCatOneBotUUID} from "@/common/helper";
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['number', 'string'] },
file_id: { type: ['string'] },
},
required: ['group_id', 'file_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
interface GetGroupFileUrlResponse {
url?: string;
}
export class GetGroupFileUrl extends BaseAction<Payload, GetGroupFileUrlResponse> {
actionName = ActionName.GOCQHTTP_GetGroupFileUrl;
payloadSchema = SchemaData;
async _handle(payload: Payload) {
if (!this.core.apis.PacketApi.available) {
throw new Error('PacketClient is not init');
}
const contextMsgFile = FileNapCatOneBotUUID.decode(payload.file_id) || FileNapCatOneBotUUID.decodeModelId(payload.file_id);
if (contextMsgFile?.fileUUID) {
return {
url: await this.core.apis.PacketApi.sendGroupFileDownloadReq(+payload.group_id, contextMsgFile.fileUUID)
}
}
throw new Error('real fileUUID not found!');
}
}

View File

@ -90,6 +90,7 @@ import { SetSpecialTittle } from './extends/SetSpecialTittle';
import { UploadForwardMsg } from "@/onebot/action/extends/UploadForwardMsg"; import { UploadForwardMsg } from "@/onebot/action/extends/UploadForwardMsg";
import { GetGroupShutList } from './group/GetGroupShutList'; import { GetGroupShutList } from './group/GetGroupShutList';
import { GetGroupMemberList } from './group/GetGroupMemberList'; import { GetGroupMemberList } from './group/GetGroupMemberList';
import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl";
export type ActionMap = Map<string, BaseAction<any, any>>; export type ActionMap = Map<string, BaseAction<any, any>>;
@ -192,6 +193,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
new SetSpecialTittle(obContext, core), new SetSpecialTittle(obContext, core),
new UploadForwardMsg(obContext, core), new UploadForwardMsg(obContext, core),
new GetGroupShutList(obContext, core), new GetGroupShutList(obContext, core),
new GetGroupFileUrl(obContext, core),
]; ];
const actionMap = new Map(); const actionMap = new Map();
for (const action of actionHandlers) { for (const action of actionHandlers) {

View File

@ -85,6 +85,7 @@ export enum ActionName {
MarkGroupMsgAsRead = 'mark_group_msg_as_read', MarkGroupMsgAsRead = 'mark_group_msg_as_read',
GoCQHTTP_UploadGroupFile = 'upload_group_file', GoCQHTTP_UploadGroupFile = 'upload_group_file',
GOCQHTTP_DeleteGroupFile = 'delete_group_file', GOCQHTTP_DeleteGroupFile = 'delete_group_file',
GOCQHTTP_GetGroupFileUrl = 'get_group_file_url',
GoCQHTTP_CreateGroupFileFolder = 'create_group_file_folder', GoCQHTTP_CreateGroupFileFolder = 'create_group_file_folder',
GoCQHTTP_DeleteGroupFileFolder = 'delete_group_file_folder', GoCQHTTP_DeleteGroupFileFolder = 'delete_group_file_folder',
GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info', GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info',