mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
45 minutes, worth it.
This commit is contained in:
parent
9d5bc776f4
commit
f5742da82e
9 changed files with 284 additions and 252 deletions
|
@ -6,12 +6,12 @@ function add(command, interval, bot) {
|
||||||
|
|
||||||
bot.cloops.push({id, interval, command});
|
bot.cloops.push({id, interval, command});
|
||||||
}
|
}
|
||||||
function remove(item) {
|
function remove(item, bot) {
|
||||||
clearInterval(bot.cloops[item].id);
|
clearInterval(bot.cloops[item].id);
|
||||||
|
|
||||||
bot.cloops.splice(item, 1);
|
bot.cloops.splice(item, 1);
|
||||||
}
|
}
|
||||||
function clear() {
|
function clear(bot) {
|
||||||
for (const interval of bot.cloops) clearInterval(interval.id);
|
for (const interval of bot.cloops) clearInterval(interval.id);
|
||||||
|
|
||||||
bot.cloops = [];
|
bot.cloops = [];
|
||||||
|
@ -77,10 +77,10 @@ module.exports = {
|
||||||
} else if (args[1] === 'list') {
|
} else if (args[1] === 'list') {
|
||||||
list(bot, false, null, selector);
|
list(bot, false, null, selector);
|
||||||
} else if (args[1] === 'remove') {
|
} else if (args[1] === 'remove') {
|
||||||
remove(args[2]);
|
remove(args[2], bot);
|
||||||
bot.tellraw(selector, [{text: 'Removed cloop '}, {text: args[2], color: 'aqua'}]);
|
bot.tellraw(selector, [{text: 'Removed cloop '}, {text: args[2], color: 'aqua'}]);
|
||||||
} else if (args[1] === 'removeall') {
|
} else if (args[1] === 'removeall') {
|
||||||
clear();
|
clear(bot);
|
||||||
bot.tellraw(selector, [{text: 'Removed all looped commands', color: 'white'}]);
|
bot.tellraw(selector, [{text: 'Removed all looped commands', color: 'white'}]);
|
||||||
} else {
|
} else {
|
||||||
throw new SyntaxError('Invalid argument');
|
throw new SyntaxError('Invalid argument');
|
||||||
|
|
|
@ -66,10 +66,10 @@ module.exports = {
|
||||||
'host': 'kitsune.icu',
|
'host': 'kitsune.icu',
|
||||||
'port': 25565,
|
'port': 25565,
|
||||||
},
|
},
|
||||||
{
|
// {
|
||||||
'host': '71.179.136.66',
|
// 'host': '71.179.136.66',
|
||||||
'port': 25565,
|
// 'port': 25565,
|
||||||
},
|
// },
|
||||||
// {
|
// {
|
||||||
// 'host': 'mc.chomens41793.ga',
|
// 'host': 'mc.chomens41793.ga',
|
||||||
// 'port': 25565,
|
// 'port': 25565,
|
||||||
|
|
104
plugins/chat.js
104
plugins/chat.js
|
@ -3,97 +3,7 @@
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
// const parse = require('../util/text_parser');
|
// const parse = require('../util/text_parser');
|
||||||
const {containsIllegalCharacters} = require('../util/containsIllegalCharacters');
|
const {containsIllegalCharacters} = require('../util/containsIllegalCharacters');
|
||||||
async function chatPacketListener(packet, ChatMessage, previousMessage, bot) {
|
const {chatPacketListener, parsePlayerMessages} = require('../util/chat');
|
||||||
// try catch prevents hi % exploit (it uses prismarine-chat)
|
|
||||||
// and try catch also prevents json parse error
|
|
||||||
try {
|
|
||||||
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;
|
|
||||||
|
|
||||||
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);
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function parsedChatListener(message, packet, bot) {
|
|
||||||
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);
|
|
||||||
if (raw.match(/.* .*: .*/g)) {
|
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
|
||||||
const username = raw.replace(/.*?\[.*?\] /, '').replace(/:.*/g, '').replace(/§#....../gm, '');
|
|
||||||
const message = raw.split(': ')[1];
|
|
||||||
bot.emit('message', username, message, packet.sender);
|
|
||||||
} else if (raw.match(/.* .*\u203a .*/g)) {
|
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
|
||||||
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u203a.*/g, '').replace(/§#....../gm, '').split(' ')[0];
|
|
||||||
const message = raw.split('\u203a ')[1].substring(2);
|
|
||||||
bot.emit('message', username, message, packet.sender);
|
|
||||||
} else if (raw.match(/.* .*\u00BB .*/g)) {
|
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
|
||||||
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u00BB.*/g, '').replace(/§#....../gm, '').split(' ')[0];
|
|
||||||
const message = raw.split('\u00BB ')[1].substring(2);
|
|
||||||
bot.emit('message', username, message, packet.sender);
|
|
||||||
} else if (raw.match(/<.*§r> .*/g)) {
|
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
|
||||||
|
|
||||||
const username = raw.substring(3).split('§r>')[0];
|
|
||||||
const message = raw.split('§r> ')[1];
|
|
||||||
|
|
||||||
bot.emit('message', username, message, packet.sender);
|
|
||||||
} else if (raw.match(/<.*> .*/g)) {
|
|
||||||
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
|
||||||
|
|
||||||
const username = raw.substring(3).split('>')[0];
|
|
||||||
const message = raw.split('> ')[1];
|
|
||||||
|
|
||||||
bot.emit('message', username, message, packet.sender);
|
|
||||||
} else if (raw.match(/§.*§b: §b\/.*/g)) {
|
|
||||||
const username = raw.split('§b: §b')[0];
|
|
||||||
const command = raw.split('§b: §b')[1];
|
|
||||||
|
|
||||||
bot.emit('cspy', username, command);
|
|
||||||
} else if (raw.match(/§.*§e: §e\/.*/g)) {
|
|
||||||
const username = raw.split('§e: §e')[0];
|
|
||||||
const command = raw.split('§e: §e')[1];
|
|
||||||
bot.emit('cspy', username, command);
|
|
||||||
} else if (raw.match(/§.*§b: \/.*/g)) {
|
|
||||||
const username = raw.split('§b: ')[0];
|
|
||||||
const command = raw.split('§b: ')[1];
|
|
||||||
|
|
||||||
bot.emit('cspy', username, command);
|
|
||||||
} else if (raw.match(/§.*§e: \/.*/g)) {
|
|
||||||
const username = raw.split('§e: ')[0];
|
|
||||||
const command = raw.split('§e: ')[1];
|
|
||||||
bot.emit('cspy', username, command);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function inject(bot) {
|
function inject(bot) {
|
||||||
bot.chatQueue = [];
|
bot.chatQueue = [];
|
||||||
|
@ -130,15 +40,7 @@ function inject(bot) {
|
||||||
|
|
||||||
bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, previousMessage, bot));
|
bot._client.on('chat', (packet) => chatPacketListener(packet, ChatMessage, previousMessage, bot));
|
||||||
|
|
||||||
bot.on('parsed_chat', (message, packet) => parsedChatListener(message, packet, bot));
|
bot.on('parsed_chat', (message, packet) => parsePlayerMessages(message, packet, bot));
|
||||||
}
|
}
|
||||||
|
|
||||||
function proxy(bot, client, targetClient) {
|
module.exports = {inject};
|
||||||
const ChatMessage = require('prismarine-chat')(bot.version);
|
|
||||||
|
|
||||||
targetClient.on('chat', (packet) => chatPacketListener(packet, ChatMessage, '', targetClient));
|
|
||||||
|
|
||||||
targetClient.on('parsed_chat', (message, packet) => parsedChatListener(message, packet, targetClient));
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {inject, proxy};
|
|
||||||
|
|
186
plugins/proxy.js
186
plugins/proxy.js
|
@ -3,104 +3,108 @@ const mc = require('minecraft-protocol');
|
||||||
const {loadPlugins} = require('../util/loadPlugins');
|
const {loadPlugins} = require('../util/loadPlugins');
|
||||||
|
|
||||||
function inject(bot, dcclient, config) {
|
function inject(bot, dcclient, config) {
|
||||||
config.servers.forEach((server, index) => {
|
let index;
|
||||||
if (server.host !== bot.options.host) return;
|
config.servers.forEach((server, _index) => {
|
||||||
|
if (bot.options.host !== server.host) return;
|
||||||
|
index = _index;
|
||||||
|
});
|
||||||
|
|
||||||
const {MessageBuilder} = require('prismarine-chat')(bot.version);
|
const {MessageBuilder} = require('prismarine-chat')(bot.version);
|
||||||
|
|
||||||
const version = bot.version;
|
const version = bot.version;
|
||||||
const srv = mc.createServer({
|
const srv = mc.createServer({
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
'port': 25566 + index,
|
'port': 25566 + index,
|
||||||
'keepAlive': false,
|
'keepAlive': false,
|
||||||
|
version,
|
||||||
|
});
|
||||||
|
|
||||||
|
srv.on('login', function(client) {
|
||||||
|
bot.console.info(`[Proxy] ${client.username} connected to proxy`);
|
||||||
|
let endedClient = false;
|
||||||
|
let endedTarget = false;
|
||||||
|
|
||||||
|
const targetClient = mc.createClient({
|
||||||
|
username: client.username,
|
||||||
|
host: bot.options.host,
|
||||||
version,
|
version,
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.once('end', () => srv.close());
|
targetClient.chat = function(message) {
|
||||||
|
targetClient.write('chat', {message});
|
||||||
|
};
|
||||||
|
|
||||||
srv.on('login', function(client) {
|
targetClient.on('login', (packet) => {
|
||||||
bot.console.info(`[Proxy] ${client.username} connected to proxy`);
|
targetClient.entityId = packet.entityId;
|
||||||
let endedClient = false;
|
loadPlugins(bot, null, config, null, targetClient, client, true);
|
||||||
let endedTarget = false;
|
|
||||||
|
|
||||||
const targetClient = mc.createClient({
|
|
||||||
username: client.username,
|
|
||||||
host: bot.options.host,
|
|
||||||
version,
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.chat = function(message) {
|
|
||||||
targetClient.write('chat', {message});
|
|
||||||
};
|
|
||||||
|
|
||||||
targetClient.on('login', (packet) => {
|
|
||||||
targetClient.entityId = packet.entityId;
|
|
||||||
loadPlugins(bot, null, config, null, targetClient, client, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.on('packet', (data, meta) => {
|
|
||||||
if (!endedClient &&
|
|
||||||
meta.state === mc.states.PLAY &&
|
|
||||||
client.state === mc.states.PLAY
|
|
||||||
) client.write(meta.name, data);
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.on('error', () => {});
|
|
||||||
|
|
||||||
targetClient.on('end', () => {
|
|
||||||
targetClient.end();
|
|
||||||
endedTarget = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('end', function() {
|
|
||||||
endedClient = true;
|
|
||||||
targetClient.end();
|
|
||||||
bot.console.info(`[Proxy] ${client.username} ended`);
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('error', function() {
|
|
||||||
endedClient = true;
|
|
||||||
bot.console.info(`[Proxy] ${client.username} got error`);
|
|
||||||
});
|
|
||||||
|
|
||||||
client.on('packet', (data, meta) => {
|
|
||||||
if (meta.name === 'chat' && !data.message?.startsWith('/')) {
|
|
||||||
if (data.message.startsWith('.')) {
|
|
||||||
return bot.command_handler.run(
|
|
||||||
client.username,
|
|
||||||
client.username,
|
|
||||||
'*' + data.message.substring(1),
|
|
||||||
client.uuid,
|
|
||||||
null,
|
|
||||||
'h',
|
|
||||||
'o',
|
|
||||||
client.username,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
bot.tellraw('@a', {
|
|
||||||
color: 'dark_gray',
|
|
||||||
translate: '[%s] [%s] %s \u203a %s',
|
|
||||||
with: [
|
|
||||||
{
|
|
||||||
text: 'Chat',
|
|
||||||
color: 'gray',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: 'Proxy',
|
|
||||||
color: 'gray',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: client.username,
|
|
||||||
color: 'green',
|
|
||||||
},
|
|
||||||
MessageBuilder.fromString('&7' + data.message),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
targetClient.write(meta.name, data);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
targetClient.on('packet', (data, meta) => {
|
||||||
|
if (!endedClient &&
|
||||||
|
meta.state === mc.states.PLAY &&
|
||||||
|
client.state === mc.states.PLAY
|
||||||
|
) client.write(meta.name, data);
|
||||||
|
});
|
||||||
|
|
||||||
|
targetClient.on('error', () => {});
|
||||||
|
|
||||||
|
targetClient.on('end', () => {
|
||||||
|
targetClient.end();
|
||||||
|
endedTarget = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('end', function() {
|
||||||
|
endedClient = true;
|
||||||
|
targetClient.end();
|
||||||
|
bot.console.info(`[Proxy] ${client.username} ended`);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('error', function() {
|
||||||
|
endedClient = true;
|
||||||
|
bot.console.info(`[Proxy] ${client.username} got error`);
|
||||||
|
});
|
||||||
|
|
||||||
|
client.on('packet', (data, meta) => {
|
||||||
|
if (meta.name === 'chat' && !data.message?.startsWith('/')) {
|
||||||
|
if (data.message.startsWith('.')) {
|
||||||
|
return bot.command_handler.run(
|
||||||
|
client.username,
|
||||||
|
client.username,
|
||||||
|
'*' + data.message.substring(1),
|
||||||
|
client.uuid,
|
||||||
|
null,
|
||||||
|
'h',
|
||||||
|
'o',
|
||||||
|
client.username,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
bot.tellraw('@a', {
|
||||||
|
color: 'dark_gray',
|
||||||
|
translate: '[%s] [%s] %s \u203a %s',
|
||||||
|
with: [
|
||||||
|
{
|
||||||
|
text: 'Chat',
|
||||||
|
color: 'gray',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: 'Proxy',
|
||||||
|
color: 'gray',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: client.username,
|
||||||
|
color: 'green',
|
||||||
|
},
|
||||||
|
MessageBuilder.fromString('&7' + data.message),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
targetClient.write(meta.name, data);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
bot.once('end', () => {
|
||||||
|
srv.close();
|
||||||
|
srv.removeAllListeners();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
15
plugins/proxy/chat.js
Normal file
15
plugins/proxy/chat.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/* eslint-disable require-jsdoc */
|
||||||
|
const {chatPacketListener, parsePlayerMessages} = require('../../util/chat');
|
||||||
|
function inject(bot, client, targetClient) {
|
||||||
|
const ChatMessage = require('prismarine-chat')(bot.version);
|
||||||
|
|
||||||
|
targetClient.on('chat', (packet) => {
|
||||||
|
chatPacketListener(packet, ChatMessage, '', targetClient);
|
||||||
|
});
|
||||||
|
|
||||||
|
targetClient.on('parsed_chat', (message, packet) => {
|
||||||
|
parsePlayerMessages(message, packet, targetClient);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {inject};
|
49
plugins/proxy/self_care.js
Normal file
49
plugins/proxy/self_care.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/* eslint-disable max-len */
|
||||||
|
/* eslint-disable require-jsdoc */
|
||||||
|
function inject(bot, client, targetClient, config) {
|
||||||
|
let cspy = false;
|
||||||
|
let op = true;
|
||||||
|
let gameMode = 1;
|
||||||
|
|
||||||
|
targetClient.on('parsed_chat', (data) => {
|
||||||
|
if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true;
|
||||||
|
if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
targetClient.on('entity_status', (data) => {
|
||||||
|
if (data.entityId !== targetClient.entityId) return;
|
||||||
|
|
||||||
|
switch (data.entityStatus) {
|
||||||
|
case 24:
|
||||||
|
op = false;
|
||||||
|
break;
|
||||||
|
case 28:
|
||||||
|
op = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
targetClient.on('game_state_change', (data) => {
|
||||||
|
if (data.reason !== 3) return;
|
||||||
|
|
||||||
|
gameMode = data.gameMode;
|
||||||
|
});
|
||||||
|
|
||||||
|
targetClient.once('login', (data) => {
|
||||||
|
gameMode = data.gameMode;
|
||||||
|
});
|
||||||
|
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
if (bot.options.host !== '0.tcp.ap.ngrok.io') {
|
||||||
|
if (!op && config.self_care.op) targetClient.chat('/minecraft:op @s[type=player]');
|
||||||
|
if (!cspy && config.self_care.cspy) targetClient.chat('/commandspy:commandspy on');
|
||||||
|
}
|
||||||
|
if (gameMode !== 1 && config.self_care.gamemode) targetClient.chat('/minecraft:gamemode creative @s[type=player]');
|
||||||
|
}, config.self_care_check_interval);
|
||||||
|
|
||||||
|
bot.once('end', () => {
|
||||||
|
clearInterval(interval);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {inject};
|
|
@ -65,55 +65,9 @@ function inject(bot, dcclient, config) {
|
||||||
if (muted && config.self_care.mute) bot.chat('/essentials:mute ' + bot.uuid);
|
if (muted && config.self_care.mute) bot.chat('/essentials:mute ' + bot.uuid);
|
||||||
}, config.self_care_check_interval);
|
}, config.self_care_check_interval);
|
||||||
|
|
||||||
bot.once('end', () => {
|
|
||||||
clearInterval(interval);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function proxy(bot, client, targetClient, config) {
|
|
||||||
let cspy = false;
|
|
||||||
let op = true;
|
|
||||||
let gameMode = 1;
|
|
||||||
|
|
||||||
targetClient.on('parsed_chat', (data) => {
|
|
||||||
if (data.toString() === 'Successfully enabled CommandSpy' || data.toString() === ' Enabled your command spy.' || data.toString() === ' Your command spy is already enabled.') cspy = true;
|
|
||||||
if (data.toString() === 'Successfully disabled CommandSpy' || data.toString() === ' Disabled your command spy.') cspy = false;
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.on('entity_status', (data) => {
|
|
||||||
if (data.entityId !== targetClient.entityId) return;
|
|
||||||
|
|
||||||
switch (data.entityStatus) {
|
|
||||||
case 24:
|
|
||||||
op = false;
|
|
||||||
break;
|
|
||||||
case 28:
|
|
||||||
op = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.on('game_state_change', (data) => {
|
|
||||||
if (data.reason !== 3) return;
|
|
||||||
|
|
||||||
gameMode = data.gameMode;
|
|
||||||
});
|
|
||||||
|
|
||||||
targetClient.once('login', (data) => {
|
|
||||||
gameMode = data.gameMode;
|
|
||||||
});
|
|
||||||
|
|
||||||
const interval = setInterval(() => {
|
|
||||||
if (bot.options.host !== '0.tcp.ap.ngrok.io') {
|
|
||||||
if (!op && config.self_care.op) targetClient.chat('/minecraft:op @s[type=player]');
|
|
||||||
if (!cspy && config.self_care.cspy) targetClient.chat('/commandspy:commandspy on');
|
|
||||||
}
|
|
||||||
if (gameMode !== 1 && config.self_care.gamemode) targetClient.chat('/minecraft:gamemode creative @s[type=player]');
|
|
||||||
}, config.self_care_check_interval);
|
|
||||||
|
|
||||||
bot.once('end', () => {
|
bot.once('end', () => {
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {inject, proxy};
|
module.exports = {inject};
|
||||||
|
|
107
util/chat.js
Normal file
107
util/chat.js
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
/* eslint-disable max-len */
|
||||||
|
/**
|
||||||
|
* for the chat packet listener (in util cuz proxy + bot)
|
||||||
|
* @param {object} packet chat packet
|
||||||
|
* @param {object} ChatMessage basically just require prismarine-chat
|
||||||
|
* @param {string} previousMessage previous message.
|
||||||
|
* @param {object} bot bot
|
||||||
|
*/
|
||||||
|
function chatPacketListener(packet, ChatMessage, previousMessage, bot) {
|
||||||
|
// try catch prevents hi % exploit (it uses prismarine-chat)
|
||||||
|
// and try catch also prevents json parse error
|
||||||
|
try {
|
||||||
|
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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* parse player messages (for prismarine-chat)
|
||||||
|
* @param {object} message prismarine-chat ChatMessage
|
||||||
|
* @param {object} packet chat packet
|
||||||
|
* @param {object} bot bot
|
||||||
|
*/
|
||||||
|
function parsePlayerMessages(message, packet, bot) {
|
||||||
|
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);
|
||||||
|
if (raw.match(/.* .*: .*/g)) {
|
||||||
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
const username = raw.replace(/.*?\[.*?\] /, '').replace(/:.*/g, '').replace(/§#....../gm, '');
|
||||||
|
const message = raw.split(': ')[1];
|
||||||
|
bot.emit('message', username, message, packet.sender);
|
||||||
|
} else if (raw.match(/.* .*\u203a .*/g)) {
|
||||||
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u203a.*/g, '').replace(/§#....../gm, '').split(' ')[0];
|
||||||
|
const message = raw.split('\u203a ')[1].substring(2);
|
||||||
|
bot.emit('message', username, message, packet.sender);
|
||||||
|
} else if (raw.match(/.* .*\u00BB .*/g)) {
|
||||||
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
const username = raw.replace(/.*?\[.*?\] /g, '').replace(/\u00BB.*/g, '').replace(/§#....../gm, '').split(' ')[0];
|
||||||
|
const message = raw.split('\u00BB ')[1].substring(2);
|
||||||
|
bot.emit('message', username, message, packet.sender);
|
||||||
|
} else if (raw.match(/<.*§r> .*/g)) {
|
||||||
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
|
||||||
|
const username = raw.substring(3).split('§r>')[0];
|
||||||
|
const message = raw.split('§r> ')[1];
|
||||||
|
|
||||||
|
bot.emit('message', username, message, packet.sender);
|
||||||
|
} else if (raw.match(/<.*> .*/g)) {
|
||||||
|
// if (packet.sender === '00000000-0000-0000-0000-000000000000') return;
|
||||||
|
|
||||||
|
const username = raw.substring(3).split('>')[0];
|
||||||
|
const message = raw.split('> ')[1];
|
||||||
|
|
||||||
|
bot.emit('message', username, message, packet.sender);
|
||||||
|
} else if (raw.match(/§.*§b: §b\/.*/g)) {
|
||||||
|
const username = raw.split('§b: §b')[0];
|
||||||
|
const command = raw.split('§b: §b')[1];
|
||||||
|
|
||||||
|
bot.emit('cspy', username, command);
|
||||||
|
} else if (raw.match(/§.*§e: §e\/.*/g)) {
|
||||||
|
const username = raw.split('§e: §e')[0];
|
||||||
|
const command = raw.split('§e: §e')[1];
|
||||||
|
bot.emit('cspy', username, command);
|
||||||
|
} else if (raw.match(/§.*§b: \/.*/g)) {
|
||||||
|
const username = raw.split('§b: ')[0];
|
||||||
|
const command = raw.split('§b: ')[1];
|
||||||
|
|
||||||
|
bot.emit('cspy', username, command);
|
||||||
|
} else if (raw.match(/§.*§e: \/.*/g)) {
|
||||||
|
const username = raw.split('§e: ')[0];
|
||||||
|
const command = raw.split('§e: ')[1];
|
||||||
|
bot.emit('cspy', username, command);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {chatPacketListener, parsePlayerMessages};
|
|
@ -14,10 +14,10 @@ const path = require('path');
|
||||||
* @param {boolean} proxy is proxy
|
* @param {boolean} proxy is proxy
|
||||||
*/
|
*/
|
||||||
async function loadPlugins(bot, dcclient, config, rl, targetClient, client, proxy) {
|
async function loadPlugins(bot, dcclient, config, rl, targetClient, client, proxy) {
|
||||||
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
|
|
||||||
|
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
|
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins'));
|
||||||
plugins.forEach((plugin) => {
|
plugins.forEach((plugin) => {
|
||||||
|
if (!plugin.endsWith('.js')) return;
|
||||||
try {
|
try {
|
||||||
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
||||||
plug.inject(bot, dcclient, config, rl);
|
plug.inject(bot, dcclient, config, rl);
|
||||||
|
@ -27,11 +27,12 @@ async function loadPlugins(bot, dcclient, config, rl, targetClient, client, prox
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
const plugins = await fs.readdir(path.join(__dirname, '..', 'plugins', 'proxy'));
|
||||||
plugins.forEach((plugin) => {
|
plugins.forEach((plugin) => {
|
||||||
|
if (!plugin.endsWith('.js')) return;
|
||||||
try {
|
try {
|
||||||
const plug = require(path.join(__dirname, '..', 'plugins', plugin));
|
const plug = require(path.join(__dirname, '..', 'plugins', 'proxy', plugin));
|
||||||
if (!plug.proxy) return;
|
plug.inject(bot, client, targetClient, config);
|
||||||
plug.proxy(bot, client, targetClient, config);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`Proxy Plugin ${plugin} is having exception loading the plugin:`);
|
console.log(`Proxy Plugin ${plugin} is having exception loading the plugin:`);
|
||||||
console.log(util.inspect(e));
|
console.log(util.inspect(e));
|
||||||
|
|
Loading…
Reference in a new issue