mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-01-17 22:10:29 +00:00
Merge remote-tracking branch 'origin/v2' into v2
This commit is contained in:
commit
8839563ff8
@ -27,7 +27,7 @@
|
|||||||
],
|
],
|
||||||
"injects": {
|
"injects": {
|
||||||
"renderer": "./renderer.js",
|
"renderer": "./renderer.js",
|
||||||
"main": "./liteloader.cjs",
|
"main": "./napcat.cjs",
|
||||||
"preload": "./preload.cjs"
|
"preload": "./preload.cjs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
import path, { dirname } from 'path';
|
import path, { dirname } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
export const napcat_version = '2.0.0';
|
export const napcat_version = '2.0.0';
|
||||||
|
|
||||||
@ -7,10 +8,21 @@ export class NapCatPathWrapper {
|
|||||||
binaryPath: string;
|
binaryPath: string;
|
||||||
logsPath: string;
|
logsPath: string;
|
||||||
configPath: string;
|
configPath: string;
|
||||||
|
cachePath: string;
|
||||||
|
|
||||||
constructor(mainPath: string = dirname(fileURLToPath(import.meta.url))) {
|
constructor(mainPath: string = dirname(fileURLToPath(import.meta.url))) {
|
||||||
this.binaryPath = mainPath;
|
this.binaryPath = mainPath;
|
||||||
this.logsPath = path.join(this.binaryPath, 'logs');
|
this.logsPath = path.join(this.binaryPath, 'logs');
|
||||||
this.configPath = path.join(this.binaryPath, 'config');
|
this.configPath = path.join(this.binaryPath, 'config');
|
||||||
|
this.cachePath = path.join(this.binaryPath, 'cache');
|
||||||
|
if (fs.existsSync(this.logsPath)) {
|
||||||
|
fs.mkdirSync(this.logsPath, { recursive: true });
|
||||||
|
}
|
||||||
|
if (fs.existsSync(this.configPath)) {
|
||||||
|
fs.mkdirSync(this.configPath, { recursive: true });
|
||||||
|
}
|
||||||
|
if (fs.existsSync(this.cachePath)) {
|
||||||
|
fs.mkdirSync(this.cachePath, { recursive: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export class ConfigBase<T> {
|
|||||||
constructor(coreContext: NapCatCore, configPath: string) {
|
constructor(coreContext: NapCatCore, configPath: string) {
|
||||||
this.coreContext = coreContext;
|
this.coreContext = coreContext;
|
||||||
this.configPath = configPath;
|
this.configPath = configPath;
|
||||||
|
fs.mkdirSync(this.configPath, { recursive: true });
|
||||||
this.read();
|
this.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,21 +21,16 @@ export class ConfigBase<T> {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConfigDir() {
|
|
||||||
const configDir = path.resolve(this.configPath, 'config');
|
|
||||||
fs.mkdirSync(configDir, { recursive: true });
|
|
||||||
return configDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
getConfigPath(pathName: string | null): string {
|
getConfigPath(pathName: string | null): string {
|
||||||
const suffix = pathName ? `_${pathName}` : '';
|
const suffix = pathName ? `_${pathName}` : '';
|
||||||
const filename = `${this.name}${suffix}.json`;
|
const filename = `${this.name}${suffix}.json`;
|
||||||
return path.join(this.getConfigDir(), filename);
|
return path.join(this.configPath, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
read() {
|
read() {
|
||||||
// 尝试加载当前账号配置
|
// 尝试加载当前账号配置
|
||||||
if (this.read_from_file(this.coreContext.selfInfo.uin, false)) return this;
|
if (this.read_from_file(this.coreContext.selfInfo.uin, false)) return this.config;
|
||||||
// 尝试加载默认配置
|
// 尝试加载默认配置
|
||||||
return this.read_from_file('', true);
|
return this.read_from_file('', true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { NTApiContext, WrapperNodeApi } from '@/core/wrapper';
|
import { NodeQQNTWrapperUtil, NTApiContext, WrapperNodeApi } from '@/core/wrapper';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import { InstanceContext } from './wrapper';
|
import { InstanceContext } from './wrapper';
|
||||||
@ -35,11 +35,13 @@ export class NapCatCore {
|
|||||||
NapCatTempPath: string;
|
NapCatTempPath: string;
|
||||||
// runtime info, not readonly
|
// runtime info, not readonly
|
||||||
selfInfo: SelfInfo;
|
selfInfo: SelfInfo;
|
||||||
|
util: NodeQQNTWrapperUtil;
|
||||||
|
|
||||||
// 通过构造器递过去的 runtime info 应该尽量少
|
// 通过构造器递过去的 runtime info 应该尽量少
|
||||||
constructor(context: InstanceContext, selfInfo: SelfInfo) {
|
constructor(context: InstanceContext, selfInfo: SelfInfo) {
|
||||||
this.selfInfo = selfInfo;
|
this.selfInfo = selfInfo;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
this.util = new this.context.wrapper.NodeQQNTWrapperUtil();
|
||||||
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
|
this.eventWrapper = new LegacyNTEventWrapper(context.wrapper, context.session);
|
||||||
this.initNapCatCoreListeners().then().catch(console.error);
|
this.initNapCatCoreListeners().then().catch(console.error);
|
||||||
this.ApiContext = {
|
this.ApiContext = {
|
||||||
@ -66,7 +68,7 @@ export class NapCatCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get dataPath(): string {
|
get dataPath(): string {
|
||||||
let result = this.context.wrapper.util.getNTUserDataInfoConfig();
|
let result = this.util.getNTUserDataInfoConfig();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result = path.resolve(os.homedir(), './.config/QQ');
|
result = path.resolve(os.homedir(), './.config/QQ');
|
||||||
fs.mkdirSync(result, { recursive: true });
|
fs.mkdirSync(result, { recursive: true });
|
||||||
|
|||||||
@ -127,7 +127,7 @@ async function NCInit() {
|
|||||||
await NCoreInitFramework(wrapperSession, wrapperLoginService, registerInitCallback);
|
await NCoreInitFramework(wrapperSession, wrapperLoginService, registerInitCallback);
|
||||||
//console.log("[NapCat] [Info] NapCat初始化完成");
|
//console.log("[NapCat] [Info] NapCat初始化完成");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[NapCat] [Error] 初始化NapCat失败', error);
|
console.log('[NapCat] [Error] 初始化NapCat失败', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,8 @@ const FrameworkBaseConfigPlugin: PluginOption[] = [
|
|||||||
cp({
|
cp({
|
||||||
targets: [
|
targets: [
|
||||||
{ src: './manifest.json', dest: 'dist' },
|
{ src: './manifest.json', dest: 'dist' },
|
||||||
|
{ src: './src/external/napcat.json', dest: 'dist/config/' },
|
||||||
|
{ src: './src/external/onebot11.json', dest: 'dist/config/' },
|
||||||
{ src: './src/framework/liteloader.cjs', dest: 'dist' },
|
{ src: './src/framework/liteloader.cjs', dest: 'dist' },
|
||||||
{ src: './src/framework/napcat.cjs', dest: 'dist' },
|
{ src: './src/framework/napcat.cjs', dest: 'dist' },
|
||||||
{ src: './src/framework/preload.cjs', dest: 'dist' },
|
{ src: './src/framework/preload.cjs', dest: 'dist' },
|
||||||
@ -78,6 +80,8 @@ const ShellBaseConfigPlugin: PluginOption[] = [
|
|||||||
// { src: './src/napcat.json', dest: 'dist/config/' },
|
// { src: './src/napcat.json', dest: 'dist/config/' },
|
||||||
// { src: './static/', dest: 'dist/static/', flatten: false },
|
// { src: './static/', dest: 'dist/static/', flatten: false },
|
||||||
// { src: './src/onebot11/onebot11.json', dest: 'dist/config/' },
|
// { src: './src/onebot11/onebot11.json', dest: 'dist/config/' },
|
||||||
|
{ src: './src/external/napcat.json', dest: 'dist/config/' },
|
||||||
|
{ src: './src/external/onebot11.json', dest: 'dist/config/' },
|
||||||
{ src: './package.json', dest: 'dist' },
|
{ src: './package.json', dest: 'dist' },
|
||||||
// { src: './README.md', dest: 'dist' },
|
// { src: './README.md', dest: 'dist' },
|
||||||
// { src: './logo.png', dest: 'dist/logs' },
|
// { src: './logo.png', dest: 'dist/logs' },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user