From 716257c45f8eeffbeb04528949f508181c4ea932 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Mon, 12 Feb 2024 21:54:29 -0500 Subject: [PATCH] hacky porting --- commands/destroy.js | 6 ++-- commands/dragonfard.js | 17 ---------- commands/fard2.js | 22 ------------- commands/fard4.js | 14 --------- commands/music.js | 5 +-- commands/net.js | 18 ----------- commands/play.js | 13 -------- commands/scare.js | 13 -------- commands/translate.js | 19 ------------ index.js | 23 +++++++------- index_sus.js | 6 ---- persistent/seen.json | 70 +++++++++++++++++++++++++++++++++++++++++- plugins/anti_stuff.js | 2 +- plugins/chat.js | 58 +++++++++++++++++++++++++++++----- plugins/video.js | 8 ++--- util/text_parser.js | 6 ++-- 16 files changed, 145 insertions(+), 155 deletions(-) delete mode 100644 commands/dragonfard.js delete mode 100644 commands/fard2.js delete mode 100644 commands/fard4.js delete mode 100644 commands/net.js delete mode 100644 commands/play.js delete mode 100644 commands/scare.js delete mode 100644 commands/translate.js delete mode 100644 index_sus.js diff --git a/commands/destroy.js b/commands/destroy.js index 464d393..8a00ac6 100644 --- a/commands/destroy.js +++ b/commands/destroy.js @@ -1,10 +1,10 @@ const name = 'destroy' const description = 'destroy' -const usage = '{prefix}destroy' +const usages = ['destroy'] const aliases = ['destroy'] const enabled = true -const permLevel = 1 +const permLevel = 0 function execute (bot, cmd, entity, args, handler) { let i = 0 @@ -14,4 +14,4 @@ function execute (bot, cmd, entity, args, handler) { }, 1) } -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } +module.exports = { name, description, usages, aliases, enabled, execute, permLevel } diff --git a/commands/dragonfard.js b/commands/dragonfard.js deleted file mode 100644 index 17d659d..0000000 --- a/commands/dragonfard.js +++ /dev/null @@ -1,17 +0,0 @@ -const name = 'dragonfard' -const description = 'slash summon ender dragon' -const usage = '{prefix}dragonfard' -const aliases = ['dragonfard'] -const enabled = true - -const permLevel = 1 - -function execute (bot, cmd, entity, args, handler) { - let i = 0 - setInterval(() => { - bot.core.run(`/execute at @e run setblock ~ 1 ~${i++} command_block{Command:'summon ender_dragon ~ ~ ~ {Health:0}',auto:1} destroy`) - if (i > 50) { i = 0 } - }, 1) -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/fard2.js b/commands/fard2.js deleted file mode 100644 index a4484ce..0000000 --- a/commands/fard2.js +++ /dev/null @@ -1,22 +0,0 @@ -const name = 'fard2' -const description = 'CustomName' -const usage = '{prefix}fard2' -const aliases = ['fard2'] -const enabled = true - -const permLevel = 0 - -function execute (bot, cmd, entity, args, handler) { - let cmd1 = 'title @a title "' - let prevCmd1 = '' - - while ((cmd1.length + 1) < 32767) { - prevCmd1 = cmd1 - cmd1 += 'e' - } - prevCmd1 += '"' - - bot.core.run(prevCmd1) -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/fard4.js b/commands/fard4.js deleted file mode 100644 index 238ab17..0000000 --- a/commands/fard4.js +++ /dev/null @@ -1,14 +0,0 @@ -const name = 'fard4' -const description = 'data modify storage' -const usage = '{prefix}fard4' -const aliases = ['fard4'] -const enabled = true - -const permLevel = 1 - -function execute (bot, cmd, entity, args, handler) { - bot.core.run('/data modify storage e e set value [e,e,e,e,e]') - setTimeout(() => bot.cloops.push({ command: '/data modify storage e e append from storage e e[]', interval: 1 }), 69) -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/music.js b/commands/music.js index 5ae205a..dfa3860 100644 --- a/commands/music.js +++ b/commands/music.js @@ -14,15 +14,15 @@ const permLevel = 0 const fs = require('fs') const path = require('path') const https = require('https') -const tmp = require('tmp') function execute (bot, cmd, player, args, handler) { const subCmd = args.shift() - let filepath, tmpobj, file, files, primary, msg, split + let filepath, file, files, primary, msg, split switch (subCmd) { case 'play': filepath = args.join(' ').replace(/\xa7.?/g, '') + /* if (/https?:\/\//.test(filepath)) { https.get(filepath, (res) => { // Open file in local filesystem @@ -42,6 +42,7 @@ function execute (bot, cmd, player, args, handler) { // }); return } + */ filepath = path.join('music', filepath) // if (!filepath.endsWith('.mid')) { filepath += '.mid' } diff --git a/commands/net.js b/commands/net.js deleted file mode 100644 index 1d1ed90..0000000 --- a/commands/net.js +++ /dev/null @@ -1,18 +0,0 @@ -const name = 'net' -const description = 'Runs a command as each bot.' -const usage = '{prefix}netcb ' -const aliases = ['net'] -const enabled = true - -const permLevel = 0 - -function execute (bot, cmd, player, args, handler) { - const command = args.shift() - if (handler.info(command).name === name) { return bot.core.run(`/tellraw @a ${JSON.stringify({ text: 'You may not run net using net.', color: bot.colors.error })}`) } - - bot.getBots().forEach((bot) => { - handler.execute(bot, command, player, args.slice(0)) - }) -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/play.js b/commands/play.js deleted file mode 100644 index 8e73589..0000000 --- a/commands/play.js +++ /dev/null @@ -1,13 +0,0 @@ -const name = 'play' -const description = 'Runs a command in the command core' -const usage = '{prefix}cb ' -const aliases = ['cb'] -const enabled = true - -const permLevel = 0 - -function execute (bot, cmd, entity, args, handler) { - -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/scare.js b/commands/scare.js deleted file mode 100644 index 85da2b2..0000000 --- a/commands/scare.js +++ /dev/null @@ -1,13 +0,0 @@ -const name = 'scare' -const description = 'i am have clien lag help me pls' -const usage = '{prefix}scare' -const aliases = ['scare'] -const enabled = true - -const permLevel = 1 - -function execute (bot, cmd, entity, args, handler) { - bot.cloops.push({ command: `scare ${args.join(' ')}`, interval: 1 }) -} - -module.exports = { name, description, usage, aliases, enabled, execute, permLevel } diff --git a/commands/translate.js b/commands/translate.js deleted file mode 100644 index e985997..0000000 --- a/commands/translate.js +++ /dev/null @@ -1,19 +0,0 @@ -const name = 'translate' -const description = 'Translates text.' -const usages = [' '] -const aliases = ['translate'] -const enabled = true - -const permLevel = 0 - -const { Translate } = require('translate') - -async function execute (bot, cmd, player, args, handler) { - const language = args.shift() - const text = args.join(' ').replace(/§.?/g, '') - bot.core.run(`minecraft:tellraw @a ${JSON.stringify( - { text: JSON.stringify(await Translate(text, language)), color: bot.colors.primary } - )}`) -} - -module.exports = { name, description, usages, aliases, enabled, execute, permLevel } diff --git a/index.js b/index.js index 688f5d7..da72f23 100644 --- a/index.js +++ b/index.js @@ -12,31 +12,30 @@ const fs = require('fs') const path = require('path') const moment = require('moment') -let filepath = path.join('logs', moment().format('YYYY-MM-DD') + '.log') +const logDir = 'logs' +if (!fs.existsSync(logDir)) fs.mkdirSync(logDir) + +let filepath = path.join(logDir, moment().format('YYYY-MM-DD')) if (fs.existsSync(filepath)) { - const suspath = filepath + '-' + const pathWithSeparator = filepath + '-' let i = 0 while (fs.existsSync(filepath)) { - filepath = suspath + (i++) + filepath = pathWithSeparator + (i++) } } +filepath += '.log' fs.writeFileSync(filepath, '') const servers = [ - 'kaboom.pw:25565:kaboom', - 's.veast.network:25565:kaboom', - 'play.cyclenet.eu:25560:kaboom', - // 'legunepw.apexmc.co:25565:kaboom', - 'ssandcat.aternos.me:25565:vanilla' - // 'kittyandhawk.ddns.net:25565:vanilla' + 'chipmunk.land:25565:kaboom' ] const bots = createBots(servers, { - username: ' ', + username: 'MusicBot', prefix: "'", colors: { primary: 'green', secondary: 'dark_green', error: 'red' }, - version: '1.17.1', - randomizeUsername: true, + version: '1.20.4', + randomizeUsername: false, autoReconnect: true // 'online-mode': { enabled: false, username: 'removed lol', password: null } }) diff --git a/index_sus.js b/index_sus.js deleted file mode 100644 index 1064fd6..0000000 --- a/index_sus.js +++ /dev/null @@ -1,6 +0,0 @@ -const sus = require('./bot') -const servers = ['kaboom.pw:25565:kaboom', ''] - -sus.createBots(servers, { - username: ' ' -}).forEach((bot) => bot.on('login', () => bot.chatQueue.push('i accidentally deleted index.js and lost console code lol'))) diff --git a/persistent/seen.json b/persistent/seen.json index 5074fdd..62d7cc1 100644 --- a/persistent/seen.json +++ b/persistent/seen.json @@ -89,7 +89,7 @@ }, "_ChipMC_": { "first": "2022-03-11T21:15:24.931Z", - "last": "2022-03-22T03:26:08.097Z" + "last": "2024-02-12T03:43:21.153Z" }, "Dinutil§玃§封§�": { "first": "2022-03-11T21:15:24.931Z", @@ -49854,5 +49854,73 @@ "§a6jKKksNm9hi3": { "first": "2022-03-22T03:26:07.918Z", "last": "2022-03-22T03:26:08.097Z" + }, + "§7§6§n§k§b§lHBot": { + "first": "2024-02-12T02:49:06.330Z", + "last": "2024-02-12T02:59:03.100Z" + }, + "iHxOL3uXYfwpPPDO": { + "first": "2024-02-12T02:49:06.332Z", + "last": "2024-02-12T02:57:54.091Z" + }, + "1bhBPyAq8": { + "first": "2024-02-12T02:49:06.333Z", + "last": "2024-02-12T03:16:51.738Z" + }, + "§c§3§3§5§b§lHBot": { + "first": "2024-02-12T03:00:18.499Z", + "last": "2024-02-12T03:00:18.500Z" + }, + "Z9CcyAPHspfvUiwO": { + "first": "2024-02-12T03:00:18.500Z", + "last": "2024-02-12T03:00:18.500Z" + }, + "SBot_zlfIjtU": { + "first": "2024-02-12T03:03:21.257Z", + "last": "2024-02-12T03:03:21.258Z" + }, + "MiBF1qnFN": { + "first": "2024-02-12T03:03:21.258Z", + "last": "2024-02-12T03:07:00.476Z" + }, + "첎绗粉앳䢳蹷酑嶏": { + "first": "2024-02-12T03:03:21.258Z", + "last": "2024-02-12T03:03:21.258Z" + }, + "Thorioum": { + "first": "2024-02-12T03:03:21.258Z", + "last": "2024-02-12T03:05:13.445Z" + }, + "bruhmoment": { + "first": "2024-02-12T03:03:21.258Z", + "last": "2024-02-12T03:04:32.184Z" + }, + "SBot_aE0Rh03": { + "first": "2024-02-12T03:05:13.444Z", + "last": "2024-02-12T03:05:13.570Z" + }, + "㣵㥗瀭氷徭㎪愆풞૰ώ⦇␤먼♑羥": { + "first": "2024-02-12T03:05:13.445Z", + "last": "2024-02-12T03:05:13.445Z" + }, + "WhyMustUDoDis": { + "first": "2024-02-12T03:05:13.445Z", + "last": "2024-02-12T03:05:13.614Z" + }, + "SBot_DAJhfMD": { + "first": "2024-02-12T03:06:57.922Z", + "last": "2024-02-12T03:06:58.511Z" + }, + "謹䵣♯쟗ꩣ뗲뵨㦫": { + "first": "2024-02-12T03:06:58.511Z", + "last": "2024-02-12T03:06:59.304Z" + }, + "§9§3§1§9§b§lHBot": { + "first": "2024-02-12T03:12:45.902Z", + "last": "2024-02-12T03:43:21.153Z" + }, + "4nr6OfyCxS": { + "first": "2024-02-12T03:12:45.905Z", + "last": "2024-02-12T03:18:07.937Z" } } \ No newline at end of file diff --git a/plugins/anti_stuff.js b/plugins/anti_stuff.js index 449ca82..91ecbac 100644 --- a/plugins/anti_stuff.js +++ b/plugins/anti_stuff.js @@ -44,7 +44,7 @@ function client (bot, client) { if (packet.health <= 0) { bot._client.write('client_command', { payload: 0 }) } }) - bot._client.on('declare_commands', () => bot.chat.queue.push(bot.brand === 'kaboom' ? '/op @s[type=player]' : '/trigger opme')) // assumes that the vanilla server has an 'opme' trigger + // bot._client.on('declare_commands', () => bot.chat.queue.push(bot.brand === 'kaboom' ? '/op @s[type=player]' : '/trigger opme')) // assumes that the vanilla server has an 'opme' trigger } module.exports = { bot, client } diff --git a/plugins/chat.js b/plugins/chat.js index bf90b9a..ccb3001 100644 --- a/plugins/chat.js +++ b/plugins/chat.js @@ -1,16 +1,49 @@ const parseText = require('./../util/text_parser.js') +const nbt = require('prismarine-nbt') function bot (bot) { bot.chat = { queue: [], - patterns: [] + patterns: [], + message (message) { + const acc = 0 + const bitset = Buffer.allocUnsafe(3) + + bitset[0] = acc & 0xFF + bitset[1] = (acc >> 8) & 0xFF + bitset[2] = (acc >> 16) & 0xFF + + bot._client.write('chat_message', { + message, + timestamp: BigInt(Date.now()), + salt: 0n, + offset: 0, + acknowledged: bitset + }) + }, + + + command (command) { + bot._client.write('chat_command', { + command, + timestamp: BigInt(Date.now()), + salt: 0n, + argumentSignatures: [], + signedPreview: false, + messageCount: 0, + acknowledged: Buffer.alloc(3), + previousMessages: [] + }) + } } + setInterval(() => { if (!bot.loggedIn) { return } const message = bot.chat.queue.shift() if (message != null) { - bot._client.write('chat', { message }) + if (message[0] === '/') bot.chat.command(message.substring(1)) + else bot.chat.message(message) } }, 200) @@ -28,10 +61,10 @@ function bot (bot) { const player = bot.players[packet.sender] const message = msg.split('> ')[1] bot.emit('message', player, message) - } else if (msg.match(/.* .*§r: §.*/g)) { + } else if (msg.match(/.* .*§r:§r §.*/g)) { if (packet.sender === '00000000-0000-0000-0000-000000000000') return const player = bot.players[packet.sender] - const message = msg.split('§r: ')[1].substr(2) + const message = msg.split('§r:§r ')[1].substring(2) bot.emit('message', player, message) } else if (msg.match(/§.*§b: \/.*/g)) { let username = msg.split('§b: ')[0] @@ -45,10 +78,21 @@ function bot (bot) { } function client (bot, client) { - client.on('chat', (packet) => { - if (JSON.parse(packet.message)?.translate === 'advMode.setCommand.success') return + client.on('profileless_chat', (packet) => { + const message = parseText(nbt.simplify(packet.message)) + bot.emit('chat', message, packet) + }) - const message = parseText(packet.message) + client.on('player_chat', (packet) => { + const message = packet.unsignedChatContent ? parseText(nbt.simplify(packet.unsignedChatContent)) : packet.plainMessage + bot.emit('chat', message, { sender: packet.senderUuid }) + }) + + client.on('system_chat', (packet) => { + const json = nbt.simplify(packet.content) + if (json?.translate === 'advMode.setCommand.success') return + + const message = parseText(json) bot.emit('chat', message, packet) }) } diff --git a/plugins/video.js b/plugins/video.js index a584741..e9fa6a9 100644 --- a/plugins/video.js +++ b/plugins/video.js @@ -1,16 +1,16 @@ const ffmpeg = require('fluent-ffmpeg') -const tmp = require('tmp') +// const tmp = require('tmp') const fs = require('fs') const path = require('path') -const canvas = require('canvas') +// const canvas = require('canvas') const colorsys = require('colorsys') const { randomUUID } = require('crypto') const nbt = require('prismarine-nbt') const SNBT = require('../util/snbt.js') const toNBTUUID = require('./../util/uuid-to-nbt-uuid.js') -const cnv = canvas.createCanvas(256, 144) -const ctx = cnv.getContext('2d') +// const cnv = canvas.createCanvas(256, 144) +// const ctx = cnv.getContext('2d') function inject (bot) { const video = { diff --git a/util/text_parser.js b/util/text_parser.js index 7715556..9e4df84 100644 --- a/util/text_parser.js +++ b/util/text_parser.js @@ -50,9 +50,7 @@ const ansimap = { * @param {string} json_string - A text component string, such as the chat packet's 'message' property. * @returns {object} Parsed message in { raw, clean, ansi } form. */ -function parseText (jsonString) { - const json = JSON.parse(jsonString) - +function parseText (json) { let raw = parseJson(json, { color: 'reset' }) if (raw.startsWith('§r')) { raw = raw.substring(2) @@ -92,6 +90,8 @@ function parseJson (json, parent) { if (json.obfuscated) raw += '§k' if (json.text) { raw += json.text + } else if (json['']) { + raw += json[''] } if (json.translate) { // I checked with the native minecraft code. This is how Minecraft does the matching and group indexing. -hhhzzzsss if (language[json.translate]) {