mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-13 11:40:35 +00: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';
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
class BaseAction<PayloadType, ReturnDataType> {
|
class BaseAction<PayloadType, ReturnDataType> {
|
||||||
actionName!: ActionName;
|
actionName: ActionName = ActionName.Unknown;
|
||||||
CoreContext!: NapCatCore;
|
CoreContext: NapCatCore;
|
||||||
private validate: undefined | ValidateFunction<any> = undefined;
|
private validate: undefined | ValidateFunction<any> = undefined;
|
||||||
PayloadSchema: any = undefined;
|
PayloadSchema: any = undefined;
|
||||||
|
constructor(context: NapCatCore) {
|
||||||
|
//注入上下文
|
||||||
|
this.CoreContext = context;
|
||||||
|
}
|
||||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||||
if (this.PayloadSchema) {
|
if (this.PayloadSchema) {
|
||||||
this.validate = new Ajv({ allowUnionTypes: true }).compile(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 { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import BaseAction from '../BaseAction';
|
import BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQMsgApi } from '@/core/apis';
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -16,7 +15,7 @@ export class FetchCustomFace extends BaseAction<Payload, string[]> {
|
|||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
//48 可能正好是QQ需要的一个页面的数量 Tagged Mlikiowa
|
//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);
|
return ret.emojiInfoList.map(e => e.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export class FetchEmojioLike extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.FetchEmojioLike;
|
actionName = ActionName.FetchEmojioLike;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
|
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
|
||||||
const msgIdPeer = MessageUnique.getMsgIdAndPeerByShortId(parseInt(payload.message_id.toString()));
|
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];
|
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 BaseAction from '../BaseAction';
|
||||||
import { ActionName } from '../types';
|
import { ActionName } from '../types';
|
||||||
import { NTQQUserApi } from '@/core/apis';
|
|
||||||
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
|
||||||
import { selfInfo } from '@/core/data';
|
|
||||||
|
|
||||||
const SchemaData = {
|
const SchemaData = {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@ -21,6 +18,7 @@ export class GetCollectionList extends BaseAction<Payload, any> {
|
|||||||
actionName = ActionName.GetCollectionList;
|
actionName = ActionName.GetCollectionList;
|
||||||
PayloadSchema = SchemaData;
|
PayloadSchema = SchemaData;
|
||||||
protected async _handle(payload: Payload) {
|
protected async _handle(payload: Payload) {
|
||||||
|
const NTQQCollectionApi = this.CoreContext.getApiContext().CollectionApi;
|
||||||
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
|
return await NTQQCollectionApi.getAllCollection(payload.category, payload.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,6 +15,7 @@ export interface InvalidCheckResult {
|
|||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
// 以下为扩展napcat扩展
|
// 以下为扩展napcat扩展
|
||||||
|
Unknown = "unknown",
|
||||||
SharePeer = 'ArkShareGroup',
|
SharePeer = 'ArkShareGroup',
|
||||||
ShareGroupEx = 'ArkSharePeer',
|
ShareGroupEx = 'ArkSharePeer',
|
||||||
RebootNormal = 'reboot_normal',//无快速登录重新启动
|
RebootNormal = 'reboot_normal',//无快速登录重新启动
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user