bones conv: move all commands to their own files

This commit is contained in:
hgw 2023-10-03 00:20:43 +00:00
parent f963db9432
commit e5a8baaa81
Signed by: hgw
SSH Key Fingerprint: SHA256:diG7RVYHjd3aDYkZWHYcBJbImu+6zfptuUP+3k/wol4
8 changed files with 429 additions and 170 deletions

209
bot.js
View File

@ -1,11 +1,13 @@
var config = require('./config/config.json') var config = require('./config/config.json')
var irc = require("irc"); var irc = require("irc");
var fs = require("fs");
var readline = require('readline');
var path = require('path');
var randomext = require('./lib/randomnum');
const { Worker } = require('worker_threads'); const { Worker } = require('worker_threads');
//var randomWords = require('better-random-words');
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
const msgTimeout = new Set();
const msgTimeoutMsg = new Set();
const timer = ms => new Promise(res => setTimeout(res, ms))
var hostmask = null
var bot = new irc.Client(config.irc.server, config.irc.nickname, { var bot = new irc.Client(config.irc.server, config.irc.nickname, {
channels: config.irc.channels, channels: config.irc.channels,
@ -18,56 +20,28 @@ var bot = new irc.Client(config.irc.server, config.irc.nickname, {
floodProtectionDelay: config.floodprotect.flood_protection_delay floodProtectionDelay: config.floodprotect.flood_protection_delay
}); });
const msgTimeout = new Set(); function consoleLog(log) {
const msgTimeoutMsg = new Set(); if (config.misc.logging === "true") {
console.log(log)
const timer = ms => new Promise(res => setTimeout(res, ms))
const generateRandomString = (amt) => {
const chars =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890`!@#$%^&*()_+{}|\"\',./ᘈᷞኬᲡ᩶ᐨᅚ⸗⡳ᾟⓅᤲ⧛ሥ⸰⯠ᬨ⧻Შ⼷ᢕ᭄◁ⱉጻ៾᪅⎑ᘂᏤ⛰⃡";
const randomArray = Array.from(
{ length: amt },
(v, k) => chars[Math.floor(Math.random() * chars.length)]
);
const randomString = randomArray.join("");
return randomString;
}
async function help(chan) {
bot.say(chan, 'Fascinus - https://git.supernets.org/hogwart7/fascinus')
bot.say(chan, "$flood [AMOUNT (max=10000)] [TEXT] - Floods the channel with a specific line x amount of times")
bot.say(chan, "$ctcpflood [TARGET] [TEXT (one word)] [AMOUNT] - Sends x amount of CTCP requests to a target.")
bot.say(chan, "$sneed - Pastes the Sneed's Feed and Seed copypasta.")
bot.say(chan, "$rspam [LINES (def=100, max=10000)] - Spams x lines of random characters")
bot.say(chan, "$uspam [LINES (def=100, max=10000)] - Spams x lines of random unicode characters of varying length")
bot.say(chan, "$art [IMAGE URL (png/jpg/webp/jpeg)] - Creates IRC art using a source image.")
bot.say(chan, "$godwords [AMOUNT (def=50, max=100000)] - Generate x amount of random words. Inspired by TempleOS.")
}
async function flood(chan, arg) {
arg.shift() //$flood
let amt = arg.shift() //number
var text = arg.join(" ")
if (amt > 100000) {
bot.say(chan, "no");
} else { } else {
for(var i=0; i < amt; i++){ return;
bot.say(chan, text);
}
} }
} }
async function sneed(chan) { function openPostWorker(chan, command, d1, d2, d3, d4, d5, d6) {
bot.say(chan, 'THE SIGN IS A SUBTLE JOKE. THE SHOP IS CALLED \"SNEED\'S FEED & SEED\", WHERE') consoleLog(`[bot.openPostWorker] Opening ${command} worker`)
bot.say(chan, 'FEED AND SEED BOTH END IN THE SOUND "-EED", THUS RHYMING WITH THE NAME OF') const worker = new Worker(`./commands/${command}.js`, {
bot.say(chan, 'THE OWNER, SNEED. THE SIGN SAYS THAT THE SHOP WAS "FORMERLY CHUCK\'S", IMPLYING') workerData: {
bot.say(chan, 'THAT THE TWO WORDS BEGINNING WITH "F" AND "S" WOULD HAVE ENDED WITH "-UCK",') d1, d2, d3, d4, d5, d6 //d1-d6 equate to variables you can pass in to a worker, see the example1 block below for an example (var1 there is d1 here). Further defined in individual command files.
bot.say(chan, 'RHYMING WITH "CHUCK". SO, WHEN CHUCK OWNED THE SHOP, IT WOULD HAVE BEEN CALLED') }
bot.say(chan, '"CHUCK\'S FUCK AND SUCK".') });
worker.once('message', (string) => {
consoleLog(`[bot.openPostWorker.finalising] Got output from ${command}, sending to `+chan);
bot.say(chan, string);
});
} }
async function ctcp(target, text, amt) { async function ctcp(target, text, amt) { //This can not be moved to its own file due to the nature of how it works
if (amt > 10000) { if (amt > 10000) {
bot.say(chan, "no"); bot.say(chan, "no");
} else { } else {
@ -78,123 +52,37 @@ async function ctcp(target, text, amt) {
} }
} }
async function help(chan) {
openPostWorker(chan, 'help')
}
async function flood(chan, arg) {
openPostWorker(chan, 'flood', arg)
}
async function sneed(chan) {
openPostWorker(chan, 'sneed')
}
async function uspam(chan, amt) { async function uspam(chan, amt) {
var arr = []; openPostWorker(chan, 'uspam', amt)
if (amt > 10000) {
bot.say(chan, "no")
} else {
if (amt === undefined) {
var amt = 100
}
for(var i=0; i < amt; i++){
var string = "" + randomext.integer(9,0) + "," + randomext.integer(9,0) + randomext.uString(120,60);
await timer(2);
arr.push(string)
}
var output = arr.join("\n")
bot.say(chan, output);
}
} }
async function rspam(chan, amt) { async function rspam(chan, amt) {
var arr = [] openPostWorker(chan, 'rspam', amt)
if (amt > 10000) {
bot.say(chan, "no")
} else {
if (amt === undefined) {
var amt = 100
}
for(var i=0; i < amt; i++){
var string = generateRandomString(70);
await timer(2);
arr.push(string)
}
var output = arr.join("\n")
bot.say(chan, output);
}
} }
async function art(chan, url) { async function art(chan, url) {
var ext = path.extname(url) openPostWorker(chan, 'art', url)
if (ext === ".png") {
var filetype = "png"
} else if (ext === ".jpg") {
var filetype = "jpg"
} else if (ext === ".webp") {
var filetype = "webp"
} else if (ext === ".jpeg") {
var filetype = "jpeg"
} else {
bot.say(chan, "Image must be PNG, JPG, JPEG, WEBP");
return
}
console.log("Starting Banter")
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python3', ["lib/banter/banter.py", url, "-t", filetype])
pythonProcess.stdout.on('data', (data) => {
console.log(data.toString())
});
await timer(5000);
fs.stat('output.txt', function(err, stat) {
if (err == null) {
console.log('File exists');
const rl = readline.createInterface({
input: fs.createReadStream('output.txt'),
crlfDelay: Infinity,
});
rl.on('line', (line) => {
bot.say(chan, line);
});
} else if (err.code === 'ENOENT') {
console.log(err);
bot.say(chan, "Error")
} else {
bot.say(chan, "Other Error")
}
});
} }
async function godwords(chan, amt) { async function godwords(chan, amt) {
if (amt > 100000) { openPostWorker(chan, 'godwords', amt)
bot.say(chan, "no")
} else {
if (amt === undefined) {
var amt = 50
}
const worker = new Worker('./commands/godwords.js', {
workerData: {
amt
}
});
worker.once('message', (string) => {
console.log('Received string from worker, posting.');
bot.say(chan, string);
});
}
} }
bot.addListener('message', function(nick, to, text, from) { async function phish(chan, height, width) {
var args = text.split(' '); openPostWorker(chan, 'phish', height, width)
if (args[0] === '$help') {
help(to);
} else if (args[0] === '$flood') {
flood(to, args)
} else if (args[0] === '$sneed') {
sneed(to);
} else if (args[0] === '$ctcpflood') {
ctcp(args[1], args[2], args[3]);
} else if (args[0] === '$rspam') {
rspam(to, args[1])
} else if (args[0] === '$uspam') {
uspam(to, args[1]);
} else if (args[0] === '$art') {
art(to, args[1]);
} else if (args[0] === 'fart') {
art(to, args[1]);
} else if (args[0] === '$godwords') {
godwords(to, args[1]);
} }
});
bot.addListener('message', function(nick, to, text, from) { bot.addListener('message', function(nick, to, text, from) {
if (text.startsWith(config.irc.prefix)) { if (text.startsWith(config.irc.prefix)) {
@ -225,10 +113,10 @@ bot.addListener('message', function(nick, to, text, from) {
uspam(to, args[1]); uspam(to, args[1]);
} else if (command === config.irc.prefix+'art') { } else if (command === config.irc.prefix+'art') {
art(to, args[1]); art(to, args[1]);
} else if (command === config.irc.prefix+'fart') {
art(to, args[1]);
} else if (command === config.irc.prefix+'godwords') { } else if (command === config.irc.prefix+'godwords') {
godwords(to, args[1]); godwords(to, args[1]);
} else if (command === config.irc.prefix+'phish') {
phish(to, args[1], args[2])
} }
msgTimeout.add(to); msgTimeout.add(to);
setTimeout(() => { setTimeout(() => {
@ -240,7 +128,14 @@ bot.addListener('message', function(nick, to, text, from) {
bot.addListener('error', function(message) { bot.addListener('error', function(message) {
console.log('error: ', message); consoleLog('[ERROR]' +message) //Dump errors to console
}); });
console.log('Starting Fascinus'); process.on('uncaughtException', function (err) {
console.error(err);
if (config.errorhandling.log_errors_to_irc == 'true') { //If logging errors to IRC is enabled then we send the error to that, otherwise we only consoleLog it
bot.say(config.errorhandling.error_channel, errorMsg+" "+err.stack.split('\n',1).join(" "))
}
});
consoleLog('Starting Fascinus');

60
commands/art.js Normal file
View File

@ -0,0 +1,60 @@
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const { d1 } = workerData;
var url = d1
var path = require('path');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[art.errorMessage] '+error.code)
if (code == "ENOENT") {
var error = errorMsg+" ENOENT"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
async function generate(url) {
output = []
var ext = path.extname(url)
if (ext === ".png") {
var filetype = "png"
} else if (ext === ".jpg") {
var filetype = "jpg"
} else if (ext === ".webp") {
var filetype = "webp"
} else if (ext === ".jpeg") {
var filetype = "jpeg"
} else {
consoleLog('[art] Invalid image passed')
sendUpstream(errorMsg+" Image must be PNG, JPG, JPEG, WEBP");
}
consoleLog("[art] Starting banter.py process")
const spawn = require("child_process").spawn;
const pythonProcess = spawn('python3', ["/home/node/app/lib/banter/banter.py", url, "-t", filetype])
pythonProcess.stdout.on('data', (data) => {
output.push(data.toString())
});
await timer(5000);
sendUpstream(output.join('\n'))
}
generate(url)

50
commands/flood.js Normal file
View File

@ -0,0 +1,50 @@
const { error } = require('console');
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const { d1 } = workerData; //Declare all used variables here (if you only pass 1 variable to this command you only really need d1 in here, but it doesnt matter)
var arg = d1; // Declaring d1 as var1, just for consistancy with the last file but again, this may not be necessary in all cases.
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[uspam.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else if (code == "TOOLARGE") {
var error = errorMsg+" Your request is too large (Maximum is 100000)"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
var arr = []
arg.shift() //$flood
var amt = arg.shift() //number
var text = arg.join(" ")
if (amt > 100000) {
consoleLog('[flood] Request too large was made, killing worker')
errorMessage("error", "TOOLARGE")
} else {
for(var i=0; i < amt; i++){
arr.push(text)
}
}
var output = arr.join("\n")
sendUpstream(output)

View File

@ -1,7 +1,41 @@
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads'); const { parentPort, workerData } = require('worker_threads');
const { amt } = workerData; const { d1 } = workerData;
var amt = d1
var randomWords = require('../lib/randomword'); var randomWords = require('../lib/randomword');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[godwords.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else if (code == "TOOLARGE") {
var error = errorMsg+" Your request is too large (Maximum is 10000)"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
function gen(amt) {
consoleLog('[godwords.gen] Generating godwords output')
var output = []; var output = [];
var string = []; var string = [];
var text = []; var text = [];
@ -10,7 +44,16 @@ for(var i=0; i < amt; i++){
text.push(word); text.push(word);
} }
var string = text.join(" ") var string = text.join(" ")
output.push(string); output.push(string);
parentPort.postMessage(output); sendUpstream(output);
process.exit() }
if (amt > 10000) {
consoleLog('[godwords] Request too large was made, killing worker')
errorMessage("error", "TOOLARGE")
} else {
if (amt === undefined) {
var amt = 50
}
gen(amt)
}

43
commands/help.js Normal file
View File

@ -0,0 +1,43 @@
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[help.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
var output = []
output.push('Fascinus - https://git.supernets.org/hgw/fascinus')
output.push("$flood [AMOUNT (max=10000)] [TEXT] - Floods the channel with a specific line x amount of times")
output.push("$ctcpflood [TARGET] [TEXT (one word)] [AMOUNT] - Sends x amount of CTCP requests to a target.")
output.push("$sneed - Pastes the Sneed's Feed and Seed copypasta.")
output.push("$rspam [LINES (def=100, max=10000)] - Spams x lines of random characters")
output.push("$uspam [LINES (def=100, max=10000)] - Spams x lines of random unicode characters of varying length")
output.push("$art [IMAGE URL (png/jpg/webp/jpeg)] - Creates IRC art using a source image.")
output.push("$godwords [AMOUNT (def=50, max=100000)] - Generate x amount of random words. Inspired by TempleOS.")
output.push("$phish [HEIGHT (opt, max=100)] [WIDTH (opt, max=100)] - Generate an aquarium")
sendUpstream(output.join('\n'))

64
commands/rspam.js Normal file
View File

@ -0,0 +1,64 @@
const { error } = require('console');
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const { d1 } = workerData; //Declare all used variables here (if you only pass 1 variable to this command you only really need d1 in here, but it doesnt matter)
var amt = d1; // Declaring d1 as var1, just for consistancy with the last file but again, this may not be necessary in all cases.
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[rspam.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else if (code == "TOOLARGE") {
var error = errorMsg+" Your request is too large (Maximum is 10000)"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
const generateRandomString = (amt) => {
const chars =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890`!@#$%^&*()_+{}|\"\',./ᘈᷞኬᲡ᩶ᐨᅚ⸗⡳ᾟⓅᤲ⧛ሥ⸰⯠ᬨ⧻Შ⼷ᢕ᭄◁ⱉጻ៾᪅⎑ᘂᏤ⛰⃡";
const randomArray = Array.from(
{ length: amt },
(v, k) => chars[Math.floor(Math.random() * chars.length)]
);
const randomString = randomArray.join("");
return randomString;
}
var arr = []
if (amt > 10000) {
consoleLog('[rpsam] Request too large was made, killing worker')
errorMessage("error", "TOOLARGE")
} else {
if (amt === undefined) {
consoleLog('[rspam] Amount was not defined, defaulting to 100')
var amt = 100
}
for(var i=0; i < amt; i++){
var string = generateRandomString(70);
timer(2);
arr.push(string)
}
var output = arr.join("\n")
sendUpstream(output)
}

39
commands/sneed.js Normal file
View File

@ -0,0 +1,39 @@
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const timer = ms => new Promise(res => setTimeout(res, ms))
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[sneed.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
output = []
output.push('THE SIGN IS A SUBTLE JOKE. THE SHOP IS CALLED \"SNEED\'S FEED & SEED\", WHERE')
output.push('FEED AND SEED BOTH END IN THE SOUND "-EED", THUS RHYMING WITH THE NAME OF')
output.push('THE OWNER, SNEED. THE SIGN SAYS THAT THE SHOP WAS "FORMERLY CHUCK\'S", IMPLYING')
output.push('THAT THE TWO WORDS BEGINNING WITH "F" AND "S" WOULD HAVE ENDED WITH "-UCK",')
output.push('RHYMING WITH "CHUCK". SO, WHEN CHUCK OWNED THE SHOP, IT WOULD HAVE BEEN CALLED')
output.push('"CHUCK\'S FUCK AND SUCK".')
sendUpstream(output.join("\n"))

65
commands/uspam.js Normal file
View File

@ -0,0 +1,65 @@
const { error } = require('console');
const config = require('../config/config.json')
const { parentPort, workerData } = require('worker_threads');
const { d1 } = workerData; //Declare all used variables here (if you only pass 1 variable to this command you only really need d1 in here, but it doesnt matter)
var amt = d1; // Declaring d1 as var1, just for consistancy with the last file but again, this may not be necessary in all cases.
const timer = ms => new Promise(res => setTimeout(res, ms))
var randomext = require('../lib/randomnum');
warningMsg = ''+config.colours.brackets+'['+config.colours.warning+'WARNING'+config.colours.brackets+']'
errorMsg = ''+config.colours.brackets+'['+config.colours.error+'ERROR'+config.colours.brackets+']'
function consoleLog(log) {
if (config.misc.logging === "true") {
console.log(log)
} else {
return;
}
}
function errorMessage(error, code, extra) {
consoleLog('[uspam.errorMessage] '+error.code)
if (code == "BAD") {
var error = errorMsg+" SHITS_FUCKED_MAN: " + extra + " not found"
} else if (code == "TOOLARGE") {
var error = errorMsg+" Your request is too large (Maximum is 10000)"
} else {
var error = errorMsg+" Unknown error"
}
parentPort.postMessage(error);
process.exit()
}
async function sendUpstream(content) {
parentPort.postMessage(content);
process.exit()
}
const generateRandomString = (amt) => {
const chars =
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890`!@#$%^&*()_+{}|\"\',./ᘈᷞኬᲡ᩶ᐨᅚ⸗⡳ᾟⓅᤲ⧛ሥ⸰⯠ᬨ⧻Შ⼷ᢕ᭄◁ⱉጻ៾᪅⎑ᘂᏤ⛰⃡";
const randomArray = Array.from(
{ length: amt },
(v, k) => chars[Math.floor(Math.random() * chars.length)]
);
const randomString = randomArray.join("");
return randomString;
}
var arr = []
if (amt > 10000) {
consoleLog('[uspam] Request too large was made, killing worker')
errorMessage("error", "TOOLARGE")
} else {
if (amt === undefined) {
consoleLog('[uspam] Amount was not defined, defaulting to 100')
var amt = 100
}
for(var i=0; i < amt; i++){
var string = "" + randomext.integer(9,0) + "," + randomext.integer(9,0) + randomext.uString(120,60);
timer(2);
arr.push(string)
}
var output = arr.join("\n")
sendUpstream(output)
}