mirror of
https://github.com/Jerryplusy/crystelf-plugin.git
synced 2025-10-14 05:39:18 +00:00
Compare commits
2 Commits
ea7b3103f0
...
e9aeffe224
Author | SHA1 | Date | |
---|---|---|---|
e9aeffe224 | |||
d3c976ef7c |
@ -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('nickName')}发现了一条新的rss推送!`
|
`${configControl.get('profile')?.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,7 +39,6 @@ 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);
|
||||||
@ -50,21 +49,28 @@ 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);
|
||||||
data = fc.mergeConfig(data, pluginData);
|
if (Array.isArray(data) && Array.isArray(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
configCache = { ...baseConfig, ...configCache };
|
if (!Array.isArray(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] 配置模块初始化成功..');
|
||||||
}
|
}
|
||||||
@ -90,26 +96,32 @@ const configControl = {
|
|||||||
await fsp.access(filePath);
|
await fsp.access(filePath);
|
||||||
await fc.writeJSON(filePath, value);
|
await fc.writeJSON(filePath, value);
|
||||||
} catch {
|
} catch {
|
||||||
const cfg = await fc.readJSON(configFile);
|
let cfg = await fc.readJSON(configFile);
|
||||||
cfg[key] = value;
|
if (Array.isArray(cfg)) {
|
||||||
|
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 {
|
||||||
if (key !== 'config') {
|
let cfg = await fc.readJSON(configFile);
|
||||||
|
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