/* eslint-disable max-len */ /* eslint-disable require-jsdoc */ // eslint-disable-next-line no-undef // const parse = require('../util/text_parser'); function inject(bot) { const ChatMessage = require('prismarine-chat')(bot.version); bot._client.on('chat', async (packet) => { try { // const message = parse(packet.message); const message = ChatMessage.fromNotch(packet.message); bot.emit('parsed_chat', message, packet); } catch (e) { return; } }); bot.on('parsed_chat', (message, packet) => { try { const raw = message.toMotd().substring(0, 32767); if (raw.match(/.* .*:§r .*/g)) { // if (packet.sender === '00000000-0000-0000-0000-000000000000') return; const username = raw.replace(/.*?\[.*?\] /, '').replace(/:.*/g, '').replace(/§#....../gm, ''); 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.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: \/.*/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 = {inject};