mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
Merge branch 'main' of https://github.com/NapNeko/NapCatQQ
This commit is contained in:
@@ -3,12 +3,13 @@ import fs from 'node:fs';
|
|||||||
import type { NapCatCore } from '@/core';
|
import type { NapCatCore } from '@/core';
|
||||||
|
|
||||||
export abstract class ConfigBase<T> {
|
export abstract class ConfigBase<T> {
|
||||||
abstract name: string;
|
name: string;
|
||||||
coreContext: NapCatCore;
|
coreContext: NapCatCore;
|
||||||
configPath: string;
|
configPath: string;
|
||||||
configData: T = {} as T;
|
configData: T = {} as T;
|
||||||
|
|
||||||
constructor(coreContext: NapCatCore, configPath: string) {
|
protected constructor(name: string, coreContext: NapCatCore, configPath: string) {
|
||||||
|
this.name = name;
|
||||||
this.coreContext = coreContext;
|
this.coreContext = coreContext;
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
fs.mkdirSync(this.configPath, { recursive: true });
|
fs.mkdirSync(this.configPath, { recursive: true });
|
||||||
|
@@ -68,7 +68,7 @@ export class LogWrapper {
|
|||||||
this.setLogSelfInfo({ nick: '', uin: '', uid: '' });
|
this.setLogSelfInfo({ nick: '', uin: '', uid: '' });
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogLevel(fileLogLevel: LogLevel, consoleLogLevel: LogLevel) {
|
setFileAndConsoleLogLevel(fileLogLevel: LogLevel, consoleLogLevel: LogLevel) {
|
||||||
this.logConfig.categories.file.level = fileLogLevel;
|
this.logConfig.categories.file.level = fileLogLevel;
|
||||||
this.logConfig.categories.console.level = consoleLogLevel;
|
this.logConfig.categories.console.level = consoleLogLevel;
|
||||||
log4js.configure(this.logConfig);
|
log4js.configure(this.logConfig);
|
||||||
@@ -81,13 +81,12 @@ export class LogWrapper {
|
|||||||
this.loggerDefault.addContext('userInfo', userInfo);
|
this.loggerDefault.addContext('userInfo', userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFileLogEnabled(isEnabled: boolean) {
|
||||||
enableFileLog(enable: boolean) {
|
this.fileLogEnabled = isEnabled;
|
||||||
this.fileLogEnabled = enable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enableConsoleLog(enable: boolean) {
|
setConsoleLogEnabled(isEnabled: boolean) {
|
||||||
this.consoleLogEnabled = enable;
|
this.consoleLogEnabled = isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
formatMsg(msg: any[]) {
|
formatMsg(msg: any[]) {
|
||||||
|
@@ -10,6 +10,7 @@ import { NTQQFileApi, NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, NTQQSystemApi, NT
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { NTQQCollectionApi } from './apis/collection';
|
import { NTQQCollectionApi } from './apis/collection';
|
||||||
import { NapCatConfigLoader } from './helper/config';
|
import { NapCatConfigLoader } from './helper/config';
|
||||||
|
import { LogLevel } from '@/common/utils/log';
|
||||||
|
|
||||||
export enum NapCatCoreWorkingEnv {
|
export enum NapCatCoreWorkingEnv {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
@@ -55,7 +56,7 @@ export class NapCatCore {
|
|||||||
UserApi: new NTQQUserApi(this.context, this),
|
UserApi: new NTQQUserApi(this.context, this),
|
||||||
GroupApi: new NTQQGroupApi(this.context, this),
|
GroupApi: new NTQQGroupApi(this.context, this),
|
||||||
};
|
};
|
||||||
this.configLoader = new NapCatConfigLoader(this,this.context.pathWrapper.configPath);
|
this.configLoader = new NapCatConfigLoader(this, this.context.pathWrapper.configPath);
|
||||||
this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
|
this.NapCatDataPath = path.join(this.dataPath, 'NapCat');
|
||||||
fs.mkdirSync(this.NapCatDataPath, { recursive: true });
|
fs.mkdirSync(this.NapCatDataPath, { recursive: true });
|
||||||
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
|
this.NapCatTempPath = path.join(this.NapCatDataPath, 'temp');
|
||||||
@@ -64,6 +65,17 @@ export class NapCatCore {
|
|||||||
fs.mkdirSync(this.NapCatTempPath, { recursive: true });
|
fs.mkdirSync(this.NapCatTempPath, { recursive: true });
|
||||||
}
|
}
|
||||||
this.initNapCatCoreListeners().then().catch(this.context.logger.logError);
|
this.initNapCatCoreListeners().then().catch(this.context.logger.logError);
|
||||||
|
|
||||||
|
this.context.logger.setFileLogEnabled(
|
||||||
|
this.configLoader.configData.fileLog,
|
||||||
|
);
|
||||||
|
this.context.logger.setConsoleLogEnabled(
|
||||||
|
this.configLoader.configData.consoleLog,
|
||||||
|
);
|
||||||
|
this.context.logger.setFileAndConsoleLogLevel(
|
||||||
|
this.configLoader.configData.fileLogLevel as LogLevel,
|
||||||
|
this.configLoader.configData.consoleLogLevel as LogLevel,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get dataPath(): string {
|
get dataPath(): string {
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
import { ConfigBase } from "@/common/utils/ConfigBase";
|
import { ConfigBase } from "@/common/utils/ConfigBase";
|
||||||
import { LogLevel } from "@/common/utils/log";
|
|
||||||
import napCatDefaultConfig from '@/core/external/napcat.json';
|
import napCatDefaultConfig from '@/core/external/napcat.json';
|
||||||
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
||||||
export type NapCatConfig = typeof napCatDefaultConfig;
|
export type NapCatConfig = typeof napCatDefaultConfig;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
||||||
export class NapCatConfigLoader extends ConfigBase<NapCatConfig> {
|
export class NapCatConfigLoader extends ConfigBase<NapCatConfig> {
|
||||||
name = 'napcat';
|
constructor(coreContext: NapCatCore, configPath: string) {
|
||||||
|
super('napcat', coreContext, configPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,10 +1,11 @@
|
|||||||
import { ConfigBase } from '@/common/utils/ConfigBase';
|
import { ConfigBase } from '@/common/utils/ConfigBase';
|
||||||
import ob11DefaultConfig from '@/onebot/external/onebot11.json';
|
import ob11DefaultConfig from '@/onebot/external/onebot11.json';
|
||||||
|
import { NapCatCore } from '@/core';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
||||||
export type OB11Config = typeof ob11DefaultConfig;
|
export type OB11Config = typeof ob11DefaultConfig;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
|
|
||||||
export class OB11ConfigLoader extends ConfigBase<OB11Config> {
|
export class OB11ConfigLoader extends ConfigBase<OB11Config> {
|
||||||
name = 'onebot11';
|
constructor(coreContext: NapCatCore, configPath: string) {
|
||||||
|
super('onebot11', coreContext, configPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,7 +26,6 @@ import qrcode from 'qrcode-terminal';
|
|||||||
import { NapCatOneBot11Adapter } from '@/onebot';
|
import { NapCatOneBot11Adapter } from '@/onebot';
|
||||||
import { InitWebUi } from '@/webui';
|
import { InitWebUi } from '@/webui';
|
||||||
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
import { WebUiDataRuntime } from '@/webui/src/helper/Data';
|
||||||
import { promisify } from 'util';
|
|
||||||
|
|
||||||
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
program.option('-q, --qq [number]', 'QQ号').parse(process.argv);
|
||||||
const cmdOptions = program.opts();
|
const cmdOptions = program.opts();
|
||||||
@@ -151,7 +150,7 @@ export async function NCoreInitShell() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
WebUiDataRuntime.setQQQuickLoginCall(async (uin: string) => {
|
WebUiDataRuntime.setQQQuickLoginCall(async (uin: string) => {
|
||||||
const QuickLogin: Promise<{ result: boolean, message: string }> = new Promise((resolve, reject) => {
|
return await new Promise((resolve) => {
|
||||||
if (uin) {
|
if (uin) {
|
||||||
logger.log('正在快速登录 ', uin);
|
logger.log('正在快速登录 ', uin);
|
||||||
loginService.quickLoginWithUin(uin).then(res => {
|
loginService.quickLoginWithUin(uin).then(res => {
|
||||||
@@ -167,8 +166,6 @@ export async function NCoreInitShell() {
|
|||||||
resolve({ result: false, message: '快速登录失败' });
|
resolve({ result: false, message: '快速登录失败' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const result = await QuickLogin;
|
|
||||||
return result;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (quickLoginUin && historyLoginList.some(u => u.uin === quickLoginUin)) {
|
if (quickLoginUin && historyLoginList.some(u => u.uin === quickLoginUin)) {
|
||||||
@@ -186,7 +183,9 @@ export async function NCoreInitShell() {
|
|||||||
} else {
|
} else {
|
||||||
logger.log('没有 -q 指令指定快速登录,或未曾登录过这个 QQ,将使用二维码登录方式');
|
logger.log('没有 -q 指令指定快速登录,或未曾登录过这个 QQ,将使用二维码登录方式');
|
||||||
if (historyLoginList.length > 0) {
|
if (historyLoginList.length > 0) {
|
||||||
logger.log(`可用于快速登录的 QQ:\n${historyLoginList.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
logger.log(`可用于快速登录的 QQ:\n${
|
||||||
|
historyLoginList
|
||||||
|
.map((u, index) => `${index + 1}. ${u.uin} ${u.nickName}`)
|
||||||
.join('\n')
|
.join('\n')
|
||||||
}`);
|
}`);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user