Not updating automod config if there are no changes.

This commit is contained in:
DebaucheryLibrarian 2022-06-27 02:45:59 +02:00
parent a8bd2cb62a
commit dd36ee1aba
2 changed files with 11 additions and 7 deletions

View File

@ -6,7 +6,7 @@ module.exports = {
refreshToken: '',
accessToken: '',
},
interval: 5,
interval: 600,
subreddit: '',
actorCommentKey: 'KANBANNED',
baseActorNames: [],

View File

@ -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();