mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-23 15:47:57 -05:00
78 lines
1.9 KiB
JavaScript
78 lines
1.9 KiB
JavaScript
/* eslint-disable max-len */
|
|
/* eslint-disable no-var */
|
|
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();
|
|
});
|
|
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').on('SIGINT', () => {
|
|
bots[server].kill();
|
|
require('process').exit();
|
|
});
|
|
});
|
|
}
|
|
|
|
for (const server of config.servers) {
|
|
start(server.host, server.port);
|
|
}
|