diff --git a/config/default.js b/config/default.js index 3b38aee..f37b1b7 100644 --- a/config/default.js +++ b/config/default.js @@ -6,7 +6,7 @@ module.exports = { refreshToken: '', accessToken: '', }, - interval: 5, + interval: 600, subreddit: '', actorCommentKey: 'KANBANNED', baseActorNames: [], diff --git a/src/app.js b/src/app.js index b971f41..8bfef41 100644 --- a/src/app.js +++ b/src/app.js @@ -50,29 +50,33 @@ async function init() { const automodConfig = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').fetch(); const automodLines = automodConfig.content_md.split('\n'); const actorLineIndex = automodLines.findIndex((line) => line.includes(config.actorCommentKey)) + 1; + const actorLine = automodLines[actorLineIndex]; const wekanActorNames= await getWekanActorNames(); const actorNames = [...config.baseActorNames, ...wekanActorNames]; 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({ text: newConfig, 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; } - log(`Sync complete, set ${newActorLine}`); + log('Sync complete'); } init();