mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 08:10:25 +00:00
style: 强类型大法
This commit is contained in:
@@ -8,10 +8,13 @@ const SchemaData = Type.Object({
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class CreateGroupFileFolder extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_CreateGroupFileFolder;
|
||||
payloadSchema = SchemaData;
|
||||
interface ResponseType{
|
||||
result:unknown;
|
||||
groupItem:unknown;
|
||||
}
|
||||
export class CreateGroupFileFolder extends OneBotAction<Payload, ResponseType> {
|
||||
override actionName = ActionName.GoCQHTTP_CreateGroupFileFolder;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
return (await this.core.apis.GroupApi.creatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
@@ -11,9 +12,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class DeleteGroupFile extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
||||
payloadSchema = SchemaData;
|
||||
export class DeleteGroupFile extends OneBotAction<Payload, Awaited<ReturnType<NTQQGroupApi['delGroupFile']>>> {
|
||||
override actionName = ActionName.GOCQHTTP_DeleteGroupFile;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
const data = FileNapCatOneBotUUID.decodeModelId(payload.file_id);
|
||||
if (!data || !data.fileId) throw new Error('Invalid file_id');
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { NTQQGroupApi } from '@/core/apis';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
@@ -10,9 +11,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class DeleteGroupFileFolder extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
||||
payloadSchema = SchemaData;
|
||||
export class DeleteGroupFileFolder extends OneBotAction<Payload, Awaited<ReturnType<NTQQGroupApi['delGroupFileFolder']>>['groupFileCommonResult']> {
|
||||
override actionName = ActionName.GoCQHTTP_DeleteGroupFileFolder;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
return (await this.core.apis.GroupApi.delGroupFileFolder(
|
||||
payload.group_id.toString(), payload.folder ?? payload.folder_id ?? '')).groupFileCommonResult;
|
||||
|
||||
@@ -20,8 +20,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPDownloadFile extends OneBotAction<Payload, FileResponse> {
|
||||
actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_DownloadFile;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload): Promise<FileResponse> {
|
||||
const isRandomName = !payload.name;
|
||||
|
||||
@@ -11,9 +11,11 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||
payloadSchema = SchemaData;
|
||||
export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, {
|
||||
messages: OB11Message[] | undefined;
|
||||
}> {
|
||||
override actionName = ActionName.GoCQHTTP_GetForwardMsg;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
private createTemplateNode(message: OB11Message): OB11MessageNode {
|
||||
return {
|
||||
@@ -49,7 +51,7 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
||||
return retMsg;
|
||||
}
|
||||
|
||||
async _handle(payload: Payload): Promise<any> {
|
||||
async _handle(payload: Payload) {
|
||||
const msgId = payload.message_id || payload.id;
|
||||
if (!msgId) {
|
||||
throw new Error('message_id is required');
|
||||
@@ -67,6 +69,9 @@ export class GoCQHTTPGetForwardMsgAction extends OneBotAction<Payload, any> {
|
||||
}
|
||||
|
||||
const singleMsg = data.msgList[0];
|
||||
if (!singleMsg) {
|
||||
throw new Error('找不到相关的聊天记录');
|
||||
}
|
||||
const resMsg = (await this.obContext.apis.MsgApi.parseMessageV2(singleMsg))?.arrayMsg;//强制array 以便处理
|
||||
if (!(resMsg?.message?.[0] as OB11MessageForward)?.data?.content) {
|
||||
throw new Error('找不到相关的聊天记录');
|
||||
|
||||
@@ -21,10 +21,10 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class GetFriendMsgHistory extends OneBotAction<Payload, Response> {
|
||||
actionName = ActionName.GetFriendMsgHistory;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GetFriendMsgHistory;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig): Promise<Response> {
|
||||
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise<Response> {
|
||||
//处理参数
|
||||
const uid = await this.core.apis.UserApi.getUidByUinV2(payload.user_id.toString());
|
||||
|
||||
|
||||
@@ -7,10 +7,14 @@ const SchemaData = Type.Object({
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
|
||||
payloadSchema = SchemaData;
|
||||
interface ResponseType {
|
||||
can_at_all: boolean;
|
||||
remain_at_all_count_for_group: number;
|
||||
remain_at_all_count_for_uin: number;
|
||||
}
|
||||
export class GoCQHTTPGetGroupAtAllRemain extends OneBotAction<Payload, ResponseType> {
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupAtAllRemain;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const ret = await this.core.apis.GroupApi.getGroupRemainAtTimes(payload.group_id.toString());
|
||||
|
||||
@@ -14,15 +14,16 @@ export class GetGroupFileSystemInfo extends OneBotAction<Payload, {
|
||||
used_space: number, // TODO:unimplemented, but can be implemented later
|
||||
total_space: number, // unimplemented, 10 GB by default
|
||||
}> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupFileSystemInfo;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const groupFileCount = (await this.core.apis.GroupApi.getGroupFileCount([payload.group_id.toString()])).groupFileCounts[0];
|
||||
if (!groupFileCount) {
|
||||
throw new Error('Group not found');
|
||||
}
|
||||
return {
|
||||
file_count:
|
||||
(await this.core.apis.GroupApi
|
||||
.getGroupFileCount([payload.group_id.toString()]))
|
||||
.groupFileCounts[0],
|
||||
file_count: groupFileCount,
|
||||
limit_count: 10000,
|
||||
used_space: 0,
|
||||
total_space: 10 * 1024 * 1024 * 1024,
|
||||
|
||||
@@ -13,9 +13,12 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetGroupFilesByFolder extends OneBotAction<any, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
|
||||
payloadSchema = SchemaData;
|
||||
export class GetGroupFilesByFolder extends OneBotAction<Payload, {
|
||||
files: ReturnType<typeof OB11Construct.file>[],
|
||||
folders: never[],
|
||||
}> {
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupFilesByFolder;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
|
||||
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
|
||||
@@ -10,9 +10,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetGroupHonorInfo extends OneBotAction<Payload, Array<any>> {
|
||||
actionName = ActionName.GetGroupHonorInfo;
|
||||
payloadSchema = SchemaData;
|
||||
export class GetGroupHonorInfo extends OneBotAction<Payload, Array<unknown>> {
|
||||
override actionName = ActionName.GetGroupHonorInfo;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
if (!payload.type) {
|
||||
|
||||
@@ -22,10 +22,10 @@ type Payload = Static<typeof SchemaData>;
|
||||
|
||||
|
||||
export default class GoCQHTTPGetGroupMsgHistory extends OneBotAction<Payload, Response> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload, adapter: string, config: NetworkAdapterConfig): Promise<Response> {
|
||||
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig): Promise<Response> {
|
||||
//处理参数
|
||||
const isReverseOrder = typeof payload.reverseOrder === 'string' ? payload.reverseOrder === 'true' : !!payload.reverseOrder;
|
||||
const peer: Peer = { chatType: ChatType.KCHATTYPEGROUP, peerUid: payload.group_id.toString() };
|
||||
|
||||
@@ -16,8 +16,8 @@ export class GetGroupRootFiles extends OneBotAction<Payload, {
|
||||
files: OB11GroupFile[],
|
||||
folders: OB11GroupFileFolder[],
|
||||
}> {
|
||||
actionName = ActionName.GoCQHTTP_GetGroupRootFiles;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_GetGroupRootFiles;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
const ret = await this.core.apis.MsgApi.getGroupFileList(payload.group_id.toString(), {
|
||||
sortType: 1,
|
||||
|
||||
@@ -2,10 +2,9 @@ import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { sleep } from '@/common/helper';
|
||||
|
||||
export class GetOnlineClient extends OneBotAction<void, Array<any>> {
|
||||
actionName = ActionName.GetOnlineClient;
|
||||
|
||||
async _handle(payload: void) {
|
||||
export class GetOnlineClient extends OneBotAction<void, Array<void>> {
|
||||
override actionName = ActionName.GetOnlineClient;
|
||||
async _handle() {
|
||||
//注册监听
|
||||
this.core.apis.SystemApi.getOnlineDev();
|
||||
await sleep(500);
|
||||
|
||||
@@ -11,10 +11,10 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User> {
|
||||
actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload): Promise<OB11User> {
|
||||
export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11User & { uid: string }> {
|
||||
override actionName = ActionName.GoCQHTTP_GetStrangerInfo;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
const user_id = payload.user_id.toString();
|
||||
const extendData = await this.core.apis.UserApi.getUserDetailInfoByUin(user_id);
|
||||
let uid = (await this.core.apis.UserApi.getUidByUinV2(user_id));
|
||||
@@ -28,7 +28,7 @@ export default class GoCQHTTPGetStrangerInfo extends OneBotAction<Payload, OB11U
|
||||
...extendData.detail.simpleInfo.status ?? {},
|
||||
user_id: parseInt(extendData.detail.uin) ?? 0,
|
||||
uid: info.uid ?? uid,
|
||||
nickname: extendData.detail.simpleInfo.coreInfo.nick,
|
||||
nickname: extendData.detail.simpleInfo.coreInfo.nick ?? '',
|
||||
age: extendData.detail.simpleInfo.baseInfo.age ?? info.age,
|
||||
qid: extendData.detail.simpleInfo.baseInfo.qid,
|
||||
qqLevel: calcQQLevel(extendData.detail.commonExt?.qqLevel ?? info.qqLevel),
|
||||
|
||||
@@ -8,11 +8,11 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPCheckUrlSafely extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
||||
payloadSchema = SchemaData;
|
||||
export class GoCQHTTPCheckUrlSafely extends OneBotAction<Payload, { level: number }> {
|
||||
override actionName = ActionName.GoCQHTTP_CheckUrlSafely;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
async _handle() {
|
||||
return { level: 1 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPDeleteFriend extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_DeleteFriend;
|
||||
payloadSchema = SchemaData;
|
||||
export class GoCQHTTPDeleteFriend extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GoCQHTTP_DeleteFriend;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const uin = payload.friend_id ?? payload.user_id ?? '';
|
||||
|
||||
@@ -3,14 +3,19 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
model: Type.String(),
|
||||
model: Type.String(),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GoCQHTTPGetModelShow extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.GoCQHTTP_GetModelShow;
|
||||
payloadSchema = SchemaData;
|
||||
export class GoCQHTTPGetModelShow extends OneBotAction<Payload, Array<{
|
||||
variants: {
|
||||
model_show: string;
|
||||
need_pay: boolean;
|
||||
}
|
||||
}>> {
|
||||
override actionName = ActionName.GoCQHTTP_GetModelShow;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
if (!payload.model) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
//兼容性代码
|
||||
export class GoCQHTTPSetModelShow extends OneBotAction<void, any> {
|
||||
actionName = ActionName.GoCQHTTP_SetModelShow;
|
||||
export class GoCQHTTPSetModelShow extends OneBotAction<void, void> {
|
||||
override actionName = ActionName.GoCQHTTP_SetModelShow;
|
||||
|
||||
async _handle(payload: void) {
|
||||
return null;
|
||||
async _handle() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ interface Payload {
|
||||
}
|
||||
|
||||
export class GoCQHTTPHandleQuickAction extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
override actionName = ActionName.GoCQHTTP_HandleQuickAction;
|
||||
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
this.obContext.apis.QuickActionApi
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
import SendMsg, { normalize } from '@/onebot/action/msg/SendMsg';
|
||||
import { normalize, SendMsgBase } from '@/onebot/action/msg/SendMsg';
|
||||
import { OB11PostSendMsg } from '@/onebot/types';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
|
||||
// 未验证
|
||||
export class GoCQHTTPSendForwardMsg extends SendMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
protected async check(payload: OB11PostSendMsg) {
|
||||
export class GoCQHTTPSendForwardMsgBase extends SendMsgBase {
|
||||
protected override async check(payload: OB11PostSendMsg) {
|
||||
if (payload.messages) payload.message = normalize(payload.messages);
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
export class GoCQHTTPSendForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionName = ActionName.GoCQHTTP_SendForwardMsg;
|
||||
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
protected override async check(payload: OB11PostSendMsg) {
|
||||
if (payload.messages) payload.message = normalize(payload.messages);
|
||||
return super.check(payload);
|
||||
}
|
||||
}
|
||||
export class GoCQHTTPSendPrivateForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionName = ActionName.GoCQHTTP_SendPrivateForwardMsg;
|
||||
}
|
||||
|
||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsg {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
export class GoCQHTTPSendGroupForwardMsg extends GoCQHTTPSendForwardMsgBase {
|
||||
override actionName = ActionName.GoCQHTTP_SendGroupForwardMsg;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SendGroupNotice extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
|
||||
override actionName = ActionName.GoCQHTTP_SendGroupNotice;
|
||||
override payloadSchema = SchemaData;
|
||||
async _handle(payload: Payload) {
|
||||
|
||||
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ActionName } from '@/onebot/action/router';
|
||||
import { checkFileExistV2, uriToLocalFile } from '@/common/file';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import fs from 'node:fs/promises';
|
||||
import { GeneralCallResult } from '@/core';
|
||||
const SchemaData = Type.Object({
|
||||
file: Type.String(),
|
||||
group_id: Type.Union([Type.Number(), Type.String()])
|
||||
@@ -10,11 +11,11 @@ const SchemaData = Type.Object({
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class SetGroupPortrait extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.SetGroupPortrait;
|
||||
payloadSchema = SchemaData;
|
||||
export default class SetGroupPortrait extends OneBotAction<Payload, GeneralCallResult> {
|
||||
override actionName = ActionName.SetGroupPortrait;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload): Promise<any> {
|
||||
async _handle(payload: Payload): Promise<GeneralCallResult> {
|
||||
const { path, success } = (await uriToLocalFile(this.core.NapCatTempPath, payload.file));
|
||||
if (!success) {
|
||||
throw new Error(`头像${payload.file}设置失败,file字段可能格式不正确`);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import { OneBotAction } from '@/onebot/action/OneBotAction';
|
||||
import { ActionName } from '@/onebot/action/router';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
@@ -9,10 +10,9 @@ const SchemaData = Type.Object({
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class SetQQProfile extends OneBotAction<Payload, any> {
|
||||
actionName = ActionName.SetQQProfile;
|
||||
payloadSchema = SchemaData;
|
||||
export class SetQQProfile extends OneBotAction<Payload, Awaited<ReturnType<NTQQUserApi['modifySelfProfile']>> | null> {
|
||||
override actionName = ActionName.SetQQProfile;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload) {
|
||||
const self = this.core.selfInfo;
|
||||
|
||||
@@ -17,8 +17,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_UploadGroupFile;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async _handle(payload: Payload): Promise<null> {
|
||||
let file = payload.file;
|
||||
@@ -38,7 +38,7 @@ export default class GoCQHTTPUploadGroupFile extends OneBotAction<Payload, null>
|
||||
deleteAfterSentFiles: []
|
||||
};
|
||||
const sendFileEle = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name, payload.folder ?? payload.folder_id);
|
||||
await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles, true);
|
||||
await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(peer, [sendFileEle], msgContext.deleteAfterSentFiles);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ const SchemaData = Type.Object({
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, null> {
|
||||
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GOCQHTTP_UploadPrivateFile;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
async getPeer(payload: Payload): Promise<Peer> {
|
||||
if (payload.user_id) {
|
||||
@@ -43,13 +43,12 @@ export default class GoCQHTTPUploadPrivateFile extends OneBotAction<Payload, nul
|
||||
|
||||
const msgContext: SendMessageContext = {
|
||||
peer: await createContext(this.core, {
|
||||
user_id: payload.user_id.toString(),
|
||||
group_id: undefined,
|
||||
user_id: payload.user_id.toString()
|
||||
}, ContextMode.Private),
|
||||
deleteAfterSentFiles: []
|
||||
};
|
||||
const sendFileEle: SendFileElement = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name);
|
||||
await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(await this.getPeer(payload), [sendFileEle], msgContext.deleteAfterSentFiles, true);
|
||||
await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(await this.getPeer(payload), [sendFileEle], msgContext.deleteAfterSentFiles);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user