mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
feat: 注入OneBot上下文
This commit is contained in:
@@ -3,15 +3,17 @@ import { OB11Response } from './OB11Response';
|
|||||||
import { OB11Return } from '@/onebot/types';
|
import { OB11Return } from '@/onebot/types';
|
||||||
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
import { NapCatOneBot11Adapter } from '../main';
|
||||||
|
|
||||||
class BaseAction<PayloadType, ReturnDataType> {
|
class BaseAction<PayloadType, ReturnDataType> {
|
||||||
actionName: ActionName = ActionName.Unknown;
|
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) {
|
OneBotContext: NapCatOneBot11Adapter;
|
||||||
//注入上下文
|
constructor(onebotContext:NapCatOneBot11Adapter,coreContext: NapCatCore) {
|
||||||
this.CoreContext = context;
|
this.OneBotContext = onebotContext;
|
||||||
|
this.CoreContext = coreContext;
|
||||||
}
|
}
|
||||||
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
|
||||||
if (this.PayloadSchema) {
|
if (this.PayloadSchema) {
|
||||||
|
@@ -75,89 +75,90 @@ import { FetchCustomFace } from './extends/FetchCustomFace';
|
|||||||
import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivareFile';
|
import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivareFile';
|
||||||
import { FetchEmojioLike } from './extends/FetchEmojioLike';
|
import { FetchEmojioLike } from './extends/FetchEmojioLike';
|
||||||
import { NapCatCore } from '@/core';
|
import { NapCatCore } from '@/core';
|
||||||
|
import { NapCatOneBot11Adapter } from '../main';
|
||||||
|
|
||||||
export function createActionMap(context: NapCatCore) {
|
export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
|
||||||
const actionHandlers = [
|
const actionHandlers = [
|
||||||
new FetchEmojioLike(context),
|
new FetchEmojioLike(onebotContext,coreContext),
|
||||||
new GetFile(context),
|
new GetFile(onebotContext,coreContext),
|
||||||
new SetSelfProfile(context),
|
new SetSelfProfile(onebotContext,coreContext),
|
||||||
new shareGroupEx(context),
|
new shareGroupEx(onebotContext,coreContext),
|
||||||
new sharePeer(context),
|
new sharePeer(onebotContext,coreContext),
|
||||||
new CreateCollection(context),
|
new CreateCollection(onebotContext,coreContext),
|
||||||
new SetLongNick(context),
|
new SetLongNick(onebotContext,coreContext),
|
||||||
new ForwardFriendSingleMsg(context),
|
new ForwardFriendSingleMsg(onebotContext,coreContext),
|
||||||
new ForwardGroupSingleMsg(context),
|
new ForwardGroupSingleMsg(onebotContext,coreContext),
|
||||||
new MarkGroupMsgAsRead(context),
|
new MarkGroupMsgAsRead(onebotContext,coreContext),
|
||||||
new MarkPrivateMsgAsRead(context),
|
new MarkPrivateMsgAsRead(onebotContext,coreContext),
|
||||||
new SetQQAvatar(context),
|
new SetQQAvatar(onebotContext,coreContext),
|
||||||
new TranslateEnWordToZn(context),
|
new TranslateEnWordToZn(onebotContext,coreContext),
|
||||||
new GetGroupFileCount(context),
|
new GetGroupFileCount(onebotContext,coreContext),
|
||||||
new GetGroupFileList(context),
|
new GetGroupFileList(onebotContext,coreContext),
|
||||||
new SetGroupFileFolder(context),
|
new SetGroupFileFolder(onebotContext,coreContext),
|
||||||
new DelGroupFile(context),
|
new DelGroupFile(onebotContext,coreContext),
|
||||||
new DelGroupFileFolder(context),
|
new DelGroupFileFolder(onebotContext,coreContext),
|
||||||
// onebot11
|
// onebot11
|
||||||
new SendLike(context),
|
new SendLike(onebotContext,coreContext),
|
||||||
new GetMsg(context),
|
new GetMsg(onebotContext,coreContext),
|
||||||
new GetLoginInfo(context),
|
new GetLoginInfo(onebotContext,coreContext),
|
||||||
new GetFriendList(context),
|
new GetFriendList(onebotContext,coreContext),
|
||||||
new GetGroupList(context),
|
new GetGroupList(onebotContext,coreContext),
|
||||||
new GetGroupInfo(context),
|
new GetGroupInfo(onebotContext,coreContext),
|
||||||
new GetGroupMemberList(context),
|
new GetGroupMemberList(onebotContext,coreContext),
|
||||||
new GetGroupMemberInfo(context),
|
new GetGroupMemberInfo(onebotContext,coreContext),
|
||||||
new SendGroupMsg(context),
|
new SendGroupMsg(onebotContext,coreContext),
|
||||||
new SendPrivateMsg(context),
|
new SendPrivateMsg(onebotContext,coreContext),
|
||||||
new SendMsg(context),
|
new SendMsg(onebotContext,coreContext),
|
||||||
new DeleteMsg(context),
|
new DeleteMsg(onebotContext,coreContext),
|
||||||
new SetGroupAddRequest(context),
|
new SetGroupAddRequest(onebotContext,coreContext),
|
||||||
new SetFriendAddRequest(context),
|
new SetFriendAddRequest(onebotContext,coreContext),
|
||||||
new SetGroupLeave(context),
|
new SetGroupLeave(onebotContext,coreContext),
|
||||||
new GetVersionInfo(context),
|
new GetVersionInfo(onebotContext,coreContext),
|
||||||
new CanSendRecord(context),
|
new CanSendRecord(onebotContext,coreContext),
|
||||||
new CanSendImage(context),
|
new CanSendImage(onebotContext,coreContext),
|
||||||
new GetStatus(context),
|
new GetStatus(onebotContext,coreContext),
|
||||||
new SetGroupWholeBan(context),
|
new SetGroupWholeBan(onebotContext,coreContext),
|
||||||
new SetGroupBan(context),
|
new SetGroupBan(onebotContext,coreContext),
|
||||||
new SetGroupKick(context),
|
new SetGroupKick(onebotContext,coreContext),
|
||||||
new SetGroupAdmin(context),
|
new SetGroupAdmin(onebotContext,coreContext),
|
||||||
new SetGroupName(context),
|
new SetGroupName(onebotContext,coreContext),
|
||||||
new SetGroupCard(context),
|
new SetGroupCard(onebotContext,coreContext),
|
||||||
new GetImage(context),
|
new GetImage(onebotContext,coreContext),
|
||||||
new GetRecord(context),
|
new GetRecord(onebotContext,coreContext),
|
||||||
new SetMsgEmojiLike(context),
|
new SetMsgEmojiLike(onebotContext,coreContext),
|
||||||
new GetCookies(context),
|
new GetCookies(onebotContext,coreContext),
|
||||||
new SetOnlineStatus(context),
|
new SetOnlineStatus(onebotContext,coreContext),
|
||||||
new GetRobotUinRange(context),
|
new GetRobotUinRange(onebotContext,coreContext),
|
||||||
new GetFriendWithCategory(context),
|
new GetFriendWithCategory(onebotContext,coreContext),
|
||||||
//以下为go-cqhttp api
|
//以下为go-cqhttp api
|
||||||
new GetOnlineClient(context),
|
new GetOnlineClient(onebotContext,coreContext),
|
||||||
new OCRImage(context),
|
new OCRImage(onebotContext,coreContext),
|
||||||
new IOCRImage(context),
|
new IOCRImage(onebotContext,coreContext),
|
||||||
new GetGroupHonorInfo(context),
|
new GetGroupHonorInfo(onebotContext,coreContext),
|
||||||
new SendGroupNotice(context),
|
new SendGroupNotice(onebotContext,coreContext),
|
||||||
new GetGroupNotice(context),
|
new GetGroupNotice(onebotContext,coreContext),
|
||||||
new GetGroupEssence(context),
|
new GetGroupEssence(onebotContext,coreContext),
|
||||||
new GoCQHTTPSendForwardMsg(context),
|
new GoCQHTTPSendForwardMsg(onebotContext,coreContext),
|
||||||
new GoCQHTTPSendGroupForwardMsg(context),
|
new GoCQHTTPSendGroupForwardMsg(onebotContext,coreContext),
|
||||||
new GoCQHTTPSendPrivateForwardMsg(context),
|
new GoCQHTTPSendPrivateForwardMsg(onebotContext,coreContext),
|
||||||
new GoCQHTTPGetStrangerInfo(context),
|
new GoCQHTTPGetStrangerInfo(onebotContext,coreContext),
|
||||||
new GoCQHTTPDownloadFile(context),
|
new GoCQHTTPDownloadFile(onebotContext,coreContext),
|
||||||
new GetGuildList(context),
|
new GetGuildList(onebotContext,coreContext),
|
||||||
new GoCQHTTPMarkMsgAsRead(context),
|
new GoCQHTTPMarkMsgAsRead(onebotContext,coreContext),
|
||||||
new GoCQHTTPUploadGroupFile(context),
|
new GoCQHTTPUploadGroupFile(onebotContext,coreContext),
|
||||||
new GoCQHTTPGetGroupMsgHistory(context),
|
new GoCQHTTPGetGroupMsgHistory(onebotContext,coreContext),
|
||||||
new GoCQHTTPGetForwardMsgAction(context),
|
new GoCQHTTPGetForwardMsgAction(onebotContext,coreContext),
|
||||||
new GetFriendMsgHistory(context),
|
new GetFriendMsgHistory(onebotContext,coreContext),
|
||||||
new GoCQHTTPHandleQuickAction(context),
|
new GoCQHTTPHandleQuickAction(onebotContext,coreContext),
|
||||||
new GetGroupSystemMsg(context),
|
new GetGroupSystemMsg(onebotContext,coreContext),
|
||||||
new DelEssenceMsg(context),
|
new DelEssenceMsg(onebotContext,coreContext),
|
||||||
new SetEssenceMsg(context),
|
new SetEssenceMsg(onebotContext,coreContext),
|
||||||
new GetRecentContact(context),
|
new GetRecentContact(onebotContext,coreContext),
|
||||||
new MarkAllMsgAsRead(context),
|
new MarkAllMsgAsRead(onebotContext,coreContext),
|
||||||
new GetProfileLike(context),
|
new GetProfileLike(onebotContext,coreContext),
|
||||||
new SetGroupHeader(context),
|
new SetGroupHeader(onebotContext,coreContext),
|
||||||
new FetchCustomFace(context),
|
new FetchCustomFace(onebotContext,coreContext),
|
||||||
new GoCQHTTPUploadPrivateFile(context)
|
new GoCQHTTPUploadPrivateFile(onebotContext,coreContext)
|
||||||
];
|
];
|
||||||
const actionMap = new Map<string, BaseAction<any, any>>();
|
const actionMap = new Map<string, BaseAction<any, any>>();
|
||||||
for (const action of actionHandlers) {
|
for (const action of actionHandlers) {
|
||||||
|
Reference in New Issue
Block a user