mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: add action get_group_file_url
This commit is contained in:
37
src/onebot/action/file/GetGroupFileUrl.ts
Normal file
37
src/onebot/action/file/GetGroupFileUrl.ts
Normal 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!');
|
||||
}
|
||||
}
|
@@ -90,6 +90,7 @@ import { SetSpecialTittle } from './extends/SetSpecialTittle';
|
||||
import { UploadForwardMsg } from "@/onebot/action/extends/UploadForwardMsg";
|
||||
import { GetGroupShutList } from './group/GetGroupShutList';
|
||||
import { GetGroupMemberList } from './group/GetGroupMemberList';
|
||||
import { GetGroupFileUrl } from "@/onebot/action/file/GetGroupFileUrl";
|
||||
|
||||
|
||||
export type ActionMap = Map<string, BaseAction<any, any>>;
|
||||
@@ -192,6 +193,7 @@ export function createActionMap(obContext: NapCatOneBot11Adapter, core: NapCatCo
|
||||
new SetSpecialTittle(obContext, core),
|
||||
new UploadForwardMsg(obContext, core),
|
||||
new GetGroupShutList(obContext, core),
|
||||
new GetGroupFileUrl(obContext, core),
|
||||
];
|
||||
const actionMap = new Map();
|
||||
for (const action of actionHandlers) {
|
||||
|
@@ -85,6 +85,7 @@ export enum ActionName {
|
||||
MarkGroupMsgAsRead = 'mark_group_msg_as_read',
|
||||
GoCQHTTP_UploadGroupFile = 'upload_group_file',
|
||||
GOCQHTTP_DeleteGroupFile = 'delete_group_file',
|
||||
GOCQHTTP_GetGroupFileUrl = 'get_group_file_url',
|
||||
GoCQHTTP_CreateGroupFileFolder = 'create_group_file_folder',
|
||||
GoCQHTTP_DeleteGroupFileFolder = 'delete_group_file_folder',
|
||||
GoCQHTTP_GetGroupFileSystemInfo = 'get_group_file_system_info',
|
||||
|
Reference in New Issue
Block a user