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
|
||||
|
||||
- `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!opt [CATEGORY] [OPTION] [VALUE]` - Control bot options, see wiki for info on usage.
|
||||
|
||||
## Deployment
|
||||
|
||||
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.
|
||||
|
||||
## Support
|
||||
|
58
bot.js
58
bot.js
@ -1,4 +1,5 @@
|
||||
var config = require('./config/default.json');
|
||||
var uconfig = require('./config/usersettings.json');
|
||||
var irc = require("irc");
|
||||
var fs = require("fs");
|
||||
var readline = require('readline');
|
||||
@ -43,13 +44,13 @@ async function help(chan, sub) {
|
||||
bot.say(chan, '/_/ /_/ /_/\\___/_/ \\___/\\__,_/_/ \\__, / ')
|
||||
bot.say(chan, ' /____/ ')
|
||||
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!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) {
|
||||
// bot.say(chan, errorMsg+" No feed has been provided.")
|
||||
// return;
|
||||
@ -62,7 +63,8 @@ async function opt(chan, user, setting, setting2, value) {
|
||||
user,
|
||||
setting,
|
||||
setting2,
|
||||
value
|
||||
value,
|
||||
value2
|
||||
}
|
||||
});
|
||||
worker.once('message', (string) => {
|
||||
@ -81,19 +83,8 @@ async function feed(chan, nick, provfeed, n) {
|
||||
if (n === undefined) {
|
||||
var n = config.feed.default_amount;
|
||||
}
|
||||
if (isValidUrl(provfeed) === false) {
|
||||
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);
|
||||
});
|
||||
} else {
|
||||
|
||||
if (isValidUrl(provfeed) === true) {
|
||||
const worker = new Worker('./commands/feed-preset.js', {
|
||||
workerData: {
|
||||
provfeed,
|
||||
@ -103,6 +94,39 @@ async function feed(chan, nick, provfeed, n) {
|
||||
worker.once('message', (string) => {
|
||||
console.log('Received output from feed-preset worker, posting.');
|
||||
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') {
|
||||
twitter(to, args[1], args[2])
|
||||
} 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 uconfig = require('../config/usersettings.json')
|
||||
const { parentPort, workerData } = require('worker_threads');
|
||||
const { user, setting, setting2, value } = workerData;
|
||||
const { user, setting, setting2, value, value2 } = workerData;
|
||||
const fs = require('fs-extra')
|
||||
let Parser = require('rss-parser');
|
||||
let parser = new Parser({
|
||||
headers: {'User-Agent': config.feed.useragent},
|
||||
});
|
||||
const editJsonFile = require("edit-json-file");
|
||||
const { getDefaultHighWaterMark } = require('stream');
|
||||
const timer = ms => new Promise(res => setTimeout(res, ms))
|
||||
|
||||
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
|
||||
@ -42,8 +41,10 @@ function errorMessage(error, code, extra) {
|
||||
|
||||
async function testFeed(feedURL) {
|
||||
try {
|
||||
console.log('Testing feed')
|
||||
var feed = await parser.parseURL(feedURL);
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
errorMessage(e, "INVALID", feedURL);
|
||||
}
|
||||
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) {
|
||||
var file = editJsonFile('/home/node/app/config/default.json')
|
||||
console.log(file.get(setting));
|
||||
@ -92,4 +121,6 @@ if (setting === 'feed') {
|
||||
feed(user, setting2)
|
||||
} else if (setting === 'get') {
|
||||
get(setting2);
|
||||
} else if(setting === 'alias') {
|
||||
alias(setting2, value, value2, user)
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
{
|
||||
"example": {
|
||||
"nickname": {
|
||||
"feeds": [
|
||||
"https://git.supernets.org/hogwart7/mercury.rss",
|
||||
"https://git.supernets.org/hogwart7/fascinus.rss"
|
||||
]
|
||||
],
|
||||
"alias": {
|
||||
"AUR": "https://aur.archlinux.org/rss"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user