fix: 创建OB上下文

This commit is contained in:
手瓜一十雪 2024-08-10 18:03:21 +08:00
parent a710821c35
commit 6c87e15a52
6 changed files with 49 additions and 1 deletions

11
src/onebot/api/friend.ts Normal file
View File

@ -0,0 +1,11 @@
import { NapCatCore } from "@/core";
import { NapCatOneBot11Adapter } from "../main";
export class OneBotFriendApi {
obContext: NapCatOneBot11Adapter;
coreContext: NapCatCore;
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
this.obContext = obContext;
this.coreContext = coreContext;
}
}

10
src/onebot/api/group.ts Normal file
View File

@ -0,0 +1,10 @@
import { NapCatCore } from "@/core";
import { NapCatOneBot11Adapter } from "../main";
export class OneBotGroupApi{
obContext: NapCatOneBot11Adapter;
coreContext: NapCatCore;
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
this.obContext = obContext;
this.coreContext = coreContext;
}
}

3
src/onebot/api/index.ts Normal file
View File

@ -0,0 +1,3 @@
export * from './friend';
export * from './group';
export * from './user';

10
src/onebot/api/user.ts Normal file
View File

@ -0,0 +1,10 @@
import { NapCatCore } from "@/core";
import { NapCatOneBot11Adapter } from "../main";
export class OneBotUserApi{
obContext: NapCatOneBot11Adapter;
coreContext: NapCatCore;
constructor(obContext: NapCatOneBot11Adapter, coreContext: NapCatCore) {
this.obContext = obContext;
this.coreContext = coreContext;
}
}

View File

@ -1,16 +1,23 @@
import { NapCatCore, InstanceContext } from "@/core";
import { OB11Config } from "./helper/config";
import { NapCatPathWrapper } from "@/common/framework/napcat";
import { OneBotApiContextType } from "./types/adapter";
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from "./api";
//OneBot实现类
export class NapCatOneBot11Adapter {
readonly core: NapCatCore;
readonly context: InstanceContext;
config: OB11Config;
apiContext: OneBotApiContextType;
constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) {
this.core = core;
this.context = context;
this.config = new OB11Config(core, pathWrapper.configPath);
this.apiContext = {
GroupApi: new OneBotGroupApi(this, core),
UserApi: new OneBotUserApi(this, core),
FriendApi: new OneBotFriendApi(this, core)
};
}
}

View File

@ -0,0 +1,7 @@
import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from "../api";
export interface OneBotApiContextType {
FriendApi: OneBotFriendApi;
UserApi: OneBotUserApi;
GroupApi: OneBotGroupApi;
}