mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-12-24 09:00:06 +08:00
chore: Action
This commit is contained in:
parent
8a4add257f
commit
518ff48e97
@ -5,10 +5,14 @@ import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
||||
import { NapCatCore } from '@/core';
|
||||
|
||||
class BaseAction<PayloadType, ReturnDataType> {
|
||||
actionName!: ActionName;
|
||||
CoreContext!: NapCatCore;
|
||||
actionName: ActionName = ActionName.Unknown;
|
||||
CoreContext: NapCatCore;
|
||||
private validate: undefined | ValidateFunction<any> = undefined;
|
||||
PayloadSchema: any = undefined;
|
||||
constructor(context: NapCatCore) {
|
||||
//注入上下文
|
||||
this.CoreContext = context;
|
||||
}
|
||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||
if (this.PayloadSchema) {
|
||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(this.PayloadSchema);
|
||||
|
||||
@ -1,43 +0,0 @@
|
||||
import BaseAction from '../BaseAction';
|
||||
// import * as ntqqApi from "../../../ntqqapi/api";
|
||||
import {
|
||||
NTQQMsgApi,
|
||||
NTQQFriendApi,
|
||||
NTQQGroupApi,
|
||||
NTQQUserApi,
|
||||
NTQQFileApi,
|
||||
// NTQQFileCacheApi,
|
||||
} from '@/core';
|
||||
import { ActionName } from '../types';
|
||||
import { log, logDebug } from '@/common/utils/log';
|
||||
|
||||
interface Payload {
|
||||
method: string,
|
||||
args: any[],
|
||||
}
|
||||
|
||||
export default class Debug extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.Debug;
|
||||
|
||||
protected async _handle(payload: Payload): Promise<any> {
|
||||
//logDebug('debug call ntqq api', payload);
|
||||
const ntqqApi = [NTQQMsgApi, NTQQFriendApi, NTQQGroupApi, NTQQUserApi, NTQQFileApi,
|
||||
// NTQQFileCacheApi,
|
||||
];
|
||||
for (const ntqqApiClass of ntqqApi) {
|
||||
// logDebug('ntqqApiClass', ntqqApiClass);
|
||||
const method = (<any>ntqqApiClass)[payload.method];
|
||||
if (method) {
|
||||
const result = method(...payload.args);
|
||||
if (method.constructor.name === 'AsyncFunction') {
|
||||
return await result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw `${payload.method}方法 不存在`;
|
||||
|
||||
// const info = await NTQQApi.getUserDetailInfo(friends[0].uid);
|
||||
// return info
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQMsgApi } from '@/core/apis';
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
@ -16,7 +15,7 @@ export class FetchCustomFace extends BaseAction<Payload, string[]> {
|
||||
PayloadSchema = SchemaData;
|
||||
protected async _handle(payload: Payload) {
|
||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
||||
const ret = await NTQQMsgApi.fetchFavEmojiList(payload.count || 48);
|
||||
const ret = await this.CoreContext.getApiContext().MsgApi.fetchFavEmojiList(payload.count || 48);
|
||||
return ret.emojiInfoList.map(e => e.url);
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,7 @@ export class FetchEmojioLike extends BaseAction<Payload, any> {
|
||||
actionName = ActionName.FetchEmojioLike;
|
||||
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('消息不存在');
|
||||
const msg = (await NTQQMsgApi.getMsgsByMsgId(msgIdPeer.Peer, [msgIdPeer.MsgId])).msgList[0];
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
|
||||
import { NTQQCollectionApi } from '@/core/apis/collection';
|
||||
import BaseAction from '../BaseAction';
|
||||
import { ActionName } from '../types';
|
||||
import { NTQQUserApi } from '@/core/apis';
|
||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||
import { selfInfo } from '@/core/data';
|
||||
|
||||
const SchemaData = {
|
||||
type: 'object',
|
||||
@ -21,6 +18,7 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ export interface InvalidCheckResult {
|
||||
|
||||
export enum ActionName {
|
||||
// 以下为扩展napcat扩展
|
||||
Unknown = "unknown",
|
||||
SharePeer = 'ArkShareGroup',
|
||||
ShareGroupEx = 'ArkSharePeer',
|
||||
RebootNormal = 'reboot_normal',//无快速登录重新启动
|
||||
|
||||
Loading…
Reference in New Issue
Block a user