This commit is contained in:
ChomeNS 2022-11-09 17:15:59 +07:00
parent c972240c28
commit a507fe019e

140
index.js
View file

@ -1,7 +1,7 @@
/* eslint-disable max-len */
/* eslint-disable no-var */ /* eslint-disable no-var */
/* eslint-disable prefer-rest-params */ /* eslint-disable prefer-rest-params */
/* eslint-disable no-tabs */ /* eslint-disable no-tabs */
/* eslint-disable max-len */
/* eslint-disable no-undef */ /* eslint-disable no-undef */
const mc = require('minecraft-protocol'); const mc = require('minecraft-protocol');
const config = require('./config'); const config = require('./config');
@ -65,7 +65,9 @@ function dcmsg() {
function botThings() { function botThings() {
bot = new EventEmitter(); bot = new EventEmitter();
bot.options = { bot.options = {
username: process.argv[2] === 'mc.chomens41793.ga' ? 'ChomeNS_Bot' : randomstring.generate(16), username: process.argv[2] === 'mc.chomens41793.ga' ?
'ChomeNS_Bot' :
randomstring.generate(16),
host: process.argv[2], host: process.argv[2],
port: process.argv[3] ? Number(process.argv[3]) : 25565, port: process.argv[3] ? Number(process.argv[3]) : 25565,
version: config.version, version: config.version,
@ -133,7 +135,12 @@ function main() {
discordQueue = setInterval(function() { discordQueue = setInterval(function() {
if (dcmsg.queue!='') { if (dcmsg.queue!='') {
channel.send({content: '```ansi\n' + dcmsg.queue.substring(0, 1986) + '\n```', allowedMentions: {parse: []}}); channel.send({
content: '```ansi\n' + dcmsg.queue.substring(0, 1986) + '\n```',
allowedMentions: {
parse: [],
},
});
dcmsg.queue = ''; dcmsg.queue = '';
} }
}, 1000); }, 1000);
@ -142,21 +149,32 @@ function main() {
if (!messageloggingEnabled) return; if (!messageloggingEnabled) return;
if (consoleQueue.length > 50) consoleQueue = []; if (consoleQueue.length > 50) consoleQueue = [];
if (consoleQueue[0] || consoleQueue[0] === '') { if (consoleQueue[0] || consoleQueue[0] === '') {
console.log('\u001b[48:5:208m' + bot.options.host + '\u001b[0m' + ': ' + consoleQueue[0].substring(0, 10000)/* message.toAnsi() + '\u001b[0m'*/); console.log(
'\u001b[48:5:208m' +
bot.options.host +
'\u001b[0m' +
': ' +
consoleQueue[0].substring(0, 10000),
);
consoleQueue.shift(); consoleQueue.shift();
} }
}, 100); }, 100);
bot.once('end', (reason, event) => { bot.once('end', (reason, event) => {
console.log(`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`); console.log(
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
);
channel.send(`Disconnected: \`${util.inspect(reason)}\``); channel.send(`Disconnected: \`${util.inspect(reason)}\``);
let timeout = config.reconnectTimeout; let timeout = config.reconnectTimeout;
try { try {
if (reason.text) { if (reason.text) {
if (reason.text === 'Wait 5 seconds before connecting, thanks! :)') timeout = 1000 * 6; if (reason.text ===
if (reason.text === 'You are logging in too fast, try again later.') timeout = 1000 * 6; 'Wait 5 seconds before connecting, thanks! :)' ||
reason.text ===
'You are logging in too fast, try again later.'
) timeout = 1000 * 7;
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
@ -184,8 +202,12 @@ function main() {
bot.username = bot._client.username; bot.username = bot._client.username;
chatMessage = require('prismarine-chat')(bot.version); chatMessage = require('prismarine-chat')(bot.version);
const mcData = require('minecraft-data')(bot.version); const mcData = require('minecraft-data')(bot.version);
console.log(`Successfully logged in to: ${bot.options.host}:${bot.options.port}`); console.log(
channel.send(`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``); `Successfully logged in to: ${bot.options.host}:${bot.options.port}`,
);
channel.send(
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``,
);
previusMessage = undefined; previusMessage = undefined;
loginfinish = false; loginfinish = false;
started = false; started = false;
@ -209,7 +231,9 @@ function main() {
crypto, crypto,
colorConvert, colorConvert,
bruhifyText: function(message) { bruhifyText: function(message) {
if (typeof message !== 'string') throw new SyntaxError('message must be a string'); if (
typeof message !== 'string'
) throw new SyntaxError('message must be a string');
bot.bruhifyText = message.substring(0, 1000); bot.bruhifyText = message.substring(0, 1000);
}, },
generateEaglerUsername, generateEaglerUsername,
@ -222,11 +246,29 @@ function main() {
loginfinish = true; loginfinish = true;
await sleep(1400); await sleep(1400);
bot.tellraw('@a', [{text: 'ChomeNS Bot', color: 'yellow'}, {text: ' - ', color: 'dark_gray'}, {text: 'made by ', color: 'gray'}, {text: 'chayapak', color: 'gold'}]); bot.tellraw('@a', [
{
text: 'ChomeNS Bot',
color: 'yellow',
},
{
text: ' - ',
color: 'dark_gray',
},
{
text: 'made by ',
color: 'gray',
},
{
text: 'chayapak',
color: 'gold',
},
]);
}); });
bot.on('parsed_chat', async function(message, data) { bot.on('parsed_chat', async function(message, data) {
// try catch prevents hi % exploit (it uses prismarine-chat) and json parse error // try catch prevents hi % exploit (it uses prismarine-chat)
// and try catch also prevents json parse error
try { try {
if (previusMessage === message.toString()) return; if (previusMessage === message.toString()) return;
previusMessage = message.toString(); previusMessage = message.toString();
@ -242,7 +284,10 @@ function main() {
if (message.toString().includes('⣿')) return; if (message.toString().includes('⣿')) return;
const cleanMessage = escapeMarkdown(message.toAnsi(), true); const cleanMessage = escapeMarkdown(message.toAnsi(), true);
discordMsg = /* '_ _ ' + */cleanMessage.replaceAll('@', '@\u200b\u200b\u200b\u200b\u200b').replaceAll('http', 'http\u200b\u200b\u200b\u200b\u200b').replaceAll('\u001b[9', '\u001b[3');// .replace(/[\r\n]/gm, '\n') discordMsg = cleanMessage
.replaceAll('@', '@\u200b')
.replaceAll('http', 'http\u200b')
.replaceAll('\u001b[9', '\u001b[3');
consoleQueue.push(message.toAnsi()); consoleQueue.push(message.toAnsi());
@ -262,8 +307,12 @@ function main() {
bot.emit('end', reason, 'end'); bot.emit('end', reason, 'end');
}); });
bot._client.on('keep_alive', (packet) => bot.write('keep_alive', {keepAliveId: packet.keepAliveId})); bot._client.on('keep_alive', (packet) => {
bot._client.on('game_state_change', () => bot.write('client_command', {payload: 0})); bot.write('keep_alive', {keepAliveId: packet.keepAliveId});
});
bot._client.on('game_state_change', () => {
bot.write('client_command', {payload: 0});
});
bot._client.on('kick_disconnect', function(data) { bot._client.on('kick_disconnect', function(data) {
const parsed = JSON.parse(data.reason); const parsed = JSON.parse(data.reason);
@ -322,14 +371,18 @@ dcclient.on('ready', async () => {
// Console COMMANDS // Console COMMANDS
rl.on('line', function(line) { rl.on('line', function(line) {
try { try {
if (line.toLowerCase() === '' || line.toLowerCase().startsWith(' ')) return; if (line.toLowerCase() === '' ||
line.toLowerCase().startsWith(' ')) return;
if (line.toLowerCase() === '.exit' || line.toLowerCase() === '.end') { if (line.toLowerCase() === '.exit' || line.toLowerCase() === '.end') {
bot.emit('end', 'end command'); bot.emit('end', 'end command');
return; return;
} }
if (line.toLowerCase().startsWith('.servereval ')) { if (line.toLowerCase().startsWith('.servereval ')) {
try { try {
bot.tellraw('@a', {text: `${util.inspect(eval(`${line.substring(12)}`))}`, color: 'green'}); bot.tellraw('@a', {
text: `${util.inspect(eval(`${line.substring(12)}`))}`,
color: 'green',
});
return; return;
} catch (err) { } catch (err) {
bot.tellraw('@a', {text: `${util.inspect(err)}`, color: 'red'}); bot.tellraw('@a', {text: `${util.inspect(err)}`, color: 'red'});
@ -349,8 +402,37 @@ dcclient.on('ready', async () => {
return; return;
} }
if (line === '.kill') process.exit(); if (line === '.kill') process.exit();
if (line.startsWith('.')) return bot.command_handler.run('Console', '§a§lConsole§r', '*' + line.substring(1), 'c0ns0le-uuid'); if (line.startsWith('.')) {
bot.tellraw('@a', [{'text': '[', 'color': 'dark_gray'}, {'text': `${bot.username} Console`, 'color': 'gray'}, {'text': '] ', 'color': 'dark_gray'}, {'text': 'chayapak ', 'color': 'green'}, {'text': ' ', 'color': 'dark_gray'}, chatMessage.MessageBuilder.fromString('&7' + line)]); return bot.command_handler.run(
'Console',
'§a§lConsole§r',
'*' + line.substring(1),
'c0ns0le-uuid',
);
}
bot.tellraw('@a', [
{
text: '[',
color: 'dark_gray',
},
{
text: `${bot.username} Console`,
color: 'gray',
},
{
text: '] ',
color: 'dark_gray',
},
{
text: 'chayapak ',
color: 'green',
},
{
text: '\u203a ',
color: 'dark_gray',
},
chatMessage.MessageBuilder.fromString('&7' + line),
]);
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -403,11 +485,23 @@ dcclient.on('messageCreate', async (message) => {
hoverEvent: { hoverEvent: {
action: 'show_text', action: 'show_text',
value: [ value: [
{text: message.author.username, color: 'white'}, {
{text: '#', color: 'dark_gray'}, text: message.author.username,
{text: message.author.discriminator, color: 'gray'}, color: 'white',
},
{
text: '#',
color: 'dark_gray',
},
{
text: message.author.discriminator,
color: 'gray',
},
'\n', '\n',
{text: 'Click here to copy the tag to your clipboard', color: 'green'}, {
text: 'Click here to copy the tag to your clipboard',
color: 'green',
},
], ],
}, },
}, },