chore: run a full eslint

This commit is contained in:
Wesley F. Young
2024-08-10 19:58:31 +08:00
parent 9a9511aad6
commit 116a04e081
198 changed files with 8187 additions and 7744 deletions

View File

@@ -11,10 +11,12 @@ class BaseAction<PayloadType, ReturnDataType> {
private validate: undefined | ValidateFunction<any> = undefined;
PayloadSchema: any = undefined;
OneBotContext: NapCatOneBot11Adapter;
constructor(onebotContext:NapCatOneBot11Adapter,coreContext: NapCatCore) {
constructor(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
this.OneBotContext = onebotContext;
this.CoreContext = coreContext;
}
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
if (this.PayloadSchema) {
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema);
@@ -26,11 +28,11 @@ class BaseAction<PayloadType, ReturnDataType> {
});
return {
valid: false,
message: errorMessages.join('\n') as string || '未知错误'
message: errorMessages.join('\n') as string || '未知错误',
};
}
return {
valid: true
valid: true,
};
}

View File

@@ -10,7 +10,7 @@ export class OB11Response {
data: data,
message: message,
wording: message,
echo: null
echo: null,
};
}

View File

@@ -1,11 +1,12 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
rawData: { type: 'string' },
brief: { type: 'string' }
brief: { type: 'string' },
},
required: ['brief', 'rawData'],
} as const satisfies JSONSchema;
@@ -15,12 +16,13 @@ type Payload = FromSchema<typeof SchemaData>;
export class CreateCollection extends BaseAction<Payload, any> {
actionName = ActionName.CreateCollection;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
return await this.CoreContext.getApiContext().CollectionApi.createCollection(
this.CoreContext.selfInfo.uin,
this.CoreContext.selfInfo.uid,
this.CoreContext.selfInfo.nick,
payload.brief, payload.rawData
payload.brief, payload.rawData,
);
}
}

View File

@@ -1,11 +1,12 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
const SchemaData = {
type: 'object',
properties: {
count: { type: 'number' },
}
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -13,8 +14,9 @@ type Payload = FromSchema<typeof SchemaData>;
export class FetchCustomFace extends BaseAction<Payload, string[]> {
actionName = ActionName.FetchCustomFace;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48);
return ret.emojiInfoList.map(e => e.url);
}

View File

@@ -12,9 +12,9 @@ const SchemaData = {
emojiId: { type: 'string' },
emojiType: { type: 'string' },
message_id: { type: ['string', 'number'] },
count: { type: 'number' }
count: { type: 'number' },
},
required: ['emojiId', 'emojiType', 'message_id']
required: ['emojiId', 'emojiType', 'message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -22,10 +22,11 @@ type Payload = FromSchema<typeof SchemaData>;
export class FetchEmojiLike extends BaseAction<Payload, any> {
actionName = ActionName.FetchEmojiLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
if(!msgIdPeer) throw new Error('消息不存在');
if (!msgIdPeer) throw new Error('消息不存在');
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
return await NTQQMsgApi.getMsgEmojiLikesList(msgIdPeer.Peer, msg.msgSeq, payload.emojiId, payload.emojiType, payload.count);
}

View File

@@ -1,4 +1,3 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -7,7 +6,7 @@ const SchemaData = {
type: 'object',
properties: {
category: { type: 'number' },
count: { type: 'number' }
count: { type: 'number' },
},
required: ['category', 'count'],
} as const satisfies JSONSchema;
@@ -17,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetCollectionList extends BaseAction<Payload, any> {
actionName = ActionName.GetCollectionList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQCollectionApi = this.CoreContext.getApiContext().CollectionApi;
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);

View File

@@ -1,4 +1,3 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { OB11Constructor } from '@/onebot/helper/constructor';

View File

@@ -1,11 +1,10 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQGroupApi } from '@/core/apis/group';
interface OB11GroupRequestNotify {
group_id: number,
user_id: number,
flag: string
group_id: number,
user_id: number,
flag: string
}
export default class GetGroupAddRequest extends BaseAction<null, OB11GroupRequestNotify[] | null> {

View File

@@ -1,7 +1,9 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
export class GetProfileLike extends BaseAction<void, any> {
actionName = ActionName.GetProfileLike;
protected async _handle(payload: void) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const ret = await NTQQUserApi.getProfileLike(this.CoreContext.selfInfo.uid);

View File

@@ -1,11 +1,11 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQUserApi } from '@/core/apis';
export class GetRobotUinRange extends BaseAction<void, Array<any>> {
actionName = ActionName.GetRobotUinRange;
protected async _handle(payload: void) {
// console.log(await NTQQUserApi.getRobotUinRange());
// console.log(await NTQQUserApi.getRobotUinRange());
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
return await NTQQUserApi.getRobotUinRange();
}

View File

@@ -9,7 +9,7 @@ const SchemaData = {
properties: {
image: { type: 'string' },
},
required: ['image']
required: ['image'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,9 +17,10 @@ type Payload = FromSchema<typeof SchemaData>;
export class OCRImage extends BaseAction<Payload, any> {
actionName = ActionName.OCRImage;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
const { path, isLocal, errMsg,success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
if (!success) {
throw `OCR ${payload.image}失败,image字段可能格式不正确`;
}
@@ -27,7 +28,8 @@ export class OCRImage extends BaseAction<Payload, any> {
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃需要提前判断
const ret = await NTQQSystemApi.ORCImage(path);
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
if (!ret) {
throw `OCR ${payload.file}失败`;
@@ -35,11 +37,13 @@ export class OCRImage extends BaseAction<Payload, any> {
return ret.result;
}
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
throw `OCR ${payload.file}失败,文件可能不存在`;
}
}
export class IOCRImage extends OCRImage {
actionName = ActionName.IOCRImage;
}

View File

@@ -1,17 +1,18 @@
import BaseAction from '../BaseAction';
import { ActionName, BaseCheckResult } from '../types';
import * as fs from 'node:fs';
import { NTQQUserApi } from '@/core/apis/user';
import { checkFileReceived, uri2local } from '@/common/utils/file';
// import { log } from "../../../common/utils";
interface Payload {
file: string,
groupCode: string
file: string,
groupCode: string
}
export default class SetGroupHeader extends BaseAction<Payload, any> {
actionName = ActionName.SetGroupHeader;
// 用不着复杂检测
protected async check(payload: Payload): Promise<BaseCheckResult> {
if (!payload.file || typeof payload.file != 'string' || !payload.groupCode || typeof payload.groupCode != 'string') {
@@ -24,6 +25,7 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
valid: true,
};
}
protected async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
@@ -34,7 +36,8 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃需要提前判断
const ret = await NTQQGroupApi.setGroupAvatar(payload.groupCode, path);
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
if (!ret) {
throw `头像${payload.file}设置失败,api无返回`;
@@ -48,7 +51,8 @@ export default class SetGroupHeader extends BaseAction<Payload, any> {
return ret;
} else {
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
}

View File

@@ -1,7 +1,5 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQUserApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
@@ -9,7 +7,7 @@ const SchemaData = {
properties: {
longNick: { type: 'string' },
},
required: [ 'longNick'],
required: ['longNick'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +15,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class SetLongNick extends BaseAction<Payload, any> {
actionName = ActionName.SetLongNick;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const ret = await NTQQUserApi.setLongNick(payload.longNick);

View File

@@ -1,6 +1,5 @@
import BaseAction from '../BaseAction';
import { ActionName, BaseCheckResult } from '../types';
import { NTQQUserApi } from '@/core/apis';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
// 设置在线状态
@@ -9,7 +8,7 @@ const SchemaData = {
properties: {
status: { type: 'number' },
extStatus: { type: 'number' },
batteryStatus: { type: 'number' }
batteryStatus: { type: 'number' },
},
required: ['status', 'extStatus', 'batteryStatus'],
} as const satisfies JSONSchema;
@@ -19,13 +18,14 @@ type Payload = FromSchema<typeof SchemaData>;
export class SetOnlineStatus extends BaseAction<Payload, null> {
actionName = ActionName.SetOnlineStatus;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
// 可设置状态
// { status: 10, extStatus: 1027, batteryStatus: 0 }
// { status: 30, extStatus: 0, batteryStatus: 0 }
// { status: 50, extStatus: 0, batteryStatus: 0 }
// { status: 60, extStatus: 0, batteryStatus: 0 }
// { status: 70, extStatus: 0, batteryStatus: 0 }
// 可设置状态
// { status: 10, extStatus: 1027, batteryStatus: 0 }
// { status: 30, extStatus: 0, batteryStatus: 0 }
// { status: 50, extStatus: 0, batteryStatus: 0 }
// { status: 60, extStatus: 0, batteryStatus: 0 }
// { status: 70, extStatus: 0, batteryStatus: 0 }
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const ret = await NTQQUserApi.setSelfOnlineStatus(payload.status, payload.extStatus, payload.batteryStatus);
if (ret.result !== 0) {

View File

@@ -2,12 +2,14 @@ import BaseAction from '../BaseAction';
import { ActionName, BaseCheckResult } from '../types';
import * as fs from 'node:fs';
import { checkFileReceived, uri2local } from '@/common/utils/file';
interface Payload {
file: string
file: string;
}
export default class SetAvatar extends BaseAction<Payload, null> {
actionName = ActionName.SetQQAvatar;
// 用不着复杂检测
protected async check(payload: Payload): Promise<BaseCheckResult> {
if (!payload.file || typeof payload.file != 'string') {
@@ -20,6 +22,7 @@ export default class SetAvatar extends BaseAction<Payload, null> {
valid: true,
};
}
protected async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const { path, isLocal, errMsg, success } = (await uri2local(this.CoreContext.NapCatTempPath, payload.file));
@@ -30,7 +33,8 @@ export default class SetAvatar extends BaseAction<Payload, null> {
await checkFileReceived(path, 5000); // 文件不存在QQ会崩溃需要提前判断
const ret = await NTQQUserApi.setQQAvatar(path);
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
if (!ret) {
throw `头像${payload.file}设置失败,api无返回`;
@@ -43,7 +47,8 @@ export default class SetAvatar extends BaseAction<Payload, null> {
}
} else {
if (!isLocal) {
fs.unlink(path, () => { });
fs.unlink(path, () => {
});
}
throw `头像${payload.file}设置失败,无法获取头像,文件可能不存在`;
}

View File

@@ -1,4 +1,3 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -8,7 +7,7 @@ const SchemaData = {
properties: {
nick: { type: 'string' },
longNick: { type: 'string' },
sex: { type: 'number' }//传Sex值建议传0
sex: { type: 'number' },//传Sex值建议传0
},
required: ['nick', 'longNick', 'sex'],
} as const satisfies JSONSchema;
@@ -18,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class SetSelfProfile extends BaseAction<Payload, any | null> {
actionName = ActionName.SetSelfProfile;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const ret = await NTQQUserApi.modifySelfProfile({
@@ -25,7 +25,7 @@ export class SetSelfProfile extends BaseAction<Payload, any | null> {
longNick: payload.longNick,
sex: payload.sex,
birthday: { birthday_year: '', birthday_month: '', birthday_day: '' },
location: undefined
location: undefined,
});
return ret;
}

View File

@@ -1,6 +1,5 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQSystemApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
@@ -8,8 +7,8 @@ const SchemaData = {
properties: {
words: {
type: 'array',
items: { type: 'string' }
}
items: { type: 'string' },
},
},
required: ['words'],
} as const satisfies JSONSchema;
@@ -19,6 +18,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class TranslateEnWordToZn extends BaseAction<Payload, Array<any> | null> {
actionName = ActionName.TranslateEnWordToZn;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
const ret = await NTQQSystemApi.translateEnWordToZn(payload.words);

View File

@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class sharePeer extends BaseAction<Payload, any> {
actionName = ActionName.SharePeer;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
@@ -27,20 +28,23 @@ export class sharePeer extends BaseAction<Payload, any> {
}
}
}
const SchemaDataGroupEx = {
type: 'object',
properties: {
group_id: { type: 'string' },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type PayloadGroupEx = FromSchema<typeof SchemaDataGroupEx>;
export class shareGroupEx extends BaseAction<PayloadGroupEx, any> {
actionName = ActionName.ShareGroupEx;
PayloadSchema = SchemaDataGroupEx;
protected async _handle(payload: PayloadGroupEx) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
return await NTQQGroupApi.getArkJsonGroupShare(payload.group_id);
}
}
}

View File

@@ -1,13 +1,14 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['string', 'number'] },
file_id: { type: 'string' },
},
required: ['group_id', 'file_id']
required: ['group_id', 'file_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -15,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class DelGroupFile extends BaseAction<Payload, any> {
actionName = ActionName.DelGroupFile;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
return await NTQQGroupApi.DelGroupFile(payload.group_id.toString(), [payload.file_id]);

View File

@@ -1,7 +1,6 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQGroupApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
const SchemaData = {
type: 'object',
@@ -9,7 +8,7 @@ const SchemaData = {
group_id: { type: ['string', 'number'] },
folder_id: { type: 'string' },
},
required: ['group_id', 'folder_id']
required: ['group_id', 'folder_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class DelGroupFileFolder extends BaseAction<Payload, any> {
actionName = ActionName.DelGroupFileFolder;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
return (await NTQQGroupApi.DelGroupFileFolder(payload.group_id.toString(), payload.folder_id)).groupFileCommonResult;

View File

@@ -6,26 +6,28 @@ import { ChatType, ElementType, FileElement, Peer, RawMessage, VideoElement } fr
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
export interface GetFilePayload {
file: string; // 文件名或者fileUuid
file: string; // 文件名或者fileUuid
}
export interface GetFileResponse {
file?: string; // path
url?: string;
file_size?: string;
file_name?: string;
base64?: string;
file?: string; // path
url?: string;
file_size?: string;
file_name?: string;
base64?: string;
}
const GetFileBase_PayloadSchema = {
type: 'object',
properties: {
file: { type: 'string' }
file: { type: 'string' },
},
required: ['file']
required: ['file'],
} as const satisfies JSONSchema;
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
PayloadSchema: any = GetFileBase_PayloadSchema;
private getElement(msg: RawMessage): { id: string, element: VideoElement | FileElement } {
let element = msg.elements.find(e => e.fileElement);
if (!element) {
@@ -38,6 +40,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
}
return { id: element.elementId, element: element.fileElement };
}
protected async _handle(payload: GetFilePayload): Promise<GetFileResponse> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
@@ -45,9 +48,9 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const NTQQFileApi = this.CoreContext.getApiContext().FileApi;
let UuidData: {
high: string;
low: string;
} | undefined;
high: string;
low: string;
} | undefined;
try {
UuidData = UUIDConverter.decode(payload.file);
if (UuidData) {
@@ -87,7 +90,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
file: downloadPath,
url: downloadPath,
file_size: fileSize,
file_name: fileName
file_name: fileName,
};
if (true/*enableLocalFile2Url*/) {
try {
@@ -127,7 +130,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
file: downloadPath,
url: downloadPath,
file_size: NTSearchNameResult[0].fileSize.toString(),
file_name: NTSearchNameResult[0].fileName
file_name: NTSearchNameResult[0].fileName,
};
if (true/*enableLocalFile2Url*/) {
try {
@@ -182,24 +185,24 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
// // }
// }
// }
// // log('file found', cache);
// const res: GetFileResponse = {
// file: cache.path,
// url: cache.url,
// file_size: cache.size.toString(),
// file_name: cache.name
// };
// if (enableLocalFile2Url) {
// if (!cache.url) {
// try {
// res.base64 = await fs.readFile(cache.path, 'base64');
// } catch (e) {
// throw new Error('文件下载失败. ' + e);
// }
// }
// }
//return res;
// }
// // log('file found', cache);
// const res: GetFileResponse = {
// file: cache.path,
// url: cache.url,
// file_size: cache.size.toString(),
// file_name: cache.name
// };
// if (enableLocalFile2Url) {
// if (!cache.url) {
// try {
// res.base64 = await fs.readFile(cache.path, 'base64');
// } catch (e) {
// throw new Error('文件下载失败. ' + e);
// }
// }
// }
//return res;
}
}
@@ -207,20 +210,21 @@ const GetFile_PayloadSchema = {
type: 'object',
properties: {
file_id: { type: 'string' },
file: { type: 'string' }
file: { type: 'string' },
},
required: ['file_id']
required: ['file_id'],
} as const satisfies JSONSchema;
type GetFile_Payload_Internal = FromSchema<typeof GetFile_PayloadSchema>;
interface GetFile_Payload extends GetFile_Payload_Internal {
file: string
file: string;
}
export default class GetFile extends GetFileBase {
actionName = ActionName.GetFile;
PayloadSchema = GetFile_PayloadSchema;
protected async _handle(payload: GetFile_Payload): Promise<GetFileResponse> {
payload.file = payload.file_id;
return super._handle(payload);

View File

@@ -1,14 +1,13 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQGroupApi, NTQQUserApi } from '@/core/apis';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['string', 'number'] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -16,6 +15,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetGroupFileCount extends BaseAction<Payload, { count: number }> {
actionName = ActionName.GetGroupFileCount;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const ret = await NTQQGroupApi.GetGroupFileCount([payload.group_id?.toString()]);

View File

@@ -1,6 +1,7 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
const SchemaData = {
type: 'object',
properties: {
@@ -8,7 +9,7 @@ const SchemaData = {
start_index: { type: 'number' },
file_count: { type: 'number' },
},
required: ['group_id', 'start_index', 'file_count']
required: ['group_id', 'start_index', 'file_count'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -16,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any> }> {
actionName = ActionName.GetGroupFileList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const ret = await NTQQMsgApi.getGroupFileList(payload.group_id.toString(), {
@@ -23,8 +25,10 @@ export class GetGroupFileList extends BaseAction<Payload, { FileList: Array<any>
fileCount: payload.file_count,
startIndex: payload.start_index,
sortOrder: 2,
showOnlinedocFolder: 0
}).catch((e) => { return []; });
showOnlinedocFolder: 0,
}).catch((e) => {
return [];
});
return { FileList: ret };
}
}

View File

@@ -2,7 +2,7 @@ import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile';
import { ActionName } from '../types';
interface Payload extends GetFilePayload {
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac';
}
export default class GetRecord extends GetFileBase {
@@ -12,4 +12,4 @@ export default class GetRecord extends GetFileBase {
const res = super._handle(payload);
return res;
}
}
}

View File

@@ -1,13 +1,14 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['string', 'number'] },
folder_name: { type: 'string' },
},
required: ['group_id', 'folder_name']
required: ['group_id', 'folder_name'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -15,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class SetGroupFileFolder extends BaseAction<Payload, any> {
actionName = ActionName.SetGroupFileFolder;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
return (await NTQQGroupApi.CreatGroupFileFolder(payload.group_id.toString(), payload.folder_name)).resultWithGroupItem;

View File

@@ -5,9 +5,11 @@ import { join as joinPath } from 'node:path';
import { calculateFileMD5, httpDownload } from '@/common/utils/file';
import { randomUUID } from 'crypto';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
interface FileResponse {
file: string;
file: string;
}
const SchemaData = {
type: 'object',
properties: {
@@ -18,9 +20,9 @@ const SchemaData = {
headers: {
type: ['string', 'array'],
items: {
type: 'string'
}
}
type: 'string',
},
},
},
} as const satisfies JSONSchema;
@@ -29,6 +31,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GoCQHTTPDownloadFile extends BaseAction<Payload, FileResponse> {
actionName = ActionName.GoCQHTTP_DownloadFile;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<FileResponse> {
const isRandomName = !payload.name;
const name = payload.name || randomUUID();

View File

@@ -1,8 +1,7 @@
import BaseAction from '../BaseAction';
import { OB11ForwardMessage, OB11Message, OB11MessageData } from '../../types';
import { NTQQMsgApi } from '@/core/apis';
import { OB11Constructor } from '../../helper/data';
import { ActionName, BaseCheckResult } from '../types';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/utils/MessageUnique';
@@ -10,19 +9,20 @@ const SchemaData = {
type: 'object',
properties: {
message_id: { type: 'string' },
id: { type: 'string' }
id: { type: 'string' },
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
interface Response {
messages: (OB11Message & { content: OB11MessageData })[];
messages: (OB11Message & { content: OB11MessageData })[];
}
export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
actionName = ActionName.GoCQHTTP_GetForwardMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const msgId = payload.message_id || payload.id;
@@ -40,8 +40,12 @@ export class GoCQHTTPGetForwardMsgAction extends BaseAction<Payload, any> {
}
const msgList = data.msgList;
const messages = await Promise.all(msgList.map(async msg => {
const resMsg = await OB11Constructor.message(this.CoreContext, msg, "array");
resMsg.message_id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId)!;
const resMsg = await OB11Constructor.message(this.CoreContext, msg, 'array');
resMsg.message_id = MessageUnique.createMsg({
guildId: '',
chatType: msg.chatType,
peerUid: msg.peerUid,
}, msg.msgId)!;
return resMsg;
}));
messages.map(msg => {

View File

@@ -1,14 +1,13 @@
import BaseAction from '../BaseAction';
import { OB11Message, OB11User } from '../../types';
import { OB11Message } from '../../types';
import { ActionName } from '../types';
import { ChatType, RawMessage } from '@/core/entities';
import { NTQQMsgApi } from '@/core/apis/msg';
import { OB11Constructor } from '../../helper/data';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/utils/MessageUnique';
interface Response {
messages: OB11Message[];
messages: OB11Message[];
}
const SchemaData = {
@@ -17,9 +16,9 @@ const SchemaData = {
user_id: { type: ['number', 'string'] },
message_seq: { type: 'number' },
count: { type: 'number' },
reverseOrder: { type: 'boolean' }
reverseOrder: { type: 'boolean' },
},
required: ['user_id']
required: ['user_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -27,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GetFriendMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
@@ -53,7 +53,7 @@ export default class GetFriendMsgHistory extends BaseAction<Payload, Response> {
msg.id = MessageUnique.createMsg({ guildId: '', chatType: msg.chatType, peerUid: msg.peerUid }, msg.msgId);
}));
//转换消息
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
return { 'messages': ob11MsgList };
}
}

View File

@@ -1,15 +1,15 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { WebHonorType } from '@/core/entities';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] }
group_id: { type: ['number', 'string'] },
type: { enum: [WebHonorType.ALL, WebHonorType.EMOTION, WebHonorType.LEGEND, WebHonorType.PERFORMER, WebHonorType.STRONG_NEWBIE, WebHonorType.TALKATIVE] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
// enum是不是有点抽象
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetGroupHonorInfo extends BaseAction<Payload, Array<any>> {
actionName = ActionName.GetGroupHonorInfo;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
if (!payload.type) {
payload.type = WebHonorType.ALL;

View File

@@ -5,8 +5,9 @@ import { ChatType, Peer, RawMessage } from '@/core/entities';
import { OB11Constructor } from '../../helper/data';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/utils/MessageUnique';
interface Response {
messages: OB11Message[];
messages: OB11Message[];
}
const SchemaData = {
@@ -15,9 +16,9 @@ const SchemaData = {
group_id: { type: ['number', 'string'] },
message_seq: { type: 'number' },
count: { type: 'number' },
reverseOrder: { type: 'boolean' }
reverseOrder: { type: 'boolean' },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -25,6 +26,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Response> {
actionName = ActionName.GoCQHTTP_GetGroupMsgHistory;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<Response> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
//处理参数
@@ -46,7 +48,7 @@ export default class GoCQHTTPGetGroupMsgHistory extends BaseAction<Payload, Resp
}));
//转换消息
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, "array")));
const ob11MsgList = await Promise.all(msgList.map(msg => OB11Constructor.message(this.CoreContext, msg, 'array')));
return { 'messages': ob11MsgList };
}
}

View File

@@ -7,18 +7,18 @@ const SchemaData = {
type: 'object',
properties: {
no_cache: { type: 'boolean' },
}
},
} as const satisfies JSONSchema;
export class GetOnlineClient extends BaseAction<void, Array<any>> {
actionName = ActionName.GetOnlineClient;
protected async _handle(payload: void) {
//注册监听
//注册监听
const NTQQSystemApi = this.CoreContext.getApiContext().SystemApi;
NTQQSystemApi.getOnlineDev();
await sleep(500);
return [];
}
}

View File

@@ -4,12 +4,13 @@ import { OB11Constructor } from '../../helper/data';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { calcQQLevel } from '@/common/utils/helper';
const SchemaData = {
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
},
required: ['user_id']
required: ['user_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -32,7 +33,7 @@ export default class GoCQHTTPGetStrangerInfo extends BaseAction<Payload, OB11Use
qid: extendData.info.qid,
level: extendData.info.qqLevel && calcQQLevel(extendData.info.qqLevel) || 0,
login_days: 0,
uid: ''
uid: '',
};
return ret;
}

View File

@@ -3,15 +3,16 @@ import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { QuickAction, QuickActionEvent } from '@/onebot/types';
interface Payload{
context: QuickActionEvent,
operation: QuickAction
interface Payload {
context: QuickActionEvent,
operation: QuickAction
}
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null>{
export class GoCQHTTPHandleQuickAction extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_HandleQuickAction;
protected async _handle(payload: Payload): Promise<null> {
handleQuickOperation(this.CoreContext,payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
handleQuickOperation(this.CoreContext, payload.context, payload.operation).then().catch(this.CoreContext.context.logger.logError);
return null;
}
}
}

View File

@@ -1,6 +1,7 @@
import SendMsg, { normalize } from '../msg/SendMsg';
import { OB11PostSendMsg } from '../../types';
import { ActionName } from '../types';
// 未验证
export class GoCQHTTPSendForwardMsg extends SendMsg {
actionName = ActionName.GoCQHTTP_SendForwardMsg;

View File

@@ -3,6 +3,7 @@ import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { unlink } from 'node:fs';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
@@ -10,21 +11,27 @@ const SchemaData = {
content: { type: 'string' },
image: { type: 'string' },
pinned: { type: 'number' },
confirmRequired: { type: 'number' }
confirmRequired: { type: 'number' },
},
required: ['group_id', 'content']
required: ['group_id', 'content'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export class SendGroupNotice extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_SendGroupNotice;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
let UploadImage: { id: string, width: number, height: number } | undefined = undefined;
if (payload.image) {
//公告图逻辑
const { errMsg, path, isLocal, success } = (await uri2local(this.CoreContext.NapCatTempPath,payload.image));
const {
errMsg,
path,
isLocal,
success,
} = (await uri2local(this.CoreContext.NapCatTempPath, payload.image));
if (!success) {
throw `群公告${payload.image}设置失败,image字段可能格式不正确`;
}
@@ -37,7 +44,8 @@ export class SendGroupNotice extends BaseAction<Payload, null> {
throw `群公告${payload.image}设置失败,图片上传失败`;
}
if (!isLocal) {
unlink(path, () => { });
unlink(path, () => {
});
}
UploadImage = ImageUploadResult.picInfo;
}

View File

@@ -6,6 +6,7 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
import { uri2local } from '@/common/utils/file';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
const SchemaData = {
type: 'object',
properties: {
@@ -13,9 +14,9 @@ const SchemaData = {
file: { type: 'string' },
name: { type: 'string' },
folder: { type: 'string' },
folder_id: { type: 'string' }//临时扩展
folder_id: { type: 'string' },//临时扩展
},
required: ['group_id', 'file', 'name']
required: ['group_id', 'file', 'name'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -23,6 +24,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_UploadGroupFile;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
let file = payload.file;
if (fs.existsSync(file)) {
@@ -33,7 +35,10 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
throw new Error(downloadResult.errMsg);
}
const sendFileEle: SendFileElement = await SendMsgElementConstructor.file(this.CoreContext, downloadResult.path, payload.name, payload.folder_id);
await sendMsg(this.CoreContext, { chatType: ChatType.group, peerUid: payload.group_id.toString() }, [sendFileEle], [], true);
await sendMsg(this.CoreContext, {
chatType: ChatType.group,
peerUid: payload.group_id.toString(),
}, [sendFileEle], [], true);
return null;
}
}

View File

@@ -6,14 +6,15 @@ import { sendMsg } from '@/onebot/action/msg/SendMsg';
import { uri2local } from '@/common/utils/file';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
const SchemaData = {
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
file: { type: 'string' },
name: { type: 'string' }
name: { type: 'string' },
},
required: ['user_id', 'file', 'name']
required: ['user_id', 'file', 'name'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -21,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null> {
actionName = ActionName.GOCQHTTP_UploadPrivateFile;
PayloadSchema = SchemaData;
async getPeer(payload: Payload): Promise<Peer> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
@@ -34,6 +36,7 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
}
throw '缺少参数 user_id';
}
protected async _handle(payload: Payload): Promise<null> {
const peer = await this.getPeer(payload);
let file = payload.file;

View File

@@ -1,4 +1,3 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -7,9 +6,9 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
const SchemaData = {
type: 'object',
properties: {
message_id: { type: ['number', 'string'] }
message_id: { type: ['number', 'string'] },
},
required: ['message_id']
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class DelEssenceMsg extends BaseAction<Payload, any> {
actionName = ActionName.DelEssenceMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
@@ -25,7 +25,7 @@ export default class DelEssenceMsg extends BaseAction<Payload, any> {
}
return await NTQQGroupApi.removeGroupEssence(
msg.Peer.peerUid,
msg.MsgId
msg.MsgId,
);
}
}

View File

@@ -6,10 +6,10 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
group_id: { type: ['number', 'string'] },
pages: { type: 'number' },
},
required: ['group_id', 'pages']
required: ['group_id', 'pages'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetGroupEssence extends BaseAction<Payload, GroupEssenceMsgRet> {
actionName = ActionName.GoCQHTTP_GetEssenceMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
const ret = await NTQQWebApi.getGroupEssenceMsg(payload.group_id.toString(), payload.pages.toString());

View File

@@ -9,7 +9,7 @@ const SchemaData = {
properties: {
group_id: { type: ['number', 'string'] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
class GetGroupInfo extends BaseAction<Payload, OB11Group> {
actionName = ActionName.GetGroupInfo;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id.toString());

View File

@@ -9,7 +9,7 @@ const SchemaData = {
type: 'object',
properties: {
no_cache: { type: ['boolean', 'string'] },
}
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,9 +17,10 @@ type Payload = FromSchema<typeof SchemaData>;
class GetGroupList extends BaseAction<Payload, OB11Group[]> {
actionName = ActionName.GetGroupList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
const groupList: Group[] = await NTQQGroupApi.getGroups(payload?.no_cache === true || payload.no_cache === 'true');
return OB11Constructor.groups(groupList);
}
}

View File

@@ -3,6 +3,7 @@ import { OB11Constructor } from '../../helper/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
@@ -10,7 +11,7 @@ const SchemaData = {
user_id: { type: ['number', 'string'] },
no_cache: { type: ['boolean', 'string'] },
},
required: ['group_id', 'user_id']
required: ['group_id', 'user_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -18,6 +19,7 @@ type Payload = FromSchema<typeof SchemaData>;
class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
actionName = ActionName.GetGroupMemberInfo;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
@@ -74,4 +76,5 @@ class GetGroupMemberInfo extends BaseAction<Payload, OB11GroupMember> {
return retMember;
}
}
export default GetGroupMemberInfo;
export default GetGroupMemberInfo;

View File

@@ -1,16 +1,16 @@
import { OB11GroupMember } from '../../types';
import { OB11Constructor } from '../../helper/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['number', 'string'] },
no_cache: { type: ['boolean', 'string'] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -18,6 +18,7 @@ type Payload = FromSchema<typeof SchemaData>;
class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
actionName = ActionName.GetGroupMemberList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
@@ -31,7 +32,9 @@ class GetGroupMemberList extends BaseAction<Payload, OB11GroupMember[]> {
const groupMembers = await NTQQGroupApi.getGroupMembers(payload.group_id.toString());
const groupMembersArr = Array.from(groupMembers.values());
const groupMembersUids = groupMembersArr.map(e => e.uid);
let _groupMembers = groupMembersArr.map(item => { return OB11Constructor.groupMember(group.groupCode, item); });
let _groupMembers = groupMembersArr.map(item => {
return OB11Constructor.groupMember(group.groupCode, item);
});
const MemberMap: Map<number, OB11GroupMember> = new Map<number, OB11GroupMember>();
// 转为Map 方便索引

View File

@@ -2,25 +2,26 @@ import { WebApiGroupNoticeFeed } from '@/core';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
interface GroupNotice {
sender_id: number
publish_time: number
message: {
text: string
image: Array<{
height: string
width: string
id: string
}>
}
sender_id: number;
publish_time: number;
message: {
text: string
image: Array<{
height: string
width: string
id: string
}>
};
}
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
group_id: { type: ['number', 'string'] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -30,6 +31,7 @@ type ApiGroupNotice = GroupNotice & WebApiGroupNoticeFeed;
export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
actionName = ActionName.GoCQHTTP_GetGroupNotice;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
@@ -49,8 +51,8 @@ export class GetGroupNotice extends BaseAction<Payload, GroupNotice[]> {
text: retApiNotice.msg.text,
image: retApiNotice.msg.pics?.map((pic) => {
return { id: pic.id, height: pic.h, width: pic.w };
}) || []
}
}) || [],
},
};
retNotices.push(retNotice);
}

View File

@@ -5,7 +5,7 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: ['number', 'string'] }
group_id: { type: ['number', 'string'] },
},
} as const satisfies JSONSchema;
@@ -13,6 +13,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetGroupSystemMsg extends BaseAction<void, any> {
actionName = ActionName.GetGroupSystemMsg;
protected async _handle(payload: void) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;

View File

@@ -6,9 +6,9 @@ import { MessageUnique } from '@/common/utils/MessageUnique';
const SchemaData = {
type: 'object',
properties: {
message_id: { type: ['number', 'string'] }
message_id: { type: ['number', 'string'] },
},
required: ['message_id']
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -16,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetEssenceMsg extends BaseAction<Payload, any> {
actionName = ActionName.SetEssenceMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
@@ -24,7 +25,7 @@ export default class SetEssenceMsg extends BaseAction<Payload, any> {
}
return await NTQQGroupApi.addGroupEssence(
msg.Peer.peerUid,
msg.MsgId
msg.MsgId,
);
}
}

View File

@@ -1,7 +1,6 @@
import BaseAction from '../BaseAction';
import { GroupRequestOperateTypes } from '@/core/entities';
import { ActionName } from '../types';
import { NTQQGroupApi } from '@/core/apis/group';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
@@ -9,7 +8,7 @@ const SchemaData = {
properties: {
flag: { type: 'string' },
approve: { type: ['string', 'boolean'] },
reason: { type: 'string', nullable: true, }
reason: { type: 'string', nullable: true },
},
required: ['flag'],
} as const satisfies JSONSchema;
@@ -19,13 +18,14 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupAddRequest extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupAddRequest;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const flag = payload.flag.toString();
const approve = payload.approve?.toString() !== 'false';
await NTQQGroupApi.handleGroupRequest(flag,
approve ? GroupRequestOperateTypes.approve : GroupRequestOperateTypes.reject,
payload.reason || " "
payload.reason || ' ',
);
return null;
}

View File

@@ -1,17 +1,16 @@
import BaseAction from '../BaseAction';
import { GroupMemberRole } from '@/core/entities';
import { ActionName } from '../types';
import { NTQQGroupApi } from '@/core/apis/group';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
user_id: { type: [ 'number' , 'string' ] },
enable: { type: 'boolean' }
group_id: { type: ['number', 'string'] },
user_id: { type: ['number', 'string'] },
enable: { type: 'boolean' },
},
required: ['group_id', 'user_id']
required: ['group_id', 'user_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -19,11 +18,12 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupAdmin extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupAdmin;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if(!uid) throw new Error('get Uid Error');
if (!uid) throw new Error('get Uid Error');
await NTQQGroupApi.setMemberRole(payload.group_id.toString(), uid, payload.enable ? GroupMemberRole.admin : GroupMemberRole.normal);
return null;
}

View File

@@ -7,9 +7,9 @@ const SchemaData = {
properties: {
group_id: { type: ['number', 'string'] },
user_id: { type: ['number', 'string'] },
duration: { type: ['number', 'string'] }
duration: { type: ['number', 'string'] },
},
required: ['group_id', 'user_id', 'duration']
required: ['group_id', 'user_id', 'duration'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,11 +17,12 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupBan extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupBan;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if(!uid) throw new Error('uid error');
if (!uid) throw new Error('uid error');
await NTQQGroupApi.banMember(payload.group_id.toString(),
[{ uid: uid, timeStamp: parseInt(payload.duration.toString()) }]);
return null;

View File

@@ -5,11 +5,11 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
user_id: { type: [ 'number' , 'string' ] },
card: { type: 'string' }
group_id: { type: ['number', 'string'] },
user_id: { type: ['number', 'string'] },
card: { type: 'string' },
},
required: ['group_id', 'user_id', 'card']
required: ['group_id', 'user_id', 'card'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupCard extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupCard;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
await NTQQGroupApi.setMemberCard(payload.group_id.toString(), member.uid, payload.card || '');

View File

@@ -1,17 +1,16 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQGroupApi } from '@/core/apis/group';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
user_id: { type: [ 'number' , 'string' ] },
reject_add_request: { type: [ 'boolean' , 'string' ] }
group_id: { type: ['number', 'string'] },
user_id: { type: ['number', 'string'] },
reject_add_request: { type: ['boolean', 'string'] },
},
required: ['group_id', 'user_id']
required: ['group_id', 'user_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -19,12 +18,13 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupKick extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupKick;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const rejectReq = payload.reject_add_request?.toString() == 'true';
const uid = await NTQQUserApi.getUidByUin(payload.user_id.toString());
if(!uid) throw new Error('get Uid Error');
if (!uid) throw new Error('get Uid Error');
await NTQQGroupApi.kickMember(payload.group_id.toString(), [uid], rejectReq);
return null;
}

View File

@@ -1,19 +1,21 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
is_dismiss: { type: 'boolean' }
group_id: { type: ['number', 'string'] },
is_dismiss: { type: 'boolean' },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupLeave extends BaseAction<Payload, any> {
actionName = ActionName.SetGroupLeave;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<any> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
await NTQQGroupApi.quitGroup(payload.group_id.toString());

View File

@@ -1,21 +1,21 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQGroupApi } from '@/core/apis/group';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
group_name: { type: 'string' }
group_id: { type: ['number', 'string'] },
group_name: { type: 'string' },
},
required: ['group_id', 'group_name']
required: ['group_id', 'group_name'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupName extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupName;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;
await NTQQGroupApi.setGroupName(payload.group_id.toString(), payload.group_name);

View File

@@ -1,13 +1,14 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
const SchemaData = {
type: 'object',
properties: {
group_id: { type: [ 'number' , 'string' ] },
enable: { type: ['boolean','string'] }
group_id: { type: ['number', 'string'] },
enable: { type: ['boolean', 'string'] },
},
required: ['group_id']
required: ['group_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -15,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetGroupWholeBan extends BaseAction<Payload, null> {
actionName = ActionName.SetGroupWholeBan;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const enable = payload.enable?.toString() !== 'false';
const NTQQGroupApi = this.CoreContext.getApiContext().GroupApi;

View File

@@ -17,7 +17,7 @@ import GetStatus from './system/GetStatus';
import {
GoCQHTTPSendForwardMsg,
GoCQHTTPSendGroupForwardMsg,
GoCQHTTPSendPrivateForwardMsg
GoCQHTTPSendPrivateForwardMsg,
} from './go-cqhttp/SendForwardMsg';
import GoCQHTTPGetStrangerInfo from './go-cqhttp/GetStrangerInfo';
import SendLike from './user/SendLike';
@@ -78,86 +78,86 @@ import { NapCatOneBot11Adapter } from '../main';
export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
const actionHandlers = [
new FetchEmojiLike(onebotContext,coreContext),
new GetFile(onebotContext,coreContext),
new SetSelfProfile(onebotContext,coreContext),
new shareGroupEx(onebotContext,coreContext),
new sharePeer(onebotContext,coreContext),
new CreateCollection(onebotContext,coreContext),
new SetLongNick(onebotContext,coreContext),
new ForwardFriendSingleMsg(onebotContext,coreContext),
new ForwardGroupSingleMsg(onebotContext,coreContext),
new MarkGroupMsgAsRead(onebotContext,coreContext),
new MarkPrivateMsgAsRead(onebotContext,coreContext),
new SetQQAvatar(onebotContext,coreContext),
new TranslateEnWordToZn(onebotContext,coreContext),
new GetGroupFileCount(onebotContext,coreContext),
new GetGroupFileList(onebotContext,coreContext),
new SetGroupFileFolder(onebotContext,coreContext),
new DelGroupFile(onebotContext,coreContext),
new DelGroupFileFolder(onebotContext,coreContext),
new FetchEmojiLike(onebotContext, coreContext),
new GetFile(onebotContext, coreContext),
new SetSelfProfile(onebotContext, coreContext),
new shareGroupEx(onebotContext, coreContext),
new sharePeer(onebotContext, coreContext),
new CreateCollection(onebotContext, coreContext),
new SetLongNick(onebotContext, coreContext),
new ForwardFriendSingleMsg(onebotContext, coreContext),
new ForwardGroupSingleMsg(onebotContext, coreContext),
new MarkGroupMsgAsRead(onebotContext, coreContext),
new MarkPrivateMsgAsRead(onebotContext, coreContext),
new SetQQAvatar(onebotContext, coreContext),
new TranslateEnWordToZn(onebotContext, coreContext),
new GetGroupFileCount(onebotContext, coreContext),
new GetGroupFileList(onebotContext, coreContext),
new SetGroupFileFolder(onebotContext, coreContext),
new DelGroupFile(onebotContext, coreContext),
new DelGroupFileFolder(onebotContext, coreContext),
// onebot11
new SendLike(onebotContext,coreContext),
new GetMsg(onebotContext,coreContext),
new GetLoginInfo(onebotContext,coreContext),
new GetFriendList(onebotContext,coreContext),
new GetGroupList(onebotContext,coreContext),
new GetGroupInfo(onebotContext,coreContext),
new GetGroupMemberList(onebotContext,coreContext),
new GetGroupMemberInfo(onebotContext,coreContext),
new SendGroupMsg(onebotContext,coreContext),
new SendPrivateMsg(onebotContext,coreContext),
new SendMsg(onebotContext,coreContext),
new DeleteMsg(onebotContext,coreContext),
new SetGroupAddRequest(onebotContext,coreContext),
new SetFriendAddRequest(onebotContext,coreContext),
new SetGroupLeave(onebotContext,coreContext),
new GetVersionInfo(onebotContext,coreContext),
new CanSendRecord(onebotContext,coreContext),
new CanSendImage(onebotContext,coreContext),
new GetStatus(onebotContext,coreContext),
new SetGroupWholeBan(onebotContext,coreContext),
new SetGroupBan(onebotContext,coreContext),
new SetGroupKick(onebotContext,coreContext),
new SetGroupAdmin(onebotContext,coreContext),
new SetGroupName(onebotContext,coreContext),
new SetGroupCard(onebotContext,coreContext),
new GetImage(onebotContext,coreContext),
new GetRecord(onebotContext,coreContext),
new SetMsgEmojiLike(onebotContext,coreContext),
new GetCookies(onebotContext,coreContext),
new SetOnlineStatus(onebotContext,coreContext),
new GetRobotUinRange(onebotContext,coreContext),
new GetFriendWithCategory(onebotContext,coreContext),
new SendLike(onebotContext, coreContext),
new GetMsg(onebotContext, coreContext),
new GetLoginInfo(onebotContext, coreContext),
new GetFriendList(onebotContext, coreContext),
new GetGroupList(onebotContext, coreContext),
new GetGroupInfo(onebotContext, coreContext),
new GetGroupMemberList(onebotContext, coreContext),
new GetGroupMemberInfo(onebotContext, coreContext),
new SendGroupMsg(onebotContext, coreContext),
new SendPrivateMsg(onebotContext, coreContext),
new SendMsg(onebotContext, coreContext),
new DeleteMsg(onebotContext, coreContext),
new SetGroupAddRequest(onebotContext, coreContext),
new SetFriendAddRequest(onebotContext, coreContext),
new SetGroupLeave(onebotContext, coreContext),
new GetVersionInfo(onebotContext, coreContext),
new CanSendRecord(onebotContext, coreContext),
new CanSendImage(onebotContext, coreContext),
new GetStatus(onebotContext, coreContext),
new SetGroupWholeBan(onebotContext, coreContext),
new SetGroupBan(onebotContext, coreContext),
new SetGroupKick(onebotContext, coreContext),
new SetGroupAdmin(onebotContext, coreContext),
new SetGroupName(onebotContext, coreContext),
new SetGroupCard(onebotContext, coreContext),
new GetImage(onebotContext, coreContext),
new GetRecord(onebotContext, coreContext),
new SetMsgEmojiLike(onebotContext, coreContext),
new GetCookies(onebotContext, coreContext),
new SetOnlineStatus(onebotContext, coreContext),
new GetRobotUinRange(onebotContext, coreContext),
new GetFriendWithCategory(onebotContext, coreContext),
//以下为go-cqhttp api
new GetOnlineClient(onebotContext,coreContext),
new OCRImage(onebotContext,coreContext),
new IOCRImage(onebotContext,coreContext),
new GetGroupHonorInfo(onebotContext,coreContext),
new SendGroupNotice(onebotContext,coreContext),
new GetGroupNotice(onebotContext,coreContext),
new GetGroupEssence(onebotContext,coreContext),
new GoCQHTTPSendForwardMsg(onebotContext,coreContext),
new GoCQHTTPSendGroupForwardMsg(onebotContext,coreContext),
new GoCQHTTPSendPrivateForwardMsg(onebotContext,coreContext),
new GoCQHTTPGetStrangerInfo(onebotContext,coreContext),
new GoCQHTTPDownloadFile(onebotContext,coreContext),
new GetGuildList(onebotContext,coreContext),
new GoCQHTTPMarkMsgAsRead(onebotContext,coreContext),
new GoCQHTTPUploadGroupFile(onebotContext,coreContext),
new GoCQHTTPGetGroupMsgHistory(onebotContext,coreContext),
new GoCQHTTPGetForwardMsgAction(onebotContext,coreContext),
new GetFriendMsgHistory(onebotContext,coreContext),
new GoCQHTTPHandleQuickAction(onebotContext,coreContext),
new GetGroupSystemMsg(onebotContext,coreContext),
new DelEssenceMsg(onebotContext,coreContext),
new SetEssenceMsg(onebotContext,coreContext),
new GetRecentContact(onebotContext,coreContext),
new MarkAllMsgAsRead(onebotContext,coreContext),
new GetProfileLike(onebotContext,coreContext),
new SetGroupHeader(onebotContext,coreContext),
new FetchCustomFace(onebotContext,coreContext),
new GoCQHTTPUploadPrivateFile(onebotContext,coreContext)
new GetOnlineClient(onebotContext, coreContext),
new OCRImage(onebotContext, coreContext),
new IOCRImage(onebotContext, coreContext),
new GetGroupHonorInfo(onebotContext, coreContext),
new SendGroupNotice(onebotContext, coreContext),
new GetGroupNotice(onebotContext, coreContext),
new GetGroupEssence(onebotContext, coreContext),
new GoCQHTTPSendForwardMsg(onebotContext, coreContext),
new GoCQHTTPSendGroupForwardMsg(onebotContext, coreContext),
new GoCQHTTPSendPrivateForwardMsg(onebotContext, coreContext),
new GoCQHTTPGetStrangerInfo(onebotContext, coreContext),
new GoCQHTTPDownloadFile(onebotContext, coreContext),
new GetGuildList(onebotContext, coreContext),
new GoCQHTTPMarkMsgAsRead(onebotContext, coreContext),
new GoCQHTTPUploadGroupFile(onebotContext, coreContext),
new GoCQHTTPGetGroupMsgHistory(onebotContext, coreContext),
new GoCQHTTPGetForwardMsgAction(onebotContext, coreContext),
new GetFriendMsgHistory(onebotContext, coreContext),
new GoCQHTTPHandleQuickAction(onebotContext, coreContext),
new GetGroupSystemMsg(onebotContext, coreContext),
new DelEssenceMsg(onebotContext, coreContext),
new SetEssenceMsg(onebotContext, coreContext),
new GetRecentContact(onebotContext, coreContext),
new MarkAllMsgAsRead(onebotContext, coreContext),
new GetProfileLike(onebotContext, coreContext),
new SetGroupHeader(onebotContext, coreContext),
new FetchCustomFace(onebotContext, coreContext),
new GoCQHTTPUploadPrivateFile(onebotContext, coreContext),
];
const actionMap = new Map<string, BaseAction<any, any>>();
for (const action of actionHandlers) {

View File

@@ -10,11 +10,11 @@ const SchemaData = {
message_id: {
oneOf: [
{ type: 'number' },
{ type: 'string' }
]
}
{ type: 'string' },
],
},
},
required: ['message_id']
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -22,6 +22,7 @@ type Payload = FromSchema<typeof SchemaData>;
class DeleteMsg extends BaseAction<Payload, void> {
actionName = ActionName.DeleteMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(Number(payload.message_id));
@@ -36,8 +37,10 @@ class DeleteMsg extends BaseAction<Payload, void> {
return true;
}
return false;
}
).catch(e => new Promise<undefined>((resolve, reject) => { resolve(undefined); }));
},
).catch(e => new Promise<undefined>((resolve, reject) => {
resolve(undefined);
}));
await NTQQMsgApi.recallMsg(msg.Peer, [msg.MsgId]);
const data = await ret;
if (!data) {

View File

@@ -9,9 +9,9 @@ const SchemaData = {
properties: {
message_id: { type: 'number' },
group_id: { type: ['number', 'string'] },
user_id: { type: ['number', 'string'] }
user_id: { type: ['number', 'string'] },
},
required: ['message_id']
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;

View File

@@ -13,7 +13,7 @@ const SchemaData = {
properties: {
message_id: { type: ['number', 'string'] },
},
required: ['message_id']
required: ['message_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -21,6 +21,7 @@ type Payload = FromSchema<typeof SchemaData>;
class GetMsg extends BaseAction<Payload, OB11Message> {
actionName = ActionName.GetMsg;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
// log("history msg ids", Object.keys(msgHistory));
@@ -36,7 +37,7 @@ class GetMsg extends BaseAction<Payload, OB11Message> {
const msg = await NTQQMsgApi.getMsgsByMsgId(
peer,
[msgIdWithPeer?.MsgId || payload.message_id.toString()]);
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], "array");
const retMsg = await OB11Constructor.message(this.CoreContext, msg.msgList[0], 'array');
try {
retMsg.message_id = MessageUnique.createMsg(peer, msg.msgList[0].msgId)!;
retMsg.message_seq = retMsg.message_id;

View File

@@ -1,15 +1,14 @@
import { ChatType, Peer } from '@/core/entities';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQFriendApi, NTQQMsgApi, NTQQUserApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
group_id: { type: ['number', 'string'] }
}
group_id: { type: ['number', 'string'] },
},
} as const satisfies JSONSchema;
type PlayloadType = FromSchema<typeof SchemaData>;
@@ -31,6 +30,7 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
}
return { chatType: ChatType.group, peerUid: payload.group_id.toString() };
}
protected async _handle(payload: PlayloadType): Promise<null> {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
// 调用API
@@ -41,11 +41,13 @@ class MarkMsgAsRead extends BaseAction<PlayloadType, null> {
return null;
}
}
// 以下为非标准实现
export class MarkPrivateMsgAsRead extends MarkMsgAsRead {
PayloadSchema = SchemaData;
actionName = ActionName.MarkPrivateMsgAsRead;
}
export class MarkGroupMsgAsRead extends MarkMsgAsRead {
PayloadSchema = SchemaData;
actionName = ActionName.MarkGroupMsgAsRead;
@@ -53,7 +55,7 @@ export class MarkGroupMsgAsRead extends MarkMsgAsRead {
interface Payload {
message_id: number
message_id: number;
}
export class GoCQHTTPMarkMsgAsRead extends BaseAction<Payload, null> {

View File

@@ -6,16 +6,23 @@ import { AtType, CustomMusicSignPostData, IdMusicSignPostData, NapCatCore, Peer,
import { SendMsgElementConstructor } from '@/onebot/helper/msg';
export type MessageContext = {
deleteAfterSentFiles: string[],
peer: Peer
deleteAfterSentFiles: string[],
peer: Peer
}
async function handleOb11FileLikeMessage(
coreContext: NapCatCore,
{ data: inputdata }: OB11MessageFileBase,
{ deleteAfterSentFiles }: MessageContext
{ deleteAfterSentFiles }: MessageContext,
) {
//有的奇怪的框架将url作为参数 而不是file 此时优先url 同时注意可能传入的是非file://开头的目录 By Mlikiowa
const { path, isLocal, fileName, errMsg, success } = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
const {
path,
isLocal,
fileName,
errMsg,
success,
} = (await uri2local(coreContext.NapCatTempPath, inputdata?.url || inputdata.file));
if (!success) {
coreContext.context.logger.logError('文件下载失败', errMsg);
@@ -30,13 +37,13 @@ async function handleOb11FileLikeMessage(
}
const _handlers: {
[Key in OB11MessageDataType]: (
CoreContext: NapCatCore,
sendMsg: Extract<OB11MessageData, { type: Key }>,
// This picks the correct message type out
// How great the type system of TypeScript is!
context: MessageContext
) => Promise<SendMessageElement | undefined>
[Key in OB11MessageDataType]: (
CoreContext: NapCatCore,
sendMsg: Extract<OB11MessageData, { type: Key }>,
// This picks the correct message type out
// How great the type system of TypeScript is!
context: MessageContext,
) => Promise<SendMessageElement | undefined>
} = {
[OB11MessageDataType.text]: async (coreContext, { data: { text } }) => SendMsgElementConstructor.text(coreContext, text),
@@ -49,7 +56,7 @@ const _handlers: {
// Mlikiowa V2.0.0 Refactor Todo
const uid = await coreContext.getApiContext().UserApi.getUidByUin(atQQ);
if (!uid) throw new Error('Get Uid Error');
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, "");
return SendMsgElementConstructor.at(coreContext, atQQ, uid, AtType.atUser, '');
},
[OB11MessageDataType.reply]: async (coreContext, { data: { id } }) => {
const replyMsgM = MessageUnique.getMsgIdAndPeerByShortId(parseInt(id));
@@ -69,8 +76,8 @@ const _handlers: {
[OB11MessageDataType.mface]: async (coreContext, {
data: {
emoji_package_id, emoji_id, key, summary
}
emoji_package_id, emoji_id, key, summary,
},
}) => SendMsgElementConstructor.mface(coreContext, emoji_package_id, emoji_id, key, summary),
// File service
@@ -79,7 +86,7 @@ const _handlers: {
coreContext,
(await handleOb11FileLikeMessage(coreContext, sendMsg, context)).path,
sendMsg.data.summary || '',
sendMsg.data.subType || 0
sendMsg.data.subType || 0,
);
context.deleteAfterSentFiles.push(PicEle.picElement.sourcePath);
return PicEle;
@@ -119,7 +126,7 @@ const _handlers: {
[OB11MessageDataType.markdown]: async (coreContext, { data: { content } }) => SendMsgElementConstructor.markdown(coreContext, content),
[OB11MessageDataType.music]: async (coreContext, { data }) => {
// 保留, 直到...找到更好的解决方案
// 保留, 直到...找到更好的解决方案
if (data.type === 'custom') {
if (!data.url) {
coreContext.context.logger.logError('自定义音卡缺少参数url');
@@ -152,7 +159,7 @@ const _handlers: {
postData = data;
}
// Mlikiowa V2.0.0 Refactor Todo
const signUrl = "";
const signUrl = '';
if (!signUrl) {
if (data.type === 'qq') {
//const musicJson = (await SignMusicWrapper(data.id.toString())).data.arkResult.slice(0, -1);
@@ -179,24 +186,24 @@ const _handlers: {
[OB11MessageDataType.Location]: async (coreContext) => {
return SendMsgElementConstructor.location(coreContext);
},
[OB11MessageDataType.miniapp]: function (CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
[OB11MessageDataType.miniapp]: function(CoreContext: NapCatCore, sendMsg: never, context: MessageContext): Promise<SendMessageElement | undefined> {
throw new Error('Function not implemented.');
}
},
};
const handlers = <{
[Key in OB11MessageDataType]: (
coreContext: NapCatCore,
sendMsg: OB11MessageData,
context: MessageContext
) => Promise<SendMessageElement | undefined>
[Key in OB11MessageDataType]: (
coreContext: NapCatCore,
sendMsg: OB11MessageData,
context: MessageContext,
) => Promise<SendMessageElement | undefined>
}>_handlers;
export default async function createSendElements(
CoreContext: NapCatCore,
messageData: OB11MessageData[],
peer: Peer,
ignoreTypes: OB11MessageDataType[] = []
ignoreTypes: OB11MessageDataType[] = [],
) {
const deleteAfterSentFiles: string[] = [];
const callResultList: Array<Promise<SendMessageElement | undefined>> = [];
@@ -207,7 +214,7 @@ export default async function createSendElements(
const callResult = handlers[sendMsg.type](
CoreContext,
sendMsg,
{ peer, deleteAfterSentFiles }
{ peer, deleteAfterSentFiles },
)?.catch(undefined);
callResultList.push(callResult);
}
@@ -220,19 +227,19 @@ export async function createSendElementsParallel(
CoreContext: NapCatCore,
messageData: OB11MessageData[],
peer: Peer,
ignoreTypes: OB11MessageDataType[] = []
ignoreTypes: OB11MessageDataType[] = [],
) {
const deleteAfterSentFiles: string[] = [];
const sendElements = <SendMessageElement[]>(
await Promise.all(
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
undefined :
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles }))
).then(
results => results.filter(
element => element !== undefined
await Promise.all(
messageData.map(async sendMsg => ignoreTypes.includes(sendMsg.type) ?
undefined :
handlers[sendMsg.type](CoreContext, sendMsg, { peer, deleteAfterSentFiles })),
).then(
results => results.filter(
element => element !== undefined,
),
)
)
);
);
return { sendElements, deleteAfterSentFiles };
}

View File

@@ -2,11 +2,12 @@ import { ChatType, ElementType, NapCatCore, Peer, RawMessage, SendMessageElement
import { MessageUnique } from '@/common/utils/MessageUnique';
import { OB11MessageDataType, OB11MessageNode } from '@/onebot/types';
import createSendElements from './create-send-elements';
import { normalize, sendMsg } from "../SendMsg/index";
import { normalize, sendMsg } from '../SendMsg/index';
async function cloneMsg(coreContext: NapCatCore, msg: RawMessage): Promise<RawMessage | undefined> {
const selfPeer = {
chatType: ChatType.friend,
peerUid: coreContext.selfInfo.uid
peerUid: coreContext.selfInfo.uid,
};
const logger = coreContext.context.logger;
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
@@ -33,7 +34,7 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
const NTQQMsgApi = coreContext.getApiContext().MsgApi;
const selfPeer = {
chatType: ChatType.friend,
peerUid: coreContext.selfInfo.uid
peerUid: coreContext.selfInfo.uid,
};
let nodeMsgIds: string[] = [];
const logger = coreContext.context.logger;
@@ -54,20 +55,28 @@ export async function handleForwardNode(coreContext: NapCatCore, destPeer: Peer,
//筛选node消息
const isNodeMsg = OB11Data.filter(e => e.type === OB11MessageDataType.node).length;//找到子转发消息
if (isNodeMsg !== 0) {
if (isNodeMsg !== OB11Data.length) { logger.logError('子消息中包含非node消息 跳过不合法部分'); continue; }
if (isNodeMsg !== OB11Data.length) {
logger.logError('子消息中包含非node消息 跳过不合法部分');
continue;
}
const nodeMsg = await handleForwardNode(coreContext, selfPeer, OB11Data.filter(e => e.type === OB11MessageDataType.node));
if (nodeMsg) { nodeMsgIds.push(nodeMsg.msgId); MessageUnique.createMsg(selfPeer, nodeMsg.msgId); }
if (nodeMsg) {
nodeMsgIds.push(nodeMsg.msgId);
MessageUnique.createMsg(selfPeer, nodeMsg.msgId);
}
//完成子卡片生成跳过后续
continue;
}
const { sendElements } = await createSendElements(coreContext,OB11Data, destPeer);
const { sendElements } = await createSendElements(coreContext, OB11Data, destPeer);
//拆分消息
const MixElement = sendElements.filter(element => element.elementType !== ElementType.FILE && element.elementType !== ElementType.VIDEO);
const SingleElement = sendElements.filter(element => element.elementType === ElementType.FILE || element.elementType === ElementType.VIDEO).map(e => [e]);
const AllElement: SendMessageElement[][] = [MixElement, ...SingleElement].filter(e => e !== undefined && e.length !== 0);
const MsgNodeList: Promise<RawMessage | undefined>[] = [];
for (const sendElementsSplitElement of AllElement) {
MsgNodeList.push(sendMsg(coreContext,selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => { resolve(undefined); })));
MsgNodeList.push(sendMsg(coreContext, selfPeer, sendElementsSplitElement, [], true).catch(e => new Promise((resolve, reject) => {
resolve(undefined);
})));
}
(await Promise.allSettled(MsgNodeList)).map((result) => {
if (result.status === 'fulfilled' && result.value) {

View File

@@ -1,10 +1,9 @@
import {
OB11MessageData,
OB11MessageDataType,
OB11MessageMixType,
OB11MessageNode,
OB11PostSendMsg
OB11PostSendMsg,
} from '@/onebot/types';
import { ActionName, BaseCheckResult } from '@/onebot/action/types';
import fs from 'node:fs';
@@ -17,13 +16,15 @@ import BaseAction from '../../BaseAction';
import { handleForwardNode } from './handle-forward-node';
export interface ReturnDataType {
message_id: number;
message_id: number;
}
export enum ContextMode {
Normal = 0,
Private = 1,
Group = 2
Normal = 0,
Private = 1,
Group = 2
}
// Normalizes a mixed type (CQCode/a single segment/segment array) into a segment array.
export function normalize(message: OB11MessageMixType, autoEscape = false): OB11MessageData[] {
return typeof message === 'string' ? (
@@ -68,12 +69,18 @@ export async function sendMsg(coreContext: NapCatCore, peer: Peer, sendElements:
}
const returnMsg = await NTQQMsgApi.sendMsg(peer, sendElements, waitComplete, timeout);
try {
returnMsg!.id = MessageUnique.createMsg({ chatType: peer.chatType, guildId: '', peerUid: peer.peerUid }, returnMsg!.msgId);
returnMsg!.id = MessageUnique.createMsg({
chatType: peer.chatType,
guildId: '',
peerUid: peer.peerUid,
}, returnMsg!.msgId);
} catch (e: any) {
logger.logDebug('发送消息id获取失败', e);
returnMsg!.id = 0;
returnMsg!.id = 0;
}
deleteAfterSentFiles.map((f) => { fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e)); });
deleteAfterSentFiles.map((f) => {
fsPromise.unlink(f).then().catch(e => logger.logError('发送消息删除文件失败', e));
});
return returnMsg;
}
@@ -88,7 +95,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
const group = (await NTQQGroupApi.getGroups()).find(e => e.groupCode == payload.group_id?.toString());
return {
chatType: ChatType.group,
peerUid: payload.group_id.toString()
peerUid: payload.group_id.toString(),
};
}
if ((contextMode === ContextMode.Private || contextMode === ContextMode.Normal) && payload.user_id) {
@@ -97,7 +104,7 @@ async function createContext(coreContext: NapCatCore, payload: OB11PostSendMsg,
//console.log("[调试代码] UIN:", payload.user_id, " UID:", Uid, " IsBuddy:", isBuddy);
return {
chatType: isBuddy ? ChatType.friend : ChatType.temp,
peerUid: Uid!
peerUid: Uid!,
};
}
throw '请指定 group_id 或 user_id';
@@ -121,7 +128,10 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
const messages = normalize(payload.message);
const nodeElementLength = getSpecialMsgNum(payload, OB11MessageDataType.node);
if (nodeElementLength > 0 && nodeElementLength != messages.length) {
return { valid: false, message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素' };
return {
valid: false,
message: '转发消息不能和普通消息混在一起发送,转发需要保证message只有type为node的元素',
};
}
// if (payload.message_type !== 'private' && payload.group_id && !(await getGroup(payload.group_id))) {
// return { valid: false, message: `群${payload.group_id}不存在` };
@@ -142,13 +152,17 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
const messages = normalize(
payload.message,
payload.auto_escape === true || payload.auto_escape === 'true'
payload.auto_escape === true || payload.auto_escape === 'true',
);
if (getSpecialMsgNum(payload, OB11MessageDataType.node)) {
const returnMsg = await handleForwardNode(this.CoreContext,peer, messages as OB11MessageNode[]);
const returnMsg = await handleForwardNode(this.CoreContext, peer, messages as OB11MessageNode[]);
if (returnMsg) {
const msgShortId = MessageUnique.createMsg({ guildId: '', peerUid: peer.peerUid, chatType: peer.chatType }, returnMsg!.msgId);
const msgShortId = MessageUnique.createMsg({
guildId: '',
peerUid: peer.peerUid,
chatType: peer.chatType,
}, returnMsg!.msgId);
return { message_id: msgShortId! };
} else {
throw Error('发送转发消息失败');

View File

@@ -1,6 +1,7 @@
import SendMsg, { ContextMode } from './SendMsg';
import { ActionName, BaseCheckResult } from '../types';
import { OB11PostSendMsg } from '../../types';
// 未检测参数
class SendPrivateMsg extends SendMsg {
actionName = ActionName.SendPrivateMsg;

View File

@@ -1,6 +1,5 @@
import { ActionName } from '../types';
import BaseAction from '../BaseAction';
import { NTQQMsgApi } from '@/core/apis';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageUnique } from '@/common/utils/MessageUnique';
@@ -8,9 +7,9 @@ const SchemaData = {
type: 'object',
properties: {
message_id: { type: ['string', 'number'] },
emoji_id: { type: ['string', 'number'] }
emoji_id: { type: ['string', 'number'] },
},
required: ['message_id', 'emoji_id']
required: ['message_id', 'emoji_id'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -18,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class SetMsgEmojiLike extends BaseAction<Payload, any> {
actionName = ActionName.SetMsgEmojiLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const msg = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));

View File

@@ -2,7 +2,7 @@ import { ActionName } from '../types';
import CanSendRecord from './CanSendRecord';
interface ReturnType {
yes: boolean
yes: boolean;
}
export default class CanSendImage extends CanSendRecord {

View File

@@ -2,7 +2,7 @@ import BaseAction from '../BaseAction';
import { ActionName } from '../types';
interface ReturnType {
yes: boolean
yes: boolean;
}
export default class CanSendRecord extends BaseAction<any, ReturnType> {
@@ -10,7 +10,7 @@ export default class CanSendRecord extends BaseAction<any, ReturnType> {
protected async _handle(_payload: void): Promise<ReturnType> {
return {
yes: true
yes: true,
};
}
}

View File

@@ -1,4 +1,3 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '../../helper/data';
import BaseAction from '../BaseAction';

View File

@@ -8,7 +8,7 @@ export default class GetStatus extends BaseAction<any, any> {
return {
online: !!this.CoreContext.selfInfo.online,
good: true,
stat:{}
stat: {},
};
}
}

View File

@@ -9,7 +9,7 @@ export default class GetVersionInfo extends BaseAction<any, any> {
return {
app_name: 'NapCat.Onebot',
protocol_version: 'v11',
app_version: napcat_version
app_version: napcat_version,
};
}
}

View File

@@ -1,21 +1,21 @@
export type BaseCheckResult = ValidCheckResult | InvalidCheckResult
export interface ValidCheckResult {
valid: true
valid: true;
[k: string | number]: any
[k: string | number]: any;
}
export interface InvalidCheckResult {
valid: false
message: string
valid: false;
message: string;
[k: string | number]: any
[k: string | number]: any;
}
export enum ActionName {
// 以下为扩展napcat扩展
Unknown = "unknown",
Unknown = 'unknown',
SharePeer = 'ArkShareGroup',
ShareGroupEx = 'ArkSharePeer',
RebootNormal = 'reboot_normal',//无快速登录重新启动

View File

@@ -1,17 +1,18 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
interface Response {
cookies: string,
bkn: string
cookies: string,
bkn: string
}
const SchemaData = {
type: 'object',
properties: {
domain: { type: 'string' }
domain: { type: 'string' },
},
required: ['domain']
required: ['domain'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -19,6 +20,7 @@ type Payload = FromSchema<typeof SchemaData>;
export class GetCookies extends BaseAction<Payload, Response> {
actionName = ActionName.GetCookies;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;

View File

@@ -9,13 +9,14 @@ const SchemaData = {
type: 'object',
properties: {
no_cache: { type: ['boolean', 'string'] },
}
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
actionName = ActionName.GetFriendList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
//全新逻辑
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;

View File

@@ -1,4 +1,3 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
@@ -7,8 +6,8 @@ import { OB11Constructor } from '@/onebot/helper/data';
const SchemaData = {
type: 'object',
properties: {
count: { type: ['number', 'string'] }
}
count: { type: ['number', 'string'] },
},
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -16,6 +15,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class GetRecentContact extends BaseAction<Payload, any> {
actionName = ActionName.GetRecentContact;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
@@ -24,7 +24,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
if (FastMsg.msgList.length > 0) {
//扩展ret.info.changedList
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], 'array');
return {
lastestMsg: lastestMsg,
peerUin: t.peerUin,
@@ -34,7 +34,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
peerName: t.peerName,
};
}
return {
@@ -45,7 +45,7 @@ export default class GetRecentContact extends BaseAction<Payload, any> {
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
peerName: t.peerName,
};
}));
return data;

View File

@@ -1,4 +1,3 @@
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
@@ -7,9 +6,9 @@ const SchemaData = {
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
times: { type: ['number', 'string'] }
times: { type: ['number', 'string'] },
},
required: ['user_id', 'times']
required: ['user_id', 'times'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -17,6 +16,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SendLike extends BaseAction<Payload, null> {
actionName = ActionName.SendLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
//logDebug('点赞参数', payload);

View File

@@ -1,16 +1,15 @@
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { NTQQFriendApi } from '@/core/apis/friend';
const SchemaData = {
type: 'object',
properties: {
flag: { type: 'string' },
approve: { type: ['string', 'boolean'] },
remark: { type: 'string' }
remark: { type: 'string' },
},
required: ['flag']
required: ['flag'],
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
@@ -18,6 +17,7 @@ type Payload = FromSchema<typeof SchemaData>;
export default class SetFriendAddRequest extends BaseAction<Payload, null> {
actionName = ActionName.SetFriendAddRequest;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
const approve = payload.approve?.toString() !== 'false';