Not updating automod config if there are no changes.
This commit is contained in:
parent
a8bd2cb62a
commit
dd36ee1aba
|
@ -6,7 +6,7 @@ module.exports = {
|
||||||
refreshToken: '',
|
refreshToken: '',
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
},
|
},
|
||||||
interval: 5,
|
interval: 600,
|
||||||
subreddit: '',
|
subreddit: '',
|
||||||
actorCommentKey: 'KANBANNED',
|
actorCommentKey: 'KANBANNED',
|
||||||
baseActorNames: [],
|
baseActorNames: [],
|
||||||
|
|
16
src/app.js
16
src/app.js
|
@ -50,29 +50,33 @@ async function init() {
|
||||||
const automodConfig = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').fetch();
|
const automodConfig = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').fetch();
|
||||||
const automodLines = automodConfig.content_md.split('\n');
|
const automodLines = automodConfig.content_md.split('\n');
|
||||||
const actorLineIndex = automodLines.findIndex((line) => line.includes(config.actorCommentKey)) + 1;
|
const actorLineIndex = automodLines.findIndex((line) => line.includes(config.actorCommentKey)) + 1;
|
||||||
|
const actorLine = automodLines[actorLineIndex];
|
||||||
|
|
||||||
const wekanActorNames= await getWekanActorNames();
|
const wekanActorNames= await getWekanActorNames();
|
||||||
const actorNames = [...config.baseActorNames, ...wekanActorNames];
|
const actorNames = [...config.baseActorNames, ...wekanActorNames];
|
||||||
const newActorLine = `title: ${JSON.stringify(actorNames)}`;
|
const newActorLine = `title: ${JSON.stringify(actorNames)}`;
|
||||||
|
|
||||||
automodLines[actorLineIndex] = newActorLine;
|
if (actorLine !== newActorLine) {
|
||||||
|
automodLines[actorLineIndex] = newActorLine;
|
||||||
|
|
||||||
const newConfig = automodLines.join('\n');
|
const newConfig = automodLines.join('\n');
|
||||||
|
|
||||||
if (config.interval) {
|
|
||||||
const result = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').edit({
|
const result = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').edit({
|
||||||
text: newConfig,
|
text: newConfig,
|
||||||
reason: 'Synced kanban actor names',
|
reason: 'Synced kanban actor names',
|
||||||
});
|
});
|
||||||
|
|
||||||
log(`Sync complete, resyncing in ${config.interval} minutes, set ${newActorLine}`);
|
log(`Set ${newActorLine}`);
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => init(), config.interval * 60 * 1000);
|
if (config.interval) {
|
||||||
|
setTimeout(() => init(), config.interval * 1000);
|
||||||
|
|
||||||
|
log(`Sync complete, resyncing in ${config.interval} seconds`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(`Sync complete, set ${newActorLine}`);
|
log('Sync complete');
|
||||||
}
|
}
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
Loading…
Reference in New Issue