revert the class changes for between.js, usernameGen.js and ansi.js along with having the bot.js file extend EventEmitter like chayapak suggested

This commit is contained in:
Parker2991
2025-05-07 09:39:07 -04:00
parent a8a0b210be
commit 7cb0524f24
11 changed files with 59 additions and 72 deletions
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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);
}
+1
View File
@@ -235,6 +235,7 @@ class ChatModule {
message = tryParse(packet.content);
}
if (
message.translate === "advMode.setCommand.success" &&
config?.debug?.commandSetMessage === false
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
}
+26 -29
View File
@@ -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;
+2 -4
View File
@@ -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
+12 -15
View File
@@ -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;
+10 -16
View File
@@ -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;