Compare commits

...

7 Commits

Author SHA1 Message Date
DebaucheryLibrarian 1402f28b98 1.1.2 2023-12-05 23:37:00 +01:00
DebaucheryLibrarian 02cd395ff5 Handling missing card titles. 2023-12-05 23:36:59 +01:00
DebaucheryLibrarian dd36ee1aba Not updating automod config if there are no changes. 2022-06-27 02:45:59 +02:00
DebaucheryLibrarian a8bd2cb62a Fixed single name delimiter slicing last letter off all names. 2022-06-27 01:54:01 +02:00
DebaucheryLibrarian 039eb22ae7 Removed default subreddit from config. 2022-06-27 01:46:16 +02:00
ThePendulum 883f701359 1.1.1 2022-06-27 01:43:22 +02:00
ThePendulum 88266e5b03 Centralized logging. 2022-06-27 01:43:17 +02:00
6 changed files with 35 additions and 15 deletions

0
.gitignore vendored Normal file → Executable file
View File

0
README.md Normal file → Executable file
View File

4
config/default.js Normal file → Executable file
View File

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

4
package-lock.json generated Normal file → Executable file
View File

@ -1,12 +1,12 @@
{
"name": "kanbanmod",
"version": "1.1.0",
"version": "1.1.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "kanbanmod",
"version": "1.1.0",
"version": "1.1.2",
"license": "ISC",
"dependencies": {
"bhttp": "^1.2.8",

2
package.json Normal file → Executable file
View File

@ -1,6 +1,6 @@
{
"name": "kanbanmod",
"version": "1.1.0",
"version": "1.1.2",
"description": "",
"main": "index.js",
"scripts": {

40
src/app.js Normal file → Executable file
View File

@ -6,6 +6,10 @@ const bhttp = require('bhttp');
const reddit = new snoowrap(config.reddit);
function log(msg) {
console.log(`${new Date().toISOString()} ${msg}`);
}
async function getWekanActorNames() {
const wekanLoginRes = await bhttp.post(`${config.wekan.url}/users/login`, {
username: config.wekan.username,
@ -27,42 +31,58 @@ async function getWekanActorNames() {
}
const actorNames = wekanBoardRes.body.map((card) => {
if (!card.title) {
console.warn('Missing card title', card);
return null;
}
const name = card.title.split(/\s+/).slice(0, 2).join(' ');
// allow single name to be delimited
return name.slice(0, name.indexOf('.'));
if (name.includes('.')) {
// allow single name to be delimited
return name.slice(0, name.indexOf('.'));
}
return name;
;});
return actorNames;
return actorNames.filter(Boolean);
}
async function init() {
log(`Retrieving current configuration from ${config.subreddit}`);
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 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',
});
console.log(`${new Date().toISOString()} 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;
}
console.log(`${new Date().toISOString()} Sync complete, set ${newActorLine}`);
log('Sync complete');
}
init();