add alias functionality
This commit is contained in:
parent
975c47246b
commit
cd33d16f4d
@ -8,14 +8,14 @@ This bot is not completed, expect bugs/crashes/errors. Use in production is disa
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
- `m!feed [USER/FEED] [ENTRIES]` - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)
|
- `m!feed [USER/FEED/ALIAS] [ENTRIES]` - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)
|
||||||
- `m!twitter [USER] [ENTRIES]` - Return the last x amount of tweets from a particular user.
|
- `m!twitter [USER] [ENTRIES]` - Return the last x amount of tweets from a particular user.
|
||||||
- `m!opt [CATEGORY] [OPTION] [VALUE]` - Control bot options, see wiki for info on usage.
|
- `m!opt [CATEGORY] [OPTION] [VALUE]` - Control bot options, see wiki for info on usage.
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
1. Install Docker (required) and Docker Compose (optional, but strongly recommended, this guide assumes you have it)
|
1. Install Docker (required) and Docker Compose (optional, but strongly recommended, this guide assumes you have it)
|
||||||
2. Rename `config/example.default.json` to `config/default.json` and modify it accordingly. A list of variables and their descriptions can be found in this repos wiki.
|
2. Rename `config/example.default.json` to `config/default.json` and modify it accordingly. A list of variables and their descriptions can be found in this repos wiki. You do not need to do anything with `example.usersettings.json` unless you wish to predefine settings prior to the bots first start, the usersettings file will be made when any options are set at runtime.
|
||||||
3. Run `docker compose up` to begin. Append `-d` to start in the background and `--build` if you make any changes to any files.
|
3. Run `docker compose up` to begin. Append `-d` to start in the background and `--build` if you make any changes to any files.
|
||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
58
bot.js
58
bot.js
@ -1,4 +1,5 @@
|
|||||||
var config = require('./config/default.json');
|
var config = require('./config/default.json');
|
||||||
|
var uconfig = require('./config/usersettings.json');
|
||||||
var irc = require("irc");
|
var irc = require("irc");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
var readline = require('readline');
|
var readline = require('readline');
|
||||||
@ -43,13 +44,13 @@ async function help(chan, sub) {
|
|||||||
bot.say(chan, '/_/ /_/ /_/\\___/_/ \\___/\\__,_/_/ \\__, / ')
|
bot.say(chan, '/_/ /_/ /_/\\___/_/ \\___/\\__,_/_/ \\__, / ')
|
||||||
bot.say(chan, ' /____/ ')
|
bot.say(chan, ' /____/ ')
|
||||||
bot.say(chan, 'Mercury RSS Client - https://git.supernets.org/hogwart7/mercury')
|
bot.say(chan, 'Mercury RSS Client - https://git.supernets.org/hogwart7/mercury')
|
||||||
bot.say(chan, 'm!feed [USER/FEED] [ENTRIES] - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)')
|
bot.say(chan, 'm!feed [USER/FEED/ALIAS] [ENTRIES] - Return the last x amount of entries from any RSS feed or your own saved feeds (if you have saved feeds)')
|
||||||
bot.say(chan, "m!twitter [USER] [ENTRIES] - Return the last x amount of tweets from a particular user")
|
bot.say(chan, "m!twitter [USER] [ENTRIES] - Return the last x amount of tweets from a particular user")
|
||||||
bot.say(chan, "m!opt [CATEGORY] [OPTION] [VALUE] - Control bot options, see wiki for info on usage.")
|
bot.say(chan, "m!opt [CATEGORY] [OPTION] [VALUE] - Control bot options, see wiki for info on usage.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function opt(chan, user, setting, setting2, value) {
|
async function opt(chan, user, setting, setting2, value, value2) {
|
||||||
//if (provfeed === undefined) {
|
//if (provfeed === undefined) {
|
||||||
// bot.say(chan, errorMsg+" No feed has been provided.")
|
// bot.say(chan, errorMsg+" No feed has been provided.")
|
||||||
// return;
|
// return;
|
||||||
@ -62,7 +63,8 @@ async function opt(chan, user, setting, setting2, value) {
|
|||||||
user,
|
user,
|
||||||
setting,
|
setting,
|
||||||
setting2,
|
setting2,
|
||||||
value
|
value,
|
||||||
|
value2
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
worker.once('message', (string) => {
|
worker.once('message', (string) => {
|
||||||
@ -81,19 +83,8 @@ async function feed(chan, nick, provfeed, n) {
|
|||||||
if (n === undefined) {
|
if (n === undefined) {
|
||||||
var n = config.feed.default_amount;
|
var n = config.feed.default_amount;
|
||||||
}
|
}
|
||||||
if (isValidUrl(provfeed) === false) {
|
|
||||||
const worker = new Worker('./commands/feed-list.js', {
|
if (isValidUrl(provfeed) === true) {
|
||||||
workerData: {
|
|
||||||
provfeed,
|
|
||||||
n,
|
|
||||||
nick
|
|
||||||
}
|
|
||||||
});
|
|
||||||
worker.once('message', (string) => {
|
|
||||||
console.log('Received output from feed-list worker, posting.');
|
|
||||||
bot.say(chan, string);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const worker = new Worker('./commands/feed-preset.js', {
|
const worker = new Worker('./commands/feed-preset.js', {
|
||||||
workerData: {
|
workerData: {
|
||||||
provfeed,
|
provfeed,
|
||||||
@ -103,6 +94,39 @@ async function feed(chan, nick, provfeed, n) {
|
|||||||
worker.once('message', (string) => {
|
worker.once('message', (string) => {
|
||||||
console.log('Received output from feed-preset worker, posting.');
|
console.log('Received output from feed-preset worker, posting.');
|
||||||
bot.say(chan, string);
|
bot.say(chan, string);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
} else if (provfeed === nick) {
|
||||||
|
if ( uconfig[nick] !== undefined ) {
|
||||||
|
const worker = new Worker('./commands/feed-list.js', {
|
||||||
|
workerData: {
|
||||||
|
provfeed,
|
||||||
|
n,
|
||||||
|
nick
|
||||||
|
}
|
||||||
|
});
|
||||||
|
worker.once('message', (string) => {
|
||||||
|
console.log('Received output from feed-list worker, posting.');
|
||||||
|
bot.say(chan, string);
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
bot.say(chan, "You have no saved feeds")
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (uconfig[nick].alias !== undefined ) {
|
||||||
|
var provfeed = uconfig[nick].alias[provfeed]
|
||||||
|
const worker = new Worker('./commands/feed-preset.js', {
|
||||||
|
workerData: {
|
||||||
|
provfeed,
|
||||||
|
n,
|
||||||
|
nick
|
||||||
|
}
|
||||||
|
});
|
||||||
|
worker.once('message', (string) => {
|
||||||
|
console.log('Received output from feed-list worker, posting.');
|
||||||
|
bot.say(chan, string);
|
||||||
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +160,7 @@ bot.addListener('message', function(nick, to, text, from) {
|
|||||||
} else if (args[0] === config.irc.prefix+'twitter') {
|
} else if (args[0] === config.irc.prefix+'twitter') {
|
||||||
twitter(to, args[1], args[2])
|
twitter(to, args[1], args[2])
|
||||||
} else if (args[0] === config.irc.prefix+'opt') {
|
} else if (args[0] === config.irc.prefix+'opt') {
|
||||||
opt(to, nick, args[1], args[2], args[3])
|
opt(to, nick, args[1], args[2], args[3], args[4])
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
const config = require('../config/default.json')
|
const config = require('../config/default.json')
|
||||||
const uconfig = require('../config/usersettings.json')
|
const uconfig = require('../config/usersettings.json')
|
||||||
const { parentPort, workerData } = require('worker_threads');
|
const { parentPort, workerData } = require('worker_threads');
|
||||||
const { user, setting, setting2, value } = workerData;
|
const { user, setting, setting2, value, value2 } = workerData;
|
||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
let Parser = require('rss-parser');
|
let Parser = require('rss-parser');
|
||||||
let parser = new Parser({
|
let parser = new Parser({
|
||||||
headers: {'User-Agent': config.feed.useragent},
|
headers: {'User-Agent': config.feed.useragent},
|
||||||
});
|
});
|
||||||
const editJsonFile = require("edit-json-file");
|
const editJsonFile = require("edit-json-file");
|
||||||
const { getDefaultHighWaterMark } = require('stream');
|
|
||||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||||
|
|
||||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||||
@ -42,8 +41,10 @@ function errorMessage(error, code, extra) {
|
|||||||
|
|
||||||
async function testFeed(feedURL) {
|
async function testFeed(feedURL) {
|
||||||
try {
|
try {
|
||||||
|
console.log('Testing feed')
|
||||||
var feed = await parser.parseURL(feedURL);
|
var feed = await parser.parseURL(feedURL);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
errorMessage(e, "INVALID", feedURL);
|
errorMessage(e, "INVALID", feedURL);
|
||||||
}
|
}
|
||||||
console.log(feed)
|
console.log(feed)
|
||||||
@ -80,6 +81,34 @@ async function feed(nick, setting, value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function alias(setting, value, url, nick) {
|
||||||
|
if (setting === 'add') {
|
||||||
|
await testFeed(url);
|
||||||
|
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
||||||
|
file.set(nick+'.alias.'+value, url);
|
||||||
|
file.save();
|
||||||
|
sendUpstream('Alias added ('+value+' ==> '+url+')')
|
||||||
|
}
|
||||||
|
if (setting === 'del') {
|
||||||
|
var file = editJsonFile('/home/node/app/config/usersettings.json');
|
||||||
|
file.set(nick+'.alias.'+value, "");
|
||||||
|
file.save();
|
||||||
|
sendUpstream('Alias removed ('+value+' ==> BTFO\'d)')
|
||||||
|
}
|
||||||
|
if (setting === 'list') {
|
||||||
|
content = [];
|
||||||
|
var obj = uconfig[nick].alias
|
||||||
|
console.log(obj)
|
||||||
|
for (const [key, val] of Object.entries(obj)) {
|
||||||
|
if (val !== "") {
|
||||||
|
content.push(key + ' ==> '+val)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var output = content.join("\n")
|
||||||
|
sendUpstream(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function get(setting) {
|
async function get(setting) {
|
||||||
var file = editJsonFile('/home/node/app/config/default.json')
|
var file = editJsonFile('/home/node/app/config/default.json')
|
||||||
console.log(file.get(setting));
|
console.log(file.get(setting));
|
||||||
@ -92,4 +121,6 @@ if (setting === 'feed') {
|
|||||||
feed(user, setting2)
|
feed(user, setting2)
|
||||||
} else if (setting === 'get') {
|
} else if (setting === 'get') {
|
||||||
get(setting2);
|
get(setting2);
|
||||||
|
} else if(setting === 'alias') {
|
||||||
|
alias(setting2, value, value2, user)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
{
|
{
|
||||||
"example": {
|
"nickname": {
|
||||||
"feeds": [
|
"feeds": [
|
||||||
"https://git.supernets.org/hogwart7/mercury.rss",
|
"https://git.supernets.org/hogwart7/mercury.rss",
|
||||||
"https://git.supernets.org/hogwart7/fascinus.rss"
|
"https://git.supernets.org/hogwart7/fascinus.rss"
|
||||||
]
|
],
|
||||||
|
"alias": {
|
||||||
|
"AUR": "https://aur.archlinux.org/rss"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user