Centralized logging.

This commit is contained in:
ThePendulum 2022-06-27 01:43:17 +02:00
parent f61f67a37c
commit 88266e5b03
1 changed files with 8 additions and 2 deletions

View File

@ -6,6 +6,10 @@ const bhttp = require('bhttp');
const reddit = new snoowrap(config.reddit); const reddit = new snoowrap(config.reddit);
function log(msg) {
console.log(`${new Date().toISOString()} ${msg}`);
}
async function getWekanActorNames() { async function getWekanActorNames() {
const wekanLoginRes = await bhttp.post(`${config.wekan.url}/users/login`, { const wekanLoginRes = await bhttp.post(`${config.wekan.url}/users/login`, {
username: config.wekan.username, username: config.wekan.username,
@ -37,6 +41,8 @@ async function getWekanActorNames() {
} }
async function init() { async function init() {
log(`Retrieving current configuration from ${config.subreddit}`);
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;
@ -55,14 +61,14 @@ async function init() {
reason: 'Synced kanban actor names', reason: 'Synced kanban actor names',
}); });
console.log(`${new Date().toISOString()} Sync complete, resyncing in ${config.interval} minutes, set ${newActorLine}`); log(`Sync complete, resyncing in ${config.interval} minutes, set ${newActorLine}`);
setTimeout(() => init(), config.interval * 60 * 1000); setTimeout(() => init(), config.interval * 60 * 1000);
return; return;
} }
console.log(`${new Date().toISOString()} Sync complete, set ${newActorLine}`); log(`Sync complete, set ${newActorLine}`);
} }
init(); init();