Syncing reddit and wekan actors.
This commit is contained in:
commit
096637d46b
|
@ -0,0 +1,3 @@
|
|||
node_modules/
|
||||
config/*
|
||||
!config/default.js
|
|
@ -0,0 +1,2 @@
|
|||
# kanbanmod
|
||||
Synchronize Wekan kanban actor names with reddit automoderator forbidden title word list.
|
|
@ -0,0 +1,20 @@
|
|||
module.exports = {
|
||||
reddit: {
|
||||
userAgent: 'kanbanmod',
|
||||
clientId: '',
|
||||
clientSecret: '',
|
||||
refreshToken: '',
|
||||
accessToken: '',
|
||||
},
|
||||
interval: 5,
|
||||
subreddit: 'PornMilestones',
|
||||
actorCommentKey: 'KANBANNED',
|
||||
baseActorNames: [],
|
||||
wekan: {
|
||||
url: '',
|
||||
username: '',
|
||||
password: '',
|
||||
boardId: '',
|
||||
listId: '',
|
||||
},
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"name": "kanbanmod",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bhttp": "^1.2.8",
|
||||
"config": "^3.3.7",
|
||||
"snoowrap": "^1.23.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
const snoowrap = require('snoowrap');
|
||||
const bhttp = require('bhttp');
|
||||
|
||||
const reddit = new snoowrap(config.reddit);
|
||||
|
||||
async function getWekanActorNames() {
|
||||
const wekanLoginRes = await bhttp.post(`${config.wekan.url}/users/login`, {
|
||||
username: config.wekan.username,
|
||||
password: config.wekan.password,
|
||||
});
|
||||
|
||||
if (!wekanLoginRes.statusCode === 200) {
|
||||
throw new Error(`Wekan login failed (${wekanLoginRes.statusCode}): ${wekanLoginRes.body}`);
|
||||
}
|
||||
|
||||
const wekanBoardRes = await bhttp.get(`${config.wekan.url}/api/boards/${config.wekan.boardId}/lists/${config.wekan.listId}/cards`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${wekanLoginRes.body.token}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (!wekanBoardRes.statusCode === 200) {
|
||||
throw new Error(`Wekan card retrieval failed (${wekanBoardRes.statusCode}): ${wekanBoardRes.body}`);
|
||||
}
|
||||
|
||||
const actorNames = wekanBoardRes.body.map((card) => {
|
||||
const name = card.title.split(/\s+/).slice(0, 2).join(' ');
|
||||
|
||||
// allow single name to be delimited
|
||||
return name.slice(0, name.indexOf('.'));
|
||||
;});
|
||||
|
||||
return actorNames;
|
||||
}
|
||||
|
||||
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 wekanActorNames= await getWekanActorNames();
|
||||
const actorNames = [...config.baseActorNames, ...wekanActorNames];
|
||||
const newActorLine = `title: ${JSON.stringify(actorNames)}`;
|
||||
|
||||
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',
|
||||
});
|
||||
|
||||
console.log(`${new Date().toISOString()} Sync complete, resyncing in ${config.interval} minutes, set ${newActorLine}`);
|
||||
|
||||
setTimeout(() => init(), config.interval * 60 * 1000);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`${new Date().toISOString()} Sync complete, set ${newActorLine}`);
|
||||
}
|
||||
|
||||
init();
|
Loading…
Reference in New Issue