From 9c23572db3c48d1f740481631a7c6b5e49cc5c85 Mon Sep 17 00:00:00 2001 From: Chipmunk <65827213+ChipmunkMC@users.noreply.github.com> Date: Fri, 16 Feb 2024 21:37:11 -0500 Subject: [PATCH] mogus --- .gitignore | 2 ++ index.js | 52 ++++++++++++++++++++++----------------------- package-lock.json | 43 ++++++++++++++++++++++++++----------- package.json | 5 +++-- plugins/commands.js | 12 +++++++++-- plugins/console.js | 4 ++-- plugins/players.js | 12 +---------- 7 files changed, 75 insertions(+), 55 deletions(-) diff --git a/.gitignore b/.gitignore index dbcfa03..fc8fd2d 100644 --- a/.gitignore +++ b/.gitignore @@ -108,8 +108,10 @@ config.js config.json # Other +config.json5 logs music images videos functions +persistent diff --git a/index.js b/index.js index 6d9ea62..7cec9ef 100644 --- a/index.js +++ b/index.js @@ -1,36 +1,36 @@ const readline = require('readline') +const { createBots } = require('./bot.js') +const fs = require('fs') +const path = require('path') +const moment = require('moment') +const json5 = require('json5') + +if (!fs.existsSync('config.json5')) { + fs.copyFileSync(path.join(__dirname, 'default.json5'), 'config.json') + console.info('No config file was found, so a default one was created.') +} +const config = json5.parse(fs.readFileSync('config.json5', 'utf-8')) + +const logdir = 'logs' +if (!fs.existsSync(logdir)) fs.mkdirSync(logdir) + +let logfile = path.join(logDir, moment().format('YYYY-MM-DD')) +if (fs.existsSync(logfile)) { + const pathWithSeparator = logfile + '-' + let i = 0 + while (fs.existsSync(logfile)) { + logfile = pathWithSeparator + (i++) + } +} +filepath += '.log' +fs.writeFileSync(logfile, '') + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, prefix: '> ' }) -const { createBots } = require('./bot.js') -// const commandHandler = require('./commands.js') - -const fs = require('fs') -const path = require('path') -const moment = require('moment') - -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 pathWithSeparator = filepath + '-' - let i = 0 - while (fs.existsSync(filepath)) { - filepath = pathWithSeparator + (i++) - } -} -filepath += '.log' -fs.writeFileSync(filepath, '') - -const servers = [ - 'play.kaboom.pw:25565:kaboom', - 'chipmunk.land:25565:kaboom' -] - const bots = createBots(servers, { username: ' ', prefix: "'", diff --git a/package-lock.json b/package-lock.json index 12104bb..f44bb4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git", "colorsys": "^1.0.22", "fluent-ffmpeg": "^2.1.2", + "json5": "^2.2.3", "kahoot.js-api": "^2.4.0", "minecraft-protocol": "^1.26.5", "moment": "^2.29.1", @@ -1991,14 +1992,14 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, "node_modules/json5": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", - "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", - "dependencies": { - "minimist": "^1.2.0" - }, + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "bin": { "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" } }, "node_modules/jsonwebtoken": { @@ -3360,6 +3361,17 @@ "strip-bom": "^3.0.0" } }, + "node_modules/tsconfig-paths/node_modules/json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "json5": "lib/cli.js" + } + }, "node_modules/tweetnacl": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", @@ -4985,12 +4997,9 @@ "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=" }, "json5": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", - "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", - "requires": { - "minimist": "^1.2.0" - } + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==" }, "jsonwebtoken": { "version": "9.0.2", @@ -6000,6 +6009,16 @@ "json5": "^1.0.1", "minimist": "^1.2.0", "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "requires": { + "minimist": "^1.2.0" + } + } } }, "tweetnacl": { diff --git a/package.json b/package.json index c711433..181e833 100644 --- a/package.json +++ b/package.json @@ -3,15 +3,16 @@ "@mozilla/readability": "^0.4.1", "@skeldjs/client": "^2.15.17", "@tonejs/midi": "^2.0.27", + "brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git", "colorsys": "^1.0.22", "fluent-ffmpeg": "^2.1.2", + "json5": "^2.2.3", "kahoot.js-api": "^2.4.0", "minecraft-protocol": "^1.26.5", "moment": "^2.29.1", "prismarine-nbt": "^2.2.0", "rfb2": "^0.2.2", "standard": "^16.0.4", - "urban-dictionary": "git+https://code.chipmunk.land/ChipmunkMC/urban-dictionary.git", - "brigadier-commands": "git+https://code.chipmunk.land/ChipmunkMC/node-brigadier-commands.git" + "urban-dictionary": "git+https://code.chipmunk.land/ChipmunkMC/urban-dictionary.git" } } diff --git a/plugins/commands.js b/plugins/commands.js index b25f8dd..d6dd565 100644 --- a/plugins/commands.js +++ b/plugins/commands.js @@ -19,7 +19,9 @@ function inject (bot) { bot.on('message', (player, message) => { if (!message.startsWith(bot.prefix)) return - const sendFeedback = message => bot.core.run('minecraft:tellraw @a ' + JSON.stringify(message)) + function sendFeedback (message) { + bot.core.run('minecraft:tellraw @a ' + JSON.stringify(message)) + } bot.commands.execute(message.substring(bot.prefix.length), new CommandSource({ bot, sendFeedback })) }) @@ -32,7 +34,13 @@ function inject (bot) { if (isValid(command)) { bot.console.warn(`Command '${command.aliases[0]}' is using the legacy command system!`) - const _execute = args => command.execute(bot, command.aliases[0], {}, args) + const _execute = args => { + try { + command.execute(bot, command.aliases[0], {}, args) + } catch (error) { + bot.core.run('minecraft:tellraw @a ' + JSON.stringify({ text: error.toString(), color: 'red' })) + } + } const node = bot.commands.dispatcher.register( literal(command.aliases[0]) diff --git a/plugins/console.js b/plugins/console.js index 9cdbb3f..edcff66 100644 --- a/plugins/console.js +++ b/plugins/console.js @@ -82,8 +82,8 @@ function inject (bot) { } } - function sendFeedback (message) {console.log(message) - const { raw } = parseText(message);console.log(raw) + function sendFeedback (message) { + const { raw } = parseText(message) bot.console.log(raw) } } diff --git a/plugins/players.js b/plugins/players.js index 9134b2f..c2b63bf 100644 --- a/plugins/players.js +++ b/plugins/players.js @@ -1,15 +1,5 @@ function inject (bot, client) { - bot.players ??= {} - - client.on('player_info', (packet) => { - if (packet.action === 0) { - packet.data.forEach((player) => { - bot.players[player.name] = player - bot.players[player.UUID] = player - if (player.UUID === bot._client.uuid) { bot.player = player } - }) - } - }) + bot } module.exports.client = inject