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: '',
|
||||
accessToken: '',
|
||||
},
|
||||
interval: 5,
|
||||
interval: 600,
|
||||
subreddit: '',
|
||||
actorCommentKey: 'KANBANNED',
|
||||
baseActorNames: [],
|
||||
|
|
12
src/app.js
12
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)}`;
|
||||
|
||||
if (actorLine !== newActorLine) {
|
||||
automodLines[actorLineIndex] = newActorLine;
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue