diff --git a/src/bot.js b/src/bot.js index 1debe34..b11d205 100644 --- a/src/bot.js +++ b/src/bot.js @@ -5,7 +5,7 @@ let disconnectCount = 0; EventEmitter.defaultMaxListeners = Infinity; -class CreateBot { +class Bot extends EventEmitter { constructor (options = {}, config) { const bot = new EventEmitter(); bot.options = { @@ -95,5 +95,5 @@ class CreateBot { return bot; } } -module.exports = CreateBot; +module.exports = Bot; diff --git a/src/commands/public/help.js b/src/commands/public/help.js index d7c266f..f406095 100644 --- a/src/commands/public/help.js +++ b/src/commands/public/help.js @@ -435,7 +435,7 @@ class HelpCommand extends CommandContext { bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); } else if (source.sources.discord) { bot.discord.message.reply( - `\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine(component)?.toAnsi()).ansi}\`\`\``, + `\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(component)?.toAnsi())}\`\`\``, ); } else { bot.tellraw("@a", component); diff --git a/src/commands/public/info.js b/src/commands/public/info.js index eac958b..16dcf6a 100644 --- a/src/commands/public/info.js +++ b/src/commands/public/info.js @@ -592,7 +592,7 @@ class InfoCommand extends CommandContext { bot.console.info(bot.getMessageAsPrismarine(component)?.toAnsi()); } else if (source.sources.discord) { bot.discord.message.reply( - `\`\`\`ansi\n${new fixansi(bot.getMessageAsPrismarine(component)?.toAnsi()).ansi}\`\`\``, + `\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(component)?.toAnsi())}\`\`\``, ); } else { bot.tellraw("@a", component); diff --git a/src/index.js b/src/index.js index f20e157..f0757fe 100644 --- a/src/index.js +++ b/src/index.js @@ -2,7 +2,7 @@ const createBot = require("./bot.js"); const readline = require("readline"); const fs = require("fs"); const path = require("path"); -const LoadModules = require("./util/loadModules") +const loadModules = require("./util/loadModules") const { Client, GatewayIntentBits, Partials } = require("discord.js"); const { MessageContent, GuildMessages, Guilds, DirectMessages } = GatewayIntentBits; const discordClient = new Client({ @@ -37,7 +37,7 @@ for (const options of config.bots) { bot = new createBot(options, config); bots.push(bot); bot.bots = bots; - new LoadModules(bot, options, config, discordClient); + loadModules(bot, options, config, discordClient); bot.console.readlineInterface(rl); } diff --git a/src/modules/chat.js b/src/modules/chat.js index a7193ba..30802ca 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -235,6 +235,7 @@ class ChatModule { message = tryParse(packet.content); } + if ( message.translate === "advMode.setCommand.success" && config?.debug?.commandSetMessage === false diff --git a/src/modules/discord.js b/src/modules/discord.js index 1954298..e9319cf 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -57,7 +57,7 @@ class DiscordModule { .replaceAll("```\u001b[9```" + "```\u001b[3```") .replaceAll("https://discord", "https:\rdiscord"); try { - sendDiscordMessage(new fixansi(ansi?.replaceAll("`", "`\u200b")).ansi); + sendDiscordMessage(fixansi(ansi?.replaceAll("`", "`\u200b"))); } catch (e) { bot.console.warn(`Error sending a message to Discord: ${e.message}`); sendDiscordMessage(e.message); diff --git a/src/modules/reconnect.js b/src/modules/reconnect.js index 5cf0171..4c2e613 100644 --- a/src/modules/reconnect.js +++ b/src/modules/reconnect.js @@ -14,7 +14,7 @@ class ReconnectModule { if (options.usernameGen) { client = options.client ?? - mc.createClient(options, (options.username = new usernameGen().username())); + mc.createClient(options, (options.username = usernameGen())); } else { client = options.client ?? mc.createClient(options); } diff --git a/src/util/ansi.js b/src/util/ansi.js index f4eae49..59f3d33 100644 --- a/src/util/ansi.js +++ b/src/util/ansi.js @@ -1,35 +1,32 @@ -class Ansi { - constructor (message) { - const ansilist = { - "\x1B[93m": "\x1B[33m", // Yellow - "\x1B[96m": "\x1B[36m", // Blue - "\x1B[94m": "\x1B[34m", // Discord Blue - "\x1B[90m": "\x1B[30m", // Gray - "\x1B[91m": "\x1B[31m", // Light Red - "\x1B[95m": "\x1B[35m", // Pink - "\x1B[92m": "\x1B[32m", // Green - "\x1B[0m": "\x1B[0m\x1B[37m", // White - "\x1B[97m": "\x1B[0m\x1B[37m", // White - "\x1B[30m": "\x1B[30m", // black - "\x1B[35m": "\x1B[35m", // purple - "\x1B[3m": "\x1B[23m", // italic - "\x1B[4m": "\x1B[24m", // underline - "\x1B[9m": "\x1B[29m", // strike through - "\x1B[6m": "\x1B[29m", // obfuscated - }; - let i = message; +function ansi (message) { + const ansilist = { + "\x1B[93m": "\x1B[33m", // Yellow + "\x1B[96m": "\x1B[36m", // Blue + "\x1B[94m": "\x1B[34m", // Discord Blue + "\x1B[90m": "\x1B[30m", // Gray + "\x1B[91m": "\x1B[31m", // Light Red + "\x1B[95m": "\x1B[35m", // Pink + "\x1B[92m": "\x1B[32m", // Green + "\x1B[0m": "\x1B[0m\x1B[37m", // White + "\x1B[97m": "\x1B[0m\x1B[37m", // White + "\x1B[30m": "\x1B[30m", // black + "\x1B[35m": "\x1B[35m", // purple + "\x1B[3m": "\x1B[23m", // italic + "\x1B[4m": "\x1B[24m", // underline + "\x1B[9m": "\x1B[29m", // strike through + "\x1B[6m": "\x1B[29m", // obfuscated + }; + let i = message; - for (const ansi in ansilist) { - if (ansilist.hasOwnProperty(ansi)) { - i = i.replace(new RegExp(escapeRegExpChars(ansi), "g"), ansilist[ansi]); + for (const ansi in ansilist) { + if (ansilist.hasOwnProperty(ansi)) { + i = i.replace(new RegExp(escapeRegExpChars(ansi), "g"), ansilist[ansi]); - function escapeRegExpChars(text) { - return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); - } + function escapeRegExpChars(text) { + return text.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); } } - this.ansi = i - return i; } + return i; } -module.exports = Ansi; +module.exports = ansi; diff --git a/src/util/between.js b/src/util/between.js index 05e37e6..a48d05d 100644 --- a/src/util/between.js +++ b/src/util/between.js @@ -1,7 +1,5 @@ -class Between { - constructor () { - this._Between = Math.floor(Math.random() * (max - min) + min); - } +function between (min, max) { + return Math.floor(Math.random() * (max - min) + min); } module.exports = Between; // ported from FNFBoyfriendBot v3 diff --git a/src/util/loadModules.js b/src/util/loadModules.js index 42ee197..86d768b 100644 --- a/src/util/loadModules.js +++ b/src/util/loadModules.js @@ -1,21 +1,18 @@ const fs = require("fs"); const path = require("path"); -//async function loadModules(bot, options, config, discordClient) { -class LoadModules { - constructor (bot, options, config, discordClient) { - bot.modules = []; - for (const filename of fs.readdirSync(path.join(__dirname, "../", "modules"))) { - try { - if (filename.endsWith(".js")) { - const module = require(path.join(__dirname, "../modules", filename)); - bot.modules.push(module); - new module({ bot, options, config, discordClient }); - } - } catch (error) { - console.error(`Failed to load module ${filename} due to error`); - console.error(`\x1b[31m${error.stack}\x1b[0m`); +async function loadModules(bot, options, config, discordClient) { + bot.modules = []; + for (const filename of fs.readdirSync(path.join(__dirname, "../", "modules"))) { + try { + if (filename.endsWith(".js")) { + const module = require(path.join(__dirname, "../modules", filename)); + bot.modules.push(module); + new module({ bot, options, config, discordClient }); } + } catch (error) { + console.error(`Failed to load module ${filename} due to error`); + console.error(`\x1b[31m${error.stack}\x1b[0m`); } } } -module.exports = LoadModules; +module.exports = loadModules; diff --git a/src/util/usernameGen.js b/src/util/usernameGen.js index a9cb7f5..f32a715 100644 --- a/src/util/usernameGen.js +++ b/src/util/usernameGen.js @@ -1,18 +1,12 @@ -//function usernameGen() { -class UsernameGen { - username () { - const characters = - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - let username = ""; - for (let i = 0; i < 3 + Math.floor(Math.random() * 14); i++) { - const randomIndex = Math.floor(Math.random() * characters.length); - username += characters[randomIndex]; - } - return this._username = username; +function usernameGen() { + const characters = + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; + let username = ""; + for (let i = 0; i < 3 + Math.floor(Math.random() * 14); i++) { + const randomIndex = Math.floor(Math.random() * characters.length); + username += characters[randomIndex]; } - -// get username () { - // return this._username - //} + return username; } -module.exports = UsernameGen; + +module.exports = usernameGen;