mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-27 09:35:35 -05:00
chat, discord to plugin + hash improve!1!!
This commit is contained in:
parent
50dd35c3a8
commit
9d2664a3a4
5 changed files with 85 additions and 80 deletions
81
index.js
81
index.js
|
@ -54,14 +54,6 @@ let chomenschannel = '969773424387981356';
|
||||||
const hashchannel = '980438368422871151';
|
const hashchannel = '980438368422871151';
|
||||||
const ownerhashchannel = '980786390247833620';
|
const ownerhashchannel = '980786390247833620';
|
||||||
|
|
||||||
/**
|
|
||||||
* empty function for discord message
|
|
||||||
* @return {String}
|
|
||||||
*/
|
|
||||||
function dcmsg() {
|
|
||||||
return 'this does nothing...';
|
|
||||||
}
|
|
||||||
|
|
||||||
function botThings() {
|
function botThings() {
|
||||||
bot = new EventEmitter();
|
bot = new EventEmitter();
|
||||||
bot.options = {
|
bot.options = {
|
||||||
|
@ -87,7 +79,7 @@ function botThings() {
|
||||||
};
|
};
|
||||||
bot.visibility = false;
|
bot.visibility = false;
|
||||||
bot.getplayerusername = {};
|
bot.getplayerusername = {};
|
||||||
if (!bot.messageLogging) bot.messageLogging = true;
|
if (typeof bot.messageLogging === 'undefined') bot.messageLogging = true;
|
||||||
|
|
||||||
loadPlugins(bot, dcclient, config, rl);
|
loadPlugins(bot, dcclient, config, rl);
|
||||||
}
|
}
|
||||||
|
@ -116,49 +108,15 @@ function main() {
|
||||||
}
|
}
|
||||||
}, 450);
|
}, 450);
|
||||||
|
|
||||||
module.exports = function() {
|
module.exports = bot;
|
||||||
return bot;
|
|
||||||
};
|
|
||||||
|
|
||||||
dcmsg.queue = '';
|
|
||||||
bot.consoleQueue = [];
|
|
||||||
|
|
||||||
bot.playersAddedPlayers = {};
|
bot.playersAddedPlayers = {};
|
||||||
bot.getplayerusername = {};
|
bot.getplayerusername = {};
|
||||||
|
|
||||||
bot.hash = '';
|
|
||||||
|
|
||||||
bot.chat = (message) => {
|
bot.chat = (message) => {
|
||||||
bot.queue.push(String(message));
|
bot.queue.push(String(message));
|
||||||
};
|
};
|
||||||
|
|
||||||
discordQueue = setInterval(function() {
|
|
||||||
if (dcmsg.queue!='') {
|
|
||||||
channel.send({
|
|
||||||
content: '```ansi\n' + dcmsg.queue.substring(0, 1986) + '\n```',
|
|
||||||
allowedMentions: {
|
|
||||||
parse: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
dcmsg.queue = '';
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
consoleQueueInterval = setInterval(function() {
|
|
||||||
if (!bot.messageLogging) return;
|
|
||||||
if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
|
|
||||||
if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
|
|
||||||
console.log(
|
|
||||||
'\u001b[48:5:208m' +
|
|
||||||
bot.options.host +
|
|
||||||
'\u001b[0m' +
|
|
||||||
': ' +
|
|
||||||
bot.consoleQueue[0].substring(0, 10000),
|
|
||||||
);
|
|
||||||
bot.consoleQueue.shift();
|
|
||||||
}
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
bot.once('end', (reason, event) => {
|
bot.once('end', (reason, event) => {
|
||||||
console.log(
|
console.log(
|
||||||
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
|
`Disconnected from ${bot.options.host} (${event} event): ${util.inspect(reason)}`,
|
||||||
|
@ -181,9 +139,7 @@ function main() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
clearInterval(notonline);
|
clearInterval(notonline);
|
||||||
clearInterval(discordQueue);
|
|
||||||
clearInterval(chatQueue);
|
clearInterval(chatQueue);
|
||||||
clearInterval(consoleQueueInterval);
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -207,7 +163,6 @@ function main() {
|
||||||
channel.send(
|
channel.send(
|
||||||
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``,
|
`Successfully logged in to: \`${bot.options.host}:${bot.options.port}\``,
|
||||||
);
|
);
|
||||||
previusMessage = undefined;
|
|
||||||
loginfinish = false;
|
loginfinish = false;
|
||||||
started = false;
|
started = false;
|
||||||
bot.eaglercrashstarted = false;
|
bot.eaglercrashstarted = false;
|
||||||
|
@ -265,38 +220,6 @@ function main() {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on('parsed_chat', async function(message, data) {
|
|
||||||
// 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();
|
|
||||||
|
|
||||||
const parsedMessage = JSON.parse(data.message);
|
|
||||||
if (parsedMessage.translate === 'translation.test.invalid') return;
|
|
||||||
// down here it prevents command set message
|
|
||||||
if (parsedMessage.translate === 'advMode.setCommand.success') return;
|
|
||||||
if (parsedMessage.extra !== undefined) {
|
|
||||||
if (parsedMessage.extra[0].text === 'Command set: ') return;
|
|
||||||
}
|
|
||||||
// prevent braille cuz it CRASHES THE ENTIRE LAPTOP
|
|
||||||
if (message.toString().includes('⣿')) return;
|
|
||||||
|
|
||||||
const cleanMessage = escapeMarkdown(message.toAnsi(), true);
|
|
||||||
discordMsg = cleanMessage
|
|
||||||
.replaceAll('@', '@\u200b')
|
|
||||||
.replaceAll('http', 'http\u200b')
|
|
||||||
.replaceAll('\u001b[9', '\u001b[3');
|
|
||||||
|
|
||||||
bot.consoleQueue.push(message.toAnsi());
|
|
||||||
|
|
||||||
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
|
|
||||||
dcmsg.queue += '\n' + discordMsg;
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bot.on('player_added', (player) => {
|
bot.on('player_added', (player) => {
|
||||||
bot.playersAddedPlayers[player.name] = player.UUID;
|
bot.playersAddedPlayers[player.name] = player.UUID;
|
||||||
bot.getplayerusername[player.UUID] = player.name;
|
bot.getplayerusername[player.UUID] = player.name;
|
||||||
|
|
|
@ -3,14 +3,34 @@
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
// const parse = require('../util/text_parser');
|
// const parse = require('../util/text_parser');
|
||||||
function inject(bot) {
|
function inject(bot) {
|
||||||
|
let previousMessage;
|
||||||
const ChatMessage = require('prismarine-chat')(bot.version);
|
const ChatMessage = require('prismarine-chat')(bot.version);
|
||||||
|
|
||||||
bot._client.on('chat', async (packet) => {
|
bot._client.on('chat', async (packet) => {
|
||||||
|
// try catch prevents hi % exploit (it uses prismarine-chat)
|
||||||
|
// and try catch also prevents json parse error
|
||||||
try {
|
try {
|
||||||
// const message = parse(packet.message);
|
|
||||||
const parsedMessage = JSON.parse(packet.message);
|
const parsedMessage = JSON.parse(packet.message);
|
||||||
|
if (parsedMessage.translate === 'translation.test.invalid' ||
|
||||||
|
parsedMessage.translate === 'translation.test.invalid2') return;
|
||||||
|
|
||||||
|
// down here it prevents command set message
|
||||||
|
|
||||||
|
// for ayunboom cuz its 1.17.1
|
||||||
|
// VVVVVVVVVVVVVVVVVVVVVVVVVVVV
|
||||||
|
if (parsedMessage.extra) {
|
||||||
|
if (parsedMessage.extra[0].text === 'Command set: ') return;
|
||||||
|
}
|
||||||
|
// for 1.18 or newer(?)
|
||||||
|
// VVVVVVVVVVVVVVVVVVVVV
|
||||||
if (parsedMessage.translate === 'advMode.setCommand.success') return;
|
if (parsedMessage.translate === 'advMode.setCommand.success') return;
|
||||||
|
|
||||||
const message = ChatMessage.fromNotch(packet.message);
|
const message = ChatMessage.fromNotch(packet.message);
|
||||||
|
|
||||||
|
// before emitting, prevent spam first!!!
|
||||||
|
if (previousMessage === message.toString()) return;
|
||||||
|
previousMessage = message.toString();
|
||||||
|
|
||||||
bot.emit('parsed_chat', message, packet);
|
bot.emit('parsed_chat', message, packet);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
|
@ -19,6 +39,11 @@ function inject(bot) {
|
||||||
|
|
||||||
bot.on('parsed_chat', (message, packet) => {
|
bot.on('parsed_chat', (message, packet) => {
|
||||||
try {
|
try {
|
||||||
|
// prevent braille cuz it CRASHES THE ENTIRE LAPTOP
|
||||||
|
// but sometimes this may not work
|
||||||
|
if (message.toString().includes('⣿')) return;
|
||||||
|
|
||||||
|
// then here is all the player message parsing thing
|
||||||
const raw = message.toMotd().substring(0, 32767);
|
const raw = message.toMotd().substring(0, 32767);
|
||||||
if (raw.match(/.* .*: .*/g)) {
|
if (raw.match(/.* .*: .*/g)) {
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
|
|
@ -3,6 +3,30 @@
|
||||||
function inject(bot, dcclient, config, rl) {
|
function inject(bot, dcclient, config, rl) {
|
||||||
if (!config.console) return;
|
if (!config.console) return;
|
||||||
|
|
||||||
|
bot.consoleQueue = [];
|
||||||
|
const consoleQueueInterval = setInterval(function() {
|
||||||
|
if (!bot.messageLogging) return;
|
||||||
|
if (bot.consoleQueue.length > 50) bot.consoleQueue = [];
|
||||||
|
if (bot.consoleQueue[0] || bot.consoleQueue[0] === '') {
|
||||||
|
console.log(
|
||||||
|
'\u001b[48:5:208m' +
|
||||||
|
bot.options.host +
|
||||||
|
'\u001b[0m' +
|
||||||
|
': ' +
|
||||||
|
bot.consoleQueue[0].substring(0, 10000),
|
||||||
|
);
|
||||||
|
bot.consoleQueue.shift();
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
|
||||||
|
bot.on('parsed_chat', (message) => {
|
||||||
|
bot.consoleQueue.push(message.toAnsi());
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.once('end', () => {
|
||||||
|
clearInterval(consoleQueueInterval);
|
||||||
|
});
|
||||||
|
|
||||||
// readline > fix on console.log
|
// readline > fix on console.log
|
||||||
const log = console.log;
|
const log = console.log;
|
||||||
console.log = function() {
|
console.log = function() {
|
||||||
|
|
31
plugins/discord.js
Normal file
31
plugins/discord.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
const {escapeMarkdown} = require('../util/escapeMarkdown');
|
||||||
|
function inject(bot, dcclient, config) {
|
||||||
|
let queue = '';
|
||||||
|
const queueInterval = setInterval(() => {
|
||||||
|
if (queue === '') return;
|
||||||
|
|
||||||
|
bot.channel.send({
|
||||||
|
content: '```ansi\n' + queue.substring(0, 1986) + '\n```',
|
||||||
|
allowedMentions: {
|
||||||
|
parse: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
queue = '';
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
bot.on('parsed_chat', (message) => {
|
||||||
|
const cleanMessage = escapeMarkdown(message.toAnsi(), true);
|
||||||
|
const discordMsg = cleanMessage
|
||||||
|
.replaceAll('@', '@\u200b')
|
||||||
|
.replaceAll('http', 'http\u200b')
|
||||||
|
.replaceAll('\u001b[9', '\u001b[3');
|
||||||
|
if (message.toMotd().startsWith('§8[§eChomeNS §9Discord§8] §c')) return;
|
||||||
|
queue += '\n' + discordMsg;
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.once('end', () => {
|
||||||
|
clearInterval(queueInterval);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {inject};
|
|
@ -2,6 +2,8 @@
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
module.exports = {
|
module.exports = {
|
||||||
inject: function(bot, dcclient, config) {
|
inject: function(bot, dcclient, config) {
|
||||||
|
bot.hash = '';
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
const interval = setInterval(() => {
|
||||||
bot.hash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.normalKey).digest('hex').substring(0, 16);
|
bot.hash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.normalKey).digest('hex').substring(0, 16);
|
||||||
bot.ownerHash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.ownerHashKey).digest('hex').substring(0, 16);
|
bot.ownerHash = crypto.createHash('sha256').update(Math.floor(Date.now() / 10000) + config.keys.ownerHashKey).digest('hex').substring(0, 16);
|
||||||
|
|
Loading…
Reference in a new issue