mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
ees
This commit is contained in:
parent
c972240c28
commit
a507fe019e
1 changed files with 117 additions and 23 deletions
140
index.js
140
index.js
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable max-len */
|
||||
/* eslint-disable no-var */
|
||||
/* eslint-disable prefer-rest-params */
|
||||
/* eslint-disable no-tabs */
|
||||
/* eslint-disable max-len */
|
||||
/* eslint-disable no-undef */
|
||||
const mc = require('minecraft-protocol');
|
||||
const config = require('./config');
|
||||
|
@ -65,7 +65,9 @@ function dcmsg() {
|
|||
function botThings() {
|
||||
bot = new EventEmitter();
|
||||
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],
|
||||
port: process.argv[3] ? Number(process.argv[3]) : 25565,
|
||||
version: config.version,
|
||||
|
@ -133,7 +135,12 @@ function main() {
|
|||
|
||||
discordQueue = setInterval(function() {
|
||||
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 = '';
|
||||
}
|
||||
}, 1000);
|
||||
|
@ -142,21 +149,32 @@ function main() {
|
|||
if (!messageloggingEnabled) return;
|
||||
if (consoleQueue.length > 50) consoleQueue = [];
|
||||
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();
|
||||
}
|
||||
}, 100);
|
||||
|
||||
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)}\``);
|
||||
|
||||
let timeout = config.reconnectTimeout;
|
||||
|
||||
try {
|
||||
if (reason.text) {
|
||||
if (reason.text === 'Wait 5 seconds before connecting, thanks! :)') timeout = 1000 * 6;
|
||||
if (reason.text === 'You are logging in too fast, try again later.') timeout = 1000 * 6;
|
||||
if (reason.text ===
|
||||
'Wait 5 seconds before connecting, thanks! :)' ||
|
||||
reason.text ===
|
||||
'You are logging in too fast, try again later.'
|
||||
) timeout = 1000 * 7;
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
@ -184,8 +202,12 @@ function main() {
|
|||
bot.username = bot._client.username;
|
||||
chatMessage = require('prismarine-chat')(bot.version);
|
||||
const mcData = require('minecraft-data')(bot.version);
|
||||
console.log(`Successfully logged in to: ${bot.options.host}:${bot.options.port}`);
|
||||
channel.send(`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``);
|
||||
console.log(
|
||||
`Successfully logged in to: ${bot.options.host}:${bot.options.port}`,
|
||||
);
|
||||
channel.send(
|
||||
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``,
|
||||
);
|
||||
previusMessage = undefined;
|
||||
loginfinish = false;
|
||||
started = false;
|
||||
|
@ -209,7 +231,9 @@ function main() {
|
|||
crypto,
|
||||
colorConvert,
|
||||
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);
|
||||
},
|
||||
generateEaglerUsername,
|
||||
|
@ -222,11 +246,29 @@ function main() {
|
|||
|
||||
loginfinish = true;
|
||||
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) {
|
||||
// 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 {
|
||||
if (previusMessage === message.toString()) return;
|
||||
previusMessage = message.toString();
|
||||
|
@ -242,7 +284,10 @@ function main() {
|
|||
if (message.toString().includes('⣿')) return;
|
||||
|
||||
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());
|
||||
|
||||
|
@ -262,8 +307,12 @@ function main() {
|
|||
bot.emit('end', reason, 'end');
|
||||
});
|
||||
|
||||
bot._client.on('keep_alive', (packet) => bot.write('keep_alive', {keepAliveId: packet.keepAliveId}));
|
||||
bot._client.on('game_state_change', () => bot.write('client_command', {payload: 0}));
|
||||
bot._client.on('keep_alive', (packet) => {
|
||||
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) {
|
||||
const parsed = JSON.parse(data.reason);
|
||||
|
@ -322,14 +371,18 @@ dcclient.on('ready', async () => {
|
|||
// Console COMMANDS
|
||||
rl.on('line', function(line) {
|
||||
try {
|
||||
if (line.toLowerCase() === '' || line.toLowerCase().startsWith(' ')) return;
|
||||
if (line.toLowerCase() === '' ||
|
||||
line.toLowerCase().startsWith(' ')) return;
|
||||
if (line.toLowerCase() === '.exit' || line.toLowerCase() === '.end') {
|
||||
bot.emit('end', 'end command');
|
||||
return;
|
||||
}
|
||||
if (line.toLowerCase().startsWith('.servereval ')) {
|
||||
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;
|
||||
} catch (err) {
|
||||
bot.tellraw('@a', {text: `${util.inspect(err)}`, color: 'red'});
|
||||
|
@ -349,8 +402,37 @@ dcclient.on('ready', async () => {
|
|||
return;
|
||||
}
|
||||
if (line === '.kill') process.exit();
|
||||
if (line.startsWith('.')) 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': '› ', 'color': 'dark_gray'}, chatMessage.MessageBuilder.fromString('&7' + line)]);
|
||||
if (line.startsWith('.')) {
|
||||
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) {
|
||||
console.log(e);
|
||||
}
|
||||
|
@ -403,11 +485,23 @@ dcclient.on('messageCreate', async (message) => {
|
|||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
value: [
|
||||
{text: message.author.username, color: 'white'},
|
||||
{text: '#', color: 'dark_gray'},
|
||||
{text: message.author.discriminator, color: 'gray'},
|
||||
{
|
||||
text: message.author.username,
|
||||
color: 'white',
|
||||
},
|
||||
{
|
||||
text: '#',
|
||||
color: 'dark_gray',
|
||||
},
|
||||
{
|
||||
text: message.author.discriminator,
|
||||
color: 'gray',
|
||||
},
|
||||
'\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',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue