options command init, add set subfunction

This commit is contained in:
hgw 2023-10-02 02:11:25 +00:00
parent 624934c902
commit 4992ba5a28
6 changed files with 309 additions and 2 deletions

3
.gitignore vendored
View File

@ -131,4 +131,5 @@ dist
.env
scratch
config/default.json
config/default.json
config/usersettings.json

24
bot.js
View File

@ -37,6 +37,28 @@ async function help(chan, sub) {
}
}
async function opt(chan, user, setting, setting2, value) {
//if (provfeed === undefined) {
// bot.say(chan, errorMsg+" No feed has been provided.")
// return;
//}
//if (n === undefined) {
// var n = config.feed.default_amount;
//}
const worker = new Worker('./commands/options.js', {
workerData: {
user,
setting,
setting2,
value
}
});
worker.once('message', (string) => {
console.log('Received output from last5 worker, posting.');
bot.say(chan, string);
});
}
async function feed(chan, provfeed, n) {
if (provfeed === undefined) {
bot.say(chan, errorMsg+" No feed has been provided.")
@ -86,7 +108,7 @@ bot.addListener('message', function(nick, to, text, from) {
} else if (args[0] === config.irc.prefix+'twitter') {
twitter(to, args[1], args[2])
} else if (args[0] === config.irc.prefix+'set') {
opt(to, nick, args[1], args[2], args[3])
}
});

71
commands/options.js Normal file
View File

@ -0,0 +1,71 @@
const config = require('../config/default.json')
const { parentPort, workerData } = require('worker_threads');
const { user, setting, setting2, value } = workerData;
const fs = require('fs-extra')
let Parser = require('rss-parser');
let parser = new Parser({
headers: {'User-Agent': config.feed.useragent},
});
const striptags = require("striptags");
const moment = require('moment');
const tz = require('moment-timezone');
const editJsonFile = require("edit-json-file");
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = '['+config.colours.warning+'WARNING]'
errorMsg = '['+config.colours.error+'ERROR]'
async function sendUpstream(content) {
//var output = content.join("\n")
parentPort.postMessage(content);
process.exit()
}
function errorMessage(error, code, extra) {
console.log(error.code)
if (code == "404") {
var error = errorMsg+" 404: " + extra + " not found"
} else if (error.code == "ECONNREFUSED") {
var error = errorMsg+" Connection Refused"
} else if (error.code == "ERR_UNESCAPED_CHARACTERS"){
var error = errorMsg+" Unescaped Characters"
} else if (code == "INVALID") {
var error = errorMsg+' '+extra+' either does not exist or is not a valid feed.'
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function testFeed(feedURL) {
try {
var feed = await parser.parseURL(feedURL);
} catch (e) {
errorMessage(e, "INVALID", feedURL);
}
console.log(feed)
console.log("Feed is good, saving")
}
async function feed(nick, setting, value) {
if (setting === 'add') {
await testFeed(value);
var file = editJsonFile('/home/node/app/config/usersettings.json');
file.append(nick+".feeds", value);
file.save();
sendUpstream(value + ' added to your feed list')
//file.custom.feed.nick = value;
//fs.writeFile(file, JSON.stringify({ feed: value }))
}
}
//fs.readFile('../config/feeds.json').catch(() =>
// fs.writeFile('../config/feeds.json', '')
//);
if (setting === 'feed') {
feed(user, setting2, value);
}

View File

@ -0,0 +1,8 @@
{
"example": {
"feeds": [
"https://git.supernets.org/hogwart7/mercury.rss",
"https://git.supernets.org/hogwart7/fascinus.rss"
]
}
}

203
package-lock.json generated
View File

@ -10,7 +10,9 @@
"license": "ISC",
"dependencies": {
"config": "^3.3.9",
"edit-json-file": "^1.7.0",
"fs": "^0.0.1-security",
"fs-extra": "^11.1.1",
"irc": "^0.5.2",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
@ -29,6 +31,18 @@
"node": ">= 10.0.0"
}
},
"node_modules/edit-json-file": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/edit-json-file/-/edit-json-file-1.7.0.tgz",
"integrity": "sha512-eIkLJ9i4ija7b2TbaLHy3scyjWFLzwM2Wa6kHbV4ppVLcCqn7FzqnO1vmCG3dLrkd+teWE3mvACfv166mO0VZg==",
"dependencies": {
"find-value": "^1.0.12",
"iterate-object": "^1.3.4",
"r-json": "^1.2.10",
"set-value": "^4.1.0",
"w-json": "^1.3.10"
}
},
"node_modules/entities": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
@ -37,11 +51,34 @@
"url": "https://github.com/fb55/entities?sponsor=1"
}
},
"node_modules/find-value": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/find-value/-/find-value-1.0.12.tgz",
"integrity": "sha512-OCpo8LTk8eZ2sdDCwbU2Lc3ivYsdM6yod6jP2jHcNEFcjPhkgH0+POzTIol7xx1LZgtbI5rkO5jqxsG5MWtPjQ=="
},
"node_modules/fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"node_modules/fs-extra": {
"version": "11.1.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
"dependencies": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
},
"engines": {
"node": ">=14.14"
}
},
"node_modules/graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
},
"node_modules/iconv": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/iconv/-/iconv-2.2.3.tgz",
@ -78,6 +115,38 @@
"node": ">=6"
}
},
"node_modules/is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"dependencies": {
"isobject": "^3.0.1"
},
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/is-primitive": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/is-primitive/-/is-primitive-3.0.1.tgz",
"integrity": "sha512-GljRxhWvlCNRfZyORiH77FwdFwGcMO620o37EOYC0ORWdq+WYNVqW0w2Juzew4M+L81l6/QS3t5gkkihyRqv9w==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
"integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/iterate-object": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/iterate-object/-/iterate-object-1.3.4.tgz",
"integrity": "sha512-4dG1D1x/7g8PwHS9aK6QV5V94+ZvyP4+d19qDv43EzImmrndysIl4prmJ1hWWIGCqrZHyaHBm6BSEWHOLnpoNw=="
},
"node_modules/json5": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
@ -89,6 +158,17 @@
"node": ">=6"
}
},
"node_modules/jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"dependencies": {
"universalify": "^2.0.0"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
},
"node_modules/moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
@ -127,6 +207,11 @@
"node": ">=0.6"
}
},
"node_modules/r-json": {
"version": "1.2.10",
"resolved": "https://registry.npmjs.org/r-json/-/r-json-1.2.10.tgz",
"integrity": "sha512-hu9vyLjSlHXT62NAS7DjI9WazDlvjN0lgp3n431dCVnirVcLkZIpzSwA3orhZEKzdDD2jqNYI+w0yG0aFf4kpA=="
},
"node_modules/rss-parser": {
"version": "3.13.0",
"resolved": "https://registry.npmjs.org/rss-parser/-/rss-parser-3.13.0.tgz",
@ -141,11 +226,41 @@
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"node_modules/set-value": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/set-value/-/set-value-4.1.0.tgz",
"integrity": "sha512-zTEg4HL0RwVrqcWs3ztF+x1vkxfm0lP+MQQFPiMJTKVceBwEV0A569Ou8l9IYQG8jOZdMVI1hGsc0tmeD2o/Lw==",
"funding": [
"https://github.com/sponsors/jonschlinkert",
"https://paypal.me/jonathanschlinkert",
"https://jonschlinkert.dev/sponsor"
],
"dependencies": {
"is-plain-object": "^2.0.4",
"is-primitive": "^3.0.1"
},
"engines": {
"node": ">=11.0"
}
},
"node_modules/striptags": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/striptags/-/striptags-3.2.0.tgz",
"integrity": "sha512-g45ZOGzHDMe2bdYMdIvdAfCQkCTDMGBazSw1ypMowwGIee7ZQ5dU0rBJ8Jqgl+jAKIv4dbeE1jscZq9wid1Tkw=="
},
"node_modules/universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
"engines": {
"node": ">= 10.0.0"
}
},
"node_modules/w-json": {
"version": "1.3.10",
"resolved": "https://registry.npmjs.org/w-json/-/w-json-1.3.10.tgz",
"integrity": "sha512-XadVyw0xE+oZ5FGApXsdswv96rOhStzKqL53uSe5UaTadABGkWIg1+DTx8kiZ/VqTZTBneoL0l65RcPe4W3ecw=="
},
"node_modules/xml2js": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz",
@ -176,16 +291,48 @@
"json5": "^2.2.3"
}
},
"edit-json-file": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/edit-json-file/-/edit-json-file-1.7.0.tgz",
"integrity": "sha512-eIkLJ9i4ija7b2TbaLHy3scyjWFLzwM2Wa6kHbV4ppVLcCqn7FzqnO1vmCG3dLrkd+teWE3mvACfv166mO0VZg==",
"requires": {
"find-value": "^1.0.12",
"iterate-object": "^1.3.4",
"r-json": "^1.2.10",
"set-value": "^4.1.0",
"w-json": "^1.3.10"
}
},
"entities": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A=="
},
"find-value": {
"version": "1.0.12",
"resolved": "https://registry.npmjs.org/find-value/-/find-value-1.0.12.tgz",
"integrity": "sha512-OCpo8LTk8eZ2sdDCwbU2Lc3ivYsdM6yod6jP2jHcNEFcjPhkgH0+POzTIol7xx1LZgtbI5rkO5jqxsG5MWtPjQ=="
},
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
},
"fs-extra": {
"version": "11.1.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
"requires": {
"graceful-fs": "^4.2.0",
"jsonfile": "^6.0.1",
"universalify": "^2.0.0"
}
},
"graceful-fs": {
"version": "4.2.11",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
},
"iconv": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/iconv/-/iconv-2.2.3.tgz",
@ -210,11 +357,43 @@
"resolved": "https://registry.npmjs.org/irc-colors/-/irc-colors-1.5.0.tgz",
"integrity": "sha512-HtszKchBQTcqw1DC09uD7i7vvMayHGM1OCo6AHt5pkgZEyo99ClhHTMJdf+Ezc9ovuNNxcH89QfyclGthjZJOw=="
},
"is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"requires": {
"isobject": "^3.0.1"
}
},
"is-primitive": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/is-primitive/-/is-primitive-3.0.1.tgz",
"integrity": "sha512-GljRxhWvlCNRfZyORiH77FwdFwGcMO620o37EOYC0ORWdq+WYNVqW0w2Juzew4M+L81l6/QS3t5gkkihyRqv9w=="
},
"isobject": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz",
"integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg=="
},
"iterate-object": {
"version": "1.3.4",
"resolved": "https://registry.npmjs.org/iterate-object/-/iterate-object-1.3.4.tgz",
"integrity": "sha512-4dG1D1x/7g8PwHS9aK6QV5V94+ZvyP4+d19qDv43EzImmrndysIl4prmJ1hWWIGCqrZHyaHBm6BSEWHOLnpoNw=="
},
"json5": {
"version": "2.2.3",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg=="
},
"jsonfile": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"requires": {
"graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
}
},
"moment": {
"version": "2.29.4",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
@ -243,6 +422,11 @@
"nan": "^2.3.3"
}
},
"r-json": {
"version": "1.2.10",
"resolved": "https://registry.npmjs.org/r-json/-/r-json-1.2.10.tgz",
"integrity": "sha512-hu9vyLjSlHXT62NAS7DjI9WazDlvjN0lgp3n431dCVnirVcLkZIpzSwA3orhZEKzdDD2jqNYI+w0yG0aFf4kpA=="
},
"rss-parser": {
"version": "3.13.0",
"resolved": "https://registry.npmjs.org/rss-parser/-/rss-parser-3.13.0.tgz",
@ -257,11 +441,30 @@
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"set-value": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/set-value/-/set-value-4.1.0.tgz",
"integrity": "sha512-zTEg4HL0RwVrqcWs3ztF+x1vkxfm0lP+MQQFPiMJTKVceBwEV0A569Ou8l9IYQG8jOZdMVI1hGsc0tmeD2o/Lw==",
"requires": {
"is-plain-object": "^2.0.4",
"is-primitive": "^3.0.1"
}
},
"striptags": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/striptags/-/striptags-3.2.0.tgz",
"integrity": "sha512-g45ZOGzHDMe2bdYMdIvdAfCQkCTDMGBazSw1ypMowwGIee7ZQ5dU0rBJ8Jqgl+jAKIv4dbeE1jscZq9wid1Tkw=="
},
"universalify": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
},
"w-json": {
"version": "1.3.10",
"resolved": "https://registry.npmjs.org/w-json/-/w-json-1.3.10.tgz",
"integrity": "sha512-XadVyw0xE+oZ5FGApXsdswv96rOhStzKqL53uSe5UaTadABGkWIg1+DTx8kiZ/VqTZTBneoL0l65RcPe4W3ecw=="
},
"xml2js": {
"version": "0.5.0",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.5.0.tgz",

View File

@ -5,7 +5,9 @@
"main": "bot.js",
"dependencies": {
"config": "^3.3.9",
"edit-json-file": "^1.7.0",
"fs": "^0.0.1-security",
"fs-extra": "^11.1.1",
"irc": "^0.5.2",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",