feat: 注入OneBot上下文

This commit is contained in:
手瓜一十雪 2024-08-09 21:54:14 +08:00
parent 5990e0c2eb
commit fa07dfb720
2 changed files with 85 additions and 82 deletions

View File

@ -3,15 +3,17 @@ import { OB11Response } from './OB11Response';
import { OB11Return } from '@/onebot/types';
import Ajv, { ErrorObject, ValidateFunction } from 'ajv';
import { NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '../main';
class BaseAction<PayloadType, ReturnDataType> {
actionName: ActionName = ActionName.Unknown;
CoreContext: NapCatCore;
private validate: undefined | ValidateFunction<any> = undefined;
PayloadSchema: any = undefined;
constructor(context: NapCatCore) {
//注入上下文
this.CoreContext = context;
OneBotContext: NapCatOneBot11Adapter;
constructor(onebotContext:NapCatOneBot11Adapter,coreContext: NapCatCore) {
this.OneBotContext = onebotContext;
this.CoreContext = coreContext;
}
protected async check(payload: PayloadType): Promise<BaseCheckResult> {
if (this.PayloadSchema) {

View File

@ -75,89 +75,90 @@ import { FetchCustomFace } from './extends/FetchCustomFace';
import GoCQHTTPUploadPrivateFile from './go-cqhttp/UploadPrivareFile';
import { FetchEmojioLike } from './extends/FetchEmojioLike';
import { NapCatCore } from '@/core';
import { NapCatOneBot11Adapter } from '../main';
export function createActionMap(context: NapCatCore) {
export function createActionMap(onebotContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
const actionHandlers = [
new FetchEmojioLike(context),
new GetFile(context),
new SetSelfProfile(context),
new shareGroupEx(context),
new sharePeer(context),
new CreateCollection(context),
new SetLongNick(context),
new ForwardFriendSingleMsg(context),
new ForwardGroupSingleMsg(context),
new MarkGroupMsgAsRead(context),
new MarkPrivateMsgAsRead(context),
new SetQQAvatar(context),
new TranslateEnWordToZn(context),
new GetGroupFileCount(context),
new GetGroupFileList(context),
new SetGroupFileFolder(context),
new DelGroupFile(context),
new DelGroupFileFolder(context),
new FetchEmojioLike(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(context),
new GetMsg(context),
new GetLoginInfo(context),
new GetFriendList(context),
new GetGroupList(context),
new GetGroupInfo(context),
new GetGroupMemberList(context),
new GetGroupMemberInfo(context),
new SendGroupMsg(context),
new SendPrivateMsg(context),
new SendMsg(context),
new DeleteMsg(context),
new SetGroupAddRequest(context),
new SetFriendAddRequest(context),
new SetGroupLeave(context),
new GetVersionInfo(context),
new CanSendRecord(context),
new CanSendImage(context),
new GetStatus(context),
new SetGroupWholeBan(context),
new SetGroupBan(context),
new SetGroupKick(context),
new SetGroupAdmin(context),
new SetGroupName(context),
new SetGroupCard(context),
new GetImage(context),
new GetRecord(context),
new SetMsgEmojiLike(context),
new GetCookies(context),
new SetOnlineStatus(context),
new GetRobotUinRange(context),
new GetFriendWithCategory(context),
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(context),
new OCRImage(context),
new IOCRImage(context),
new GetGroupHonorInfo(context),
new SendGroupNotice(context),
new GetGroupNotice(context),
new GetGroupEssence(context),
new GoCQHTTPSendForwardMsg(context),
new GoCQHTTPSendGroupForwardMsg(context),
new GoCQHTTPSendPrivateForwardMsg(context),
new GoCQHTTPGetStrangerInfo(context),
new GoCQHTTPDownloadFile(context),
new GetGuildList(context),
new GoCQHTTPMarkMsgAsRead(context),
new GoCQHTTPUploadGroupFile(context),
new GoCQHTTPGetGroupMsgHistory(context),
new GoCQHTTPGetForwardMsgAction(context),
new GetFriendMsgHistory(context),
new GoCQHTTPHandleQuickAction(context),
new GetGroupSystemMsg(context),
new DelEssenceMsg(context),
new SetEssenceMsg(context),
new GetRecentContact(context),
new MarkAllMsgAsRead(context),
new GetProfileLike(context),
new SetGroupHeader(context),
new FetchCustomFace(context),
new GoCQHTTPUploadPrivateFile(context)
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) {