goodbye run.js you will be missed

This commit is contained in:
ChomeNS 2022-11-15 16:13:51 +07:00
parent 9b5ebe4cc0
commit 38813c9ae8
2 changed files with 1 additions and 83 deletions

View file

@ -2,7 +2,7 @@
"name": "bot",
"version": "1.0.0",
"description": "",
"main": "run.js",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ."

82
run.js
View file

@ -1,82 +0,0 @@
/* eslint-disable max-len */
const readline = require('node:readline');
const {stdin: input, stdout: output} = require('node:process');
const rl = readline.createInterface({input, output});
const process = require('child_process');
const config = require('./config');
require('./uptime');
rl.setMaxListeners(Infinity);
const bots = {};
/**
* the start function
* @param {String} host
* @param {Number} port
*/
function start(host, port) {
const server = host;
let theServer;
bots[server] = process.exec('node index.js ' + host);
if (host=='sus.shhnowisnottheti.me') {
theServer = 'ayunboom';
}
if (host=='129.159.58.114') {
theServer = 'dinboom';
}
if (host=='play.kaboom.pw') {
theServer = 'kaboom';
}
if (host=='192.168.1.103') {
theServer = 'local';
}
if (host=='kitsune.icu') {
theServer = 'kitsune';
}
if (host=='mc.chomens41793.ga') {
theServer = 'chomens';
}
eval(`${theServer} = []`);
eval(`${theServer}loop = setInterval(() => {
if (${theServer}[0]) {
bots[server].stdin.write(${theServer}.at(0) + '\\n');
${theServer} = [];
}
}, 0)`);
bots[server].on('close', function() {
bots[server].kill();
eval(`clearInterval(${theServer}loop)`);
start(server);
});
bots[server].stdout.on('data', function(chunk) {
rl.output.write('\x1b[2K\r');
require('process').stdout.write(`${chunk}`);
rl._refreshLine();
});
bots[server].stderr.on('data', function(chunk) {
rl.output.write('\x1b[2K\r');
require('process').stderr.write(`${chunk}`);
rl._refreshLine();
});
rl.on('line', (line) => {
if (line.startsWith('/send ')) {
try {
const args = line.substring(1).trim().split(' ');
eval(`${args.at(1)}.push(args.slice(2).join(' ').toString())`);
} catch (e) {
console.log('Invalid.');
}
return;
}
bots[server].stdin.write(line + '\n');
require('process').once('SIGINT', () => {
bots[server].kill();
require('process').exit();
});
});
}
for (const server of config.servers) {
start(server.host, server.port);
}