Compare commits
No commits in common. "master" and "f61f67a37c771739f2917e5e5271bea9542f1d2c" have entirely different histories.
master
...
f61f67a37c
|
@ -6,8 +6,8 @@ module.exports = {
|
|||
refreshToken: '',
|
||||
accessToken: '',
|
||||
},
|
||||
interval: 600,
|
||||
subreddit: '',
|
||||
interval: 5,
|
||||
subreddit: 'PornMilestones',
|
||||
actorCommentKey: 'KANBANNED',
|
||||
baseActorNames: [],
|
||||
wekan: {
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "kanbanmod",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "kanbanmod",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.0",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bhttp": "^1.2.8",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "kanbanmod",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -6,10 +6,6 @@ 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,
|
||||
|
@ -31,58 +27,42 @@ 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(' ');
|
||||
|
||||
if (name.includes('.')) {
|
||||
// allow single name to be delimited
|
||||
return name.slice(0, name.indexOf('.'));
|
||||
}
|
||||
|
||||
return name;
|
||||
// allow single name to be delimited
|
||||
return name.slice(0, name.indexOf('.'));
|
||||
;});
|
||||
|
||||
return actorNames.filter(Boolean);
|
||||
return actorNames;
|
||||
}
|
||||
|
||||
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)}`;
|
||||
|
||||
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({
|
||||
text: newConfig,
|
||||
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 * 1000);
|
||||
setTimeout(() => init(), config.interval * 60 * 1000);
|
||||
|
||||
log(`Sync complete, resyncing in ${config.interval} seconds`);
|
||||
return;
|
||||
}
|
||||
|
||||
log('Sync complete');
|
||||
console.log(`${new Date().toISOString()} Sync complete, set ${newActorLine}`);
|
||||
}
|
||||
|
||||
init();
|
||||
|
|
Loading…
Reference in New Issue