Compare commits

..

No commits in common. "master" and "f61f67a37c771739f2917e5e5271bea9542f1d2c" have entirely different histories.

6 changed files with 15 additions and 35 deletions

0
.gitignore vendored Executable file → Normal file
View File

0
README.md Executable file → Normal file
View File

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

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

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

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

2
package.json Executable file → Normal file
View File

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

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

@ -6,10 +6,6 @@ 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,
@ -31,58 +27,42 @@ async function getWekanActorNames() {
} }
const actorNames = wekanBoardRes.body.map((card) => { 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(' '); const name = card.title.split(/\s+/).slice(0, 2).join(' ');
if (name.includes('.')) {
// allow single name to be delimited // allow single name to be delimited
return name.slice(0, name.indexOf('.')); return name.slice(0, name.indexOf('.'));
}
return name;
;}); ;});
return actorNames.filter(Boolean); return actorNames;
} }
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;
const actorLine = automodLines[actorLineIndex];
const wekanActorNames = await getWekanActorNames(); const wekanActorNames= await getWekanActorNames();
const actorNames = [...config.baseActorNames, ...wekanActorNames]; const actorNames = [...config.baseActorNames, ...wekanActorNames];
const newActorLine = `title: ${JSON.stringify(actorNames)}`; const newActorLine = `title: ${JSON.stringify(actorNames)}`;
if (actorLine !== newActorLine) {
automodLines[actorLineIndex] = 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({ const result = await reddit.getSubreddit(config.subreddit).getWikiPage('config/automoderator').edit({
text: newConfig, text: newConfig,
reason: 'Synced kanban actor names', reason: 'Synced kanban actor names',
}); });
log(`Set ${newActorLine}`); console.log(`${new Date().toISOString()} Sync complete, resyncing in ${config.interval} minutes, set ${newActorLine}`);
}
if (config.interval) { setTimeout(() => init(), config.interval * 60 * 1000);
setTimeout(() => init(), config.interval * 1000);
log(`Sync complete, resyncing in ${config.interval} seconds`);
return; return;
} }
log('Sync complete'); console.log(`${new Date().toISOString()} Sync complete, set ${newActorLine}`);
} }
init(); init();