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`);
|
||||
if (feed.screenshot) {
|
||||
await Bot.pickGroup(groupId)?.sendMsg(
|
||||
`${configControl.get('nickName')}发现了一条新的rss推送!`
|
||||
`${configControl.get('profile')?.nickName}发现了一条新的rss推送!`
|
||||
);
|
||||
await tools.sleep(1000);
|
||||
//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'));
|
||||
let baseConfig = {};
|
||||
configCache = {};
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dataConfigPath, file);
|
||||
@ -50,21 +49,28 @@ async function init() {
|
||||
try {
|
||||
await fsp.access(pluginFilePath);
|
||||
const pluginData = await fc.readJSON(pluginFilePath);
|
||||
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);
|
||||
} catch {}
|
||||
|
||||
if (name === 'config') {
|
||||
baseConfig = data;
|
||||
} else {
|
||||
configCache[name] = data;
|
||||
}
|
||||
} catch (e) {
|
||||
logger.warn(`[crystelf-plugin] 读取配置文件 ${file} 失败:`, e);
|
||||
}
|
||||
}
|
||||
configCache = { ...baseConfig, ...configCache };
|
||||
if (!Array.isArray(configCache)) {
|
||||
configCache = fc.mergeConfig(configCache, defaultConfig);
|
||||
}
|
||||
if (configCache.debug) {
|
||||
logger.info('[crystelf-plugin] 配置模块初始化成功..');
|
||||
}
|
||||
@ -90,26 +96,32 @@ const configControl = {
|
||||
await fsp.access(filePath);
|
||||
await fc.writeJSON(filePath, value);
|
||||
} catch {
|
||||
const cfg = await fc.readJSON(configFile);
|
||||
let cfg = await fc.readJSON(configFile);
|
||||
if (Array.isArray(cfg)) {
|
||||
cfg.push(value);
|
||||
} else {
|
||||
cfg[key] = value;
|
||||
}
|
||||
await fc.writeJSON(configFile, cfg);
|
||||
}
|
||||
},
|
||||
|
||||
async save() {
|
||||
const cfg = await fc.readJSON(configFile);
|
||||
for (const [key, value] of Object.entries(configCache)) {
|
||||
const filePath = path.join(dataConfigPath, `${key}.json`);
|
||||
try {
|
||||
await fsp.access(filePath);
|
||||
await fc.writeJSON(filePath, value);
|
||||
} catch {
|
||||
if (key !== 'config') {
|
||||
let cfg = await fc.readJSON(configFile);
|
||||
if (Array.isArray(cfg)) {
|
||||
cfg = value;
|
||||
} else {
|
||||
cfg[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
await fc.writeJSON(configFile, cfg);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async reload() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user