diff --git a/src/core/core.ts b/src/core/core.ts index 2bcde3fc..13dd2eb9 100644 --- a/src/core/core.ts +++ b/src/core/core.ts @@ -9,8 +9,7 @@ import { LegacyNTEventWrapper } from '@/common/framework/event-legacy'; import { NTQQFileApi, NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NTQQUserApi, NTQQWebApi } from './apis'; import os from 'node:os'; import { NTQQCollectionApi } from './apis/collection'; -import { OB11Config } from '@/onebot/helper/config'; -import { NapCatConfig } from './helper/config'; +import { NapCatConfigLoader } from './helper/config'; export enum NapCatCoreWorkingEnv { Unknown = 0, @@ -38,7 +37,7 @@ export class NapCatCore { // runtime info, not readonly selfInfo: SelfInfo; util: NodeQQNTWrapperUtil; - config: any; + configLoader: NapCatConfigLoader; // 通过构造器递过去的 runtime info 应该尽量少 constructor(context: InstanceContext, selfInfo: SelfInfo) { @@ -56,7 +55,7 @@ export class NapCatCore { UserApi: new NTQQUserApi(this.context, this), GroupApi: new NTQQGroupApi(this.context, this), }; - this.config = new NapCatConfig(this,this.context.pathWrapper.configPath); + this.configLoader = new NapCatConfigLoader(this,this.context.pathWrapper.configPath); this.NapCatDataPath = path.join(this.dataPath, 'NapCat'); fs.mkdirSync(this.NapCatDataPath, { recursive: true }); this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp'); @@ -185,9 +184,9 @@ export class NapCatCore { } checkAdminEvent(groupCode: string, memberNew: GroupMember, memberOld: GroupMember | undefined): boolean { if (memberNew.role !== memberOld?.role) { - this.context.logger.log(`群 ${groupCode} ${memberNew.nick} 角色变更为 ${memberNew.role === 3 ? '管理员' : '群员'}`); - return true; + this.context.logger.log(`群 ${groupCode} ${memberNew.nick} 角色变更为 ${memberNew.role === 3 ? '管理员' : '群员'}`); + return true; } return false; - } + } } diff --git a/src/core/helper/config.ts b/src/core/helper/config.ts index 8a36456c..72fb3af2 100644 --- a/src/core/helper/config.ts +++ b/src/core/helper/config.ts @@ -1,15 +1,11 @@ import { ConfigBase } from "@/common/utils/ConfigBase"; import { LogLevel } from "@/common/utils/log"; +import napCatDefaultConfig from '@/core/external/napcat.json'; // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -export interface NapCatConfig { - fileLog: boolean, - consoleLog: boolean, - fileLogLevel: LogLevel, - consoleLogLevel: LogLevel, -} +export type NapCatConfig = typeof napCatDefaultConfig; // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -export class NapCatConfig extends ConfigBase { +export class NapCatConfigLoader extends ConfigBase { name = 'napcat'; } diff --git a/src/onebot/helper/config.ts b/src/onebot/helper/config.ts index 79a0c722..70c4fe2a 100644 --- a/src/onebot/helper/config.ts +++ b/src/onebot/helper/config.ts @@ -1,40 +1,10 @@ import { ConfigBase } from '@/common/utils/ConfigBase'; +import ob11DefaultConfig from '@/onebot/external/onebot11.json'; // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -export interface OB11Config { - http: { - enable: boolean; - host: string; - port: number; - secret: string; - enableHeart: boolean; - enablePost: boolean; - postUrls: string[]; - }; - ws: { - enable: boolean; - host: string; - port: number; - }; - reverseWs: { - enable: boolean; - urls: string[]; - }; - - debug: boolean; - heartInterval: number; - messagePostFormat: 'array' | 'string'; - enableLocalFile2Url: boolean; - musicSignUrl: string; - reportSelfMessage: boolean; - token: string; - GroupLocalTime: { - Record: boolean, - RecordList: Array - }; -} +export type OB11Config = typeof ob11DefaultConfig; // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging -export class OB11Config extends ConfigBase { +export class OB11ConfigLoader extends ConfigBase { name = 'onebot11'; } diff --git a/src/onebot/main.ts b/src/onebot/main.ts index dbf3953a..78c2ccad 100644 --- a/src/onebot/main.ts +++ b/src/onebot/main.ts @@ -9,7 +9,7 @@ import { NapCatCore, RawMessage, } from '@/core'; -import { OB11Config } from './helper/config'; +import { OB11Config, OB11ConfigLoader } from './helper/config'; import { NapCatPathWrapper } from '@/common/framework/napcat'; import { OneBotApiContextType } from '@/onebot/types'; import { OneBotFriendApi, OneBotGroupApi, OneBotUserApi } from './api'; @@ -39,7 +39,7 @@ export class NapCatOneBot11Adapter { readonly core: NapCatCore; readonly context: InstanceContext; - config: OB11Config; + configLoader: OB11ConfigLoader; apiContext: OneBotApiContextType; networkManager: OB11NetworkManager; @@ -48,7 +48,7 @@ export class NapCatOneBot11Adapter { constructor(core: NapCatCore, context: InstanceContext, pathWrapper: NapCatPathWrapper) { this.core = core; this.context = context; - this.config = new OB11Config(core, pathWrapper.configPath); + this.configLoader = new OB11ConfigLoader(core, pathWrapper.configPath); this.apiContext = { GroupApi: new OneBotGroupApi(this, core), UserApi: new OneBotUserApi(this, core), @@ -61,7 +61,7 @@ export class NapCatOneBot11Adapter { async InitOneBot() { const NTQQUserApi = this.core.apis.UserApi; const selfInfo = this.core.selfInfo; - const ob11Config = this.config.configData; + const ob11Config = this.configLoader.configData; const serviceInfo = ` HTTP服务 ${ob11Config.http.enable ? '已启动' : '未启动'}, ${ob11Config.http.host}:${ob11Config.http.port} @@ -113,7 +113,7 @@ export class NapCatOneBot11Adapter { await WebUiDataRuntime.setQQLoginUin(selfInfo.uin.toString()); await WebUiDataRuntime.setQQLoginStatus(true); await WebUiDataRuntime.setOB11ConfigCall(async (ob11: OB11Config) => { - this.config.save(ob11); + this.configLoader.save(ob11); }); } @@ -157,10 +157,10 @@ export class NapCatOneBot11Adapter { // console.log(msg); if (msg.sendStatus == 2) { // 完成后再post - OB11Constructor.message(this.core, msg, this.config.messagePostFormat) + OB11Constructor.message(this.core, msg, this.configLoader.configData.messagePostFormat) .then((ob11Msg) => { ob11Msg.target_id = parseInt(msg.peerUin); - if (this.config.reportSelfMessage) { + if (this.configLoader.configData.reportSelfMessage) { msg.id = MessageUnique.createMsg({ chatType: msg.chatType, peerUid: msg.peerUid, guildId: '' }, msg.msgId); this.emitMsg(msg); } else { @@ -322,9 +322,9 @@ export class NapCatOneBot11Adapter { } private async emitMsg(message: RawMessage) { - const { debug, reportSelfMessage } = this.config; + const { debug, reportSelfMessage, messagePostFormat } = this.configLoader.configData; this.context.logger.logDebug('收到新消息', message); - OB11Constructor.message(this.core, message, this.config.messagePostFormat).then((ob11Msg) => { + OB11Constructor.message(this.core, message, messagePostFormat).then((ob11Msg) => { this.context.logger.logDebug('收到消息: ', ob11Msg); if (debug) { ob11Msg.raw = message;