mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-10-14 13:49:18 +00:00
Compare commits
No commits in common. "e9aeffe2245a645924919f3833509622f6bef857" and "ea7b3103f097a2a4eb39a63c9120bc3998e4d1b4" have entirely different histories.
e9aeffe224
...
ea7b3103f0
@ -150,7 +150,7 @@ export default class RssPlugin extends plugin {
|
|||||||
const tempPath = path.join(process.cwd(), 'data', `rss-${Date.now()}.png`);
|
const tempPath = path.join(process.cwd(), 'data', `rss-${Date.now()}.png`);
|
||||||
if (feed.screenshot) {
|
if (feed.screenshot) {
|
||||||
await Bot.pickGroup(groupId)?.sendMsg(
|
await Bot.pickGroup(groupId)?.sendMsg(
|
||||||
`${configControl.get('profile')?.nickName}发现了一条新的rss推送!`
|
`${configControl.get('nickName')}发现了一条新的rss推送!`
|
||||||
);
|
);
|
||||||
await tools.sleep(1000);
|
await tools.sleep(1000);
|
||||||
//await Bot.pickGroup(groupId)?.sendMsg(`让${configControl.get('nickName')}看看内容是什么..`);
|
//await Bot.pickGroup(groupId)?.sendMsg(`让${configControl.get('nickName')}看看内容是什么..`);
|
||||||
|
@ -39,6 +39,7 @@ async function init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
const files = (await fsp.readdir(dataConfigPath)).filter((f) => f.endsWith('.json'));
|
const files = (await fsp.readdir(dataConfigPath)).filter((f) => f.endsWith('.json'));
|
||||||
|
let baseConfig = {};
|
||||||
configCache = {};
|
configCache = {};
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePath = path.join(dataConfigPath, file);
|
const filePath = path.join(dataConfigPath, file);
|
||||||
@ -49,28 +50,21 @@ async function init() {
|
|||||||
try {
|
try {
|
||||||
await fsp.access(pluginFilePath);
|
await fsp.access(pluginFilePath);
|
||||||
const pluginData = await fc.readJSON(pluginFilePath);
|
const pluginData = await fc.readJSON(pluginFilePath);
|
||||||
if (Array.isArray(data) && Array.isArray(pluginData)) {
|
data = fc.mergeConfig(data, pluginData);
|
||||||
const strSet = new Set(data.map((x) => JSON.stringify(x)));
|
|
||||||
for (const item of pluginData) {
|
|
||||||
const str = JSON.stringify(item);
|
|
||||||
if (!strSet.has(str)) {
|
|
||||||
data.push(item);
|
|
||||||
strSet.add(str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!Array.isArray(data) && !Array.isArray(pluginData)) {
|
|
||||||
data = fc.mergeConfig(data, pluginData);
|
|
||||||
}
|
|
||||||
await fc.writeJSON(filePath, data);
|
await fc.writeJSON(filePath, data);
|
||||||
} catch {}
|
} catch {}
|
||||||
configCache[name] = data;
|
|
||||||
|
if (name === 'config') {
|
||||||
|
baseConfig = data;
|
||||||
|
} else {
|
||||||
|
configCache[name] = data;
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.warn(`[crystelf-plugin] 读取配置文件 ${file} 失败:`, e);
|
logger.warn(`[crystelf-plugin] 读取配置文件 ${file} 失败:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Array.isArray(configCache)) {
|
configCache = { ...baseConfig, ...configCache };
|
||||||
configCache = fc.mergeConfig(configCache, defaultConfig);
|
configCache = fc.mergeConfig(configCache, defaultConfig);
|
||||||
}
|
|
||||||
if (configCache.debug) {
|
if (configCache.debug) {
|
||||||
logger.info('[crystelf-plugin] 配置模块初始化成功..');
|
logger.info('[crystelf-plugin] 配置模块初始化成功..');
|
||||||
}
|
}
|
||||||
@ -96,32 +90,26 @@ const configControl = {
|
|||||||
await fsp.access(filePath);
|
await fsp.access(filePath);
|
||||||
await fc.writeJSON(filePath, value);
|
await fc.writeJSON(filePath, value);
|
||||||
} catch {
|
} catch {
|
||||||
let cfg = await fc.readJSON(configFile);
|
const cfg = await fc.readJSON(configFile);
|
||||||
if (Array.isArray(cfg)) {
|
cfg[key] = value;
|
||||||
cfg.push(value);
|
|
||||||
} else {
|
|
||||||
cfg[key] = value;
|
|
||||||
}
|
|
||||||
await fc.writeJSON(configFile, cfg);
|
await fc.writeJSON(configFile, cfg);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async save() {
|
async save() {
|
||||||
|
const cfg = await fc.readJSON(configFile);
|
||||||
for (const [key, value] of Object.entries(configCache)) {
|
for (const [key, value] of Object.entries(configCache)) {
|
||||||
const filePath = path.join(dataConfigPath, `${key}.json`);
|
const filePath = path.join(dataConfigPath, `${key}.json`);
|
||||||
try {
|
try {
|
||||||
await fsp.access(filePath);
|
await fsp.access(filePath);
|
||||||
await fc.writeJSON(filePath, value);
|
await fc.writeJSON(filePath, value);
|
||||||
} catch {
|
} catch {
|
||||||
let cfg = await fc.readJSON(configFile);
|
if (key !== 'config') {
|
||||||
if (Array.isArray(cfg)) {
|
|
||||||
cfg = value;
|
|
||||||
} else {
|
|
||||||
cfg[key] = value;
|
cfg[key] = value;
|
||||||
}
|
}
|
||||||
await fc.writeJSON(configFile, cfg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
await fc.writeJSON(configFile, cfg);
|
||||||
},
|
},
|
||||||
|
|
||||||
async reload() {
|
async reload() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user