diff --git a/.eslintrc b/.eslintrc index 2c0a4d7e..08c2cab7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -21,6 +21,6 @@ "prefer-const": ["warn", { "destructuring": "all" }], "no-constant-condition": ["error", { "checkLoops": false }], "import/extensions": ["warn", "always", { "ts": "never" }], - "no-throw-literal": "error" + "no-throw-literal": "error", } } diff --git a/API/stats/bestiary.js b/API/stats/bestiary.js index faf6038e..f85960e5 100644 --- a/API/stats/bestiary.js +++ b/API/stats/bestiary.js @@ -72,7 +72,7 @@ function getBestiary(userProfile) { maxMilestone: totalTiers / 10 }; } catch (error) { - console.log(error); + console.error(error); return null; } } diff --git a/API/stats/chocolateFactory.js b/API/stats/chocolateFactory.js index 83921423..08a2fe57 100644 --- a/API/stats/chocolateFactory.js +++ b/API/stats/chocolateFactory.js @@ -18,7 +18,7 @@ module.exports = (profile) => { level: profile.events?.easter?.chocolate_level || 0 }; } catch (error) { - console.log(error); + console.error(error); return null; } }; diff --git a/API/stats/crimson.js b/API/stats/crimson.js index 099bd59e..e06d144b 100644 --- a/API/stats/crimson.js +++ b/API/stats/crimson.js @@ -1,5 +1,4 @@ // CREDITS: by @Kathund (https://github.com/Kathund) - const { titleCase } = require("../constants/functions.js"); module.exports = (profile) => { @@ -62,7 +61,7 @@ module.exports = (profile) => { trophyFishing: getTrophyFish(profile) }; } catch (error) { - console.log(error); + console.error(error); return null; } }; diff --git a/API/stats/dungeons.js b/API/stats/dungeons.js index ade0783e..5f843827 100644 --- a/API/stats/dungeons.js +++ b/API/stats/dungeons.js @@ -95,7 +95,7 @@ module.exports = (profile) => { } }; } catch (error) { - console.log(error); + console.error(error); return null; } }; diff --git a/API/stats/hotm.js b/API/stats/hotm.js index 001d8bf2..2b437e57 100644 --- a/API/stats/hotm.js +++ b/API/stats/hotm.js @@ -34,7 +34,7 @@ module.exports = (profile) => { forgeItem.timeFinishedText = timeFinished < Date.now() ? "Finished" : `ending ${moment(timeFinished).fromNow()}`; } else { - console.log(item); + console.error(item); forgeItem.name = "Unknown Item"; forgeItem.id = `UNKNOWN-${item.id}`; } @@ -66,7 +66,7 @@ module.exports = (profile) => { forge: forgeItems }; } catch (error) { - console.log(error); + console.error(error); return null; } }; diff --git a/API/stats/talismans.js b/API/stats/talismans.js index 3364846c..85884aaf 100644 --- a/API/stats/talismans.js +++ b/API/stats/talismans.js @@ -75,7 +75,7 @@ module.exports = async (profile) => { return null; } } catch (error) { - console.log(error); + console.error(error); return null; } }; diff --git a/index.js b/index.js index 1606ba71..572f56ac 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ process.on("uncaughtException", (error) => console.log(error)); const app = require("./src/Application.js"); diff --git a/package.json b/package.json index c9cb4900..952741ea 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,10 @@ "scripts": { "start": "node index.js", "test": "jest --detectOpenHandles --forceExit", - "lint": "npx eslint .", - "lint:fix": "npx eslint . --fix", - "prettier": "npx prettier --check .", - "prettier:fix": "npx prettier --write .", + "lint": "npx eslint src/", + "lint:fix": "npx eslint src/ --fix", + "prettier": "npx prettier src/ --check", + "prettier:fix": "npx prettier src/ --write", "nodemon": "nodemon index" }, "repository": { diff --git a/src/Application.js b/src/Application.js index fe6a9a1b..b90d7ee9 100644 --- a/src/Application.js +++ b/src/Application.js @@ -7,6 +7,7 @@ class Application { constructor() { require("./Configuration.js"); require("./Updater.js"); + require("./Logger.js"); if (!existsSync("./data/")) mkdirSync("./data/", { recursive: true }); if (!existsSync("./data/linked.json")) writeFileSync("./data/linked.json", JSON.stringify({})); } diff --git a/src/Logger.js b/src/Logger.js index f05d5cf5..d215acb6 100644 --- a/src/Logger.js +++ b/src/Logger.js @@ -1,8 +1,8 @@ +/* eslint-disable no-console */ const customLevels = { discord: 0, minecraft: 1, web: 2, warn: 3, error: 4, broadcast: 5, max: 6 }; const { createLogger, format, transports } = require("winston"); const config = require("../config.json"); const chalk = require("chalk"); - const discordTransport = new transports.File({ level: "discord", filename: "./logs/discord.log" }); const minecraftTransport = new transports.File({ level: "minecraft", filename: "./logs/minecraft.log" }); const webTransport = new transports.File({ level: "web", filename: "./logs/web.log" }); @@ -115,12 +115,13 @@ function warnMessage(message) { return console.log(chalk.bgYellow.black(`[${getCurrentTime()}] Warning >`) + " " + chalk.yellow(message)); } -function errorMessage(message) { +function errorMessage(error) { + const errorString = `${error.toString()}${error.stack?.replace(error.toString(), "")}`; if (config.other.logToFiles) { - errorLogger.log("error", message); + errorLogger.log("error", errorString); } - return console.log(chalk.bgRedBright.black(`[${getCurrentTime()}] Error >`) + " " + chalk.redBright(message)); + return console.log(chalk.bgRedBright.black(`[${getCurrentTime()}] Error >`) + " " + chalk.redBright(errorString)); } function broadcastMessage(message, location) { @@ -174,13 +175,14 @@ async function updateMessage() { console.log(chalk.bgRed.black(" ".repeat(columns).repeat(3))); } +console.discord = discordMessage; +console.minecraft = minecraftMessage; +console.web = webMessage; +console.warn = warnMessage; +console.error = errorMessage; +console.broadcast = broadcastMessage; + module.exports = { - discordMessage, - minecraftMessage, - webMessage, - warnMessage, - errorMessage, - broadcastMessage, getCurrentTime, configUpdateMessage, updateMessage diff --git a/src/Updater.js b/src/Updater.js index 707c37bd..a471fa49 100644 --- a/src/Updater.js +++ b/src/Updater.js @@ -10,7 +10,7 @@ function updateCode() { exec("git pull", (error, stdout, stderr) => { if (error) { - console.error(`Git pull error: ${error}`); + console.error(error); return; } diff --git a/src/contracts/API/mowojangAPI.js b/src/contracts/API/mowojangAPI.js index abf556b2..97a8b43c 100644 --- a/src/contracts/API/mowojangAPI.js +++ b/src/contracts/API/mowojangAPI.js @@ -28,7 +28,7 @@ async function getUUID(username) { } catch (error) { // eslint-disable-next-line no-throw-literal if (error.response.data === "Not found") throw "Invalid username."; - console.log(error); + console.error(error); throw error; } } @@ -57,7 +57,7 @@ async function getUsername(uuid) { return data.name; } catch (error) { - console.log(error); + console.error(error); // eslint-disable-next-line no-throw-literal if (error.response?.data === "Not found") throw "Invalid UUID."; throw error; @@ -75,7 +75,7 @@ async function resolveUsernameOrUUID(username) { } catch (error) { // eslint-disable-next-line no-throw-literal if (error.response.data === "Not found") throw "Invalid Username Or UUID."; - console.log(error); + console.error(error); throw error; } } diff --git a/src/discord/CommandHandler.js b/src/discord/CommandHandler.js index 1f8eeffb..bd3f99c7 100644 --- a/src/discord/CommandHandler.js +++ b/src/discord/CommandHandler.js @@ -24,7 +24,7 @@ class CommandHandler { rest .put(Routes.applicationGuildCommands(clientID, config.discord.bot.serverID), { body: commands }) - .catch(console.error); + .catch((e) => console.error(e)); } } diff --git a/src/discord/DiscordManager.js b/src/discord/DiscordManager.js index 528d6a82..8e67c50d 100644 --- a/src/discord/DiscordManager.js +++ b/src/discord/DiscordManager.js @@ -6,7 +6,6 @@ const MessageHandler = require("./handlers/MessageHandler.js"); const StateHandler = require("./handlers/StateHandler.js"); const CommandHandler = require("./CommandHandler.js"); const config = require("../../config.json"); -const Logger = require(".././Logger.js"); const fs = require("fs"); class DiscordManager extends CommunicationBridge { @@ -37,7 +36,7 @@ class DiscordManager extends CommunicationBridge { this.client.on("messageCreate", (message) => this.messageHandler.onMessage(message)); this.client.login(config.discord.bot.token).catch((error) => { - Logger.errorMessage(error); + console.error(error); }); client.commands = new Collection(); @@ -94,7 +93,7 @@ class DiscordManager extends CommunicationBridge { const mode = chat === "debugChannel" ? "minecraft" : config.discord.other.messageMode.toLowerCase(); message = chat === "debugChannel" ? fullMessage : message; if (message !== undefined && chat !== "debugChannel") { - Logger.broadcastMessage( + console.broadcast( `${username} [${guildRank.replace(/§[0-9a-fk-or]/g, "").replace(/^\[|\]$/g, "")}]: ${message}`, `Discord` ); @@ -107,7 +106,7 @@ class DiscordManager extends CommunicationBridge { const channel = await this.stateHandler.getChannel(chat || "Guild"); if (channel === undefined) { - Logger.errorMessage(`Channel ${chat} not found!`); + console.error(`Channel ${chat} not found!`); return; } if (username === bot.username && message.endsWith("Check Discord Bridge for image.")) { @@ -182,7 +181,7 @@ class DiscordManager extends CommunicationBridge { } async onBroadcastCleanEmbed({ message, color, channel }) { - Logger.broadcastMessage(message, "Event"); + console.broadcast(message, "Event"); channel = await this.stateHandler.getChannel(channel); channel.send({ @@ -196,7 +195,7 @@ class DiscordManager extends CommunicationBridge { } async onBroadcastHeadedEmbed({ message, title, icon, color, channel }) { - Logger.broadcastMessage(message, "Event"); + console.broadcast(message, "Event"); channel = await this.stateHandler.getChannel(channel); channel.send({ @@ -214,7 +213,7 @@ class DiscordManager extends CommunicationBridge { } async onPlayerToggle({ fullMessage, username, message, color, channel }) { - Logger.broadcastMessage(message, "Event"); + console.broadcast(message, "Event"); channel = await this.stateHandler.getChannel(channel); switch (config.discord.other.messageMode.toLowerCase()) { case "bot": diff --git a/src/discord/commands/helpCommand.js b/src/discord/commands/helpCommand.js index 2dfbe310..ed91bda4 100644 --- a/src/discord/commands/helpCommand.js +++ b/src/discord/commands/helpCommand.js @@ -86,7 +86,7 @@ module.exports = { await interaction.followUp({ embeds: [embed] }); } } catch (error) { - console.log(error); + console.error(error); } } }; diff --git a/src/discord/commands/infoCommand.js b/src/discord/commands/infoCommand.js index 3f52c7c7..feac5e18 100644 --- a/src/discord/commands/infoCommand.js +++ b/src/discord/commands/infoCommand.js @@ -88,7 +88,7 @@ module.exports = { ); await interaction.followUp({ embeds: [infoEmbed] }); } catch (e) { - console.log(e); + console.error(e); } } }; diff --git a/src/discord/commands/verifyCommand.js b/src/discord/commands/verifyCommand.js index 652c2093..bafbeedd 100644 --- a/src/discord/commands/verifyCommand.js +++ b/src/discord/commands/verifyCommand.js @@ -95,7 +95,7 @@ module.exports = { await updateRolesCommand.execute(interaction, user); } catch (error) { - console.log(error); + console.error(error); // eslint-disable-next-line no-ex-assign error = error .toString() diff --git a/src/discord/events/interactionCreate.js b/src/discord/events/interactionCreate.js index 94429f90..83e9668c 100644 --- a/src/discord/events/interactionCreate.js +++ b/src/discord/events/interactionCreate.js @@ -3,7 +3,6 @@ const { ErrorEmbed, SuccessEmbed } = require("../../contracts/embedHandler.js"); // eslint-disable-next-line no-unused-vars const { CommandInteraction } = require("discord.js"); const config = require("../../../config.json"); -const Logger = require("../.././Logger.js"); module.exports = { name: "interactionCreate", @@ -24,7 +23,7 @@ module.exports = { return; } - Logger.discordMessage(`${interaction.user.username} - [${interaction.commandName}]`); + console.discord(`${interaction.user.username} - [${interaction.commandName}]`); if (command.verificationCommand === true && config.verification.enabled === false) { throw new HypixelDiscordChatBridgeError("Verification is disabled."); @@ -54,8 +53,7 @@ module.exports = { await interaction.followUp({ embeds: [embed] }); } } catch (error) { - console.log(error); - + console.error(error); const errrorMessage = error instanceof HypixelDiscordChatBridgeError ? "" diff --git a/src/discord/handlers/MessageHandler.js b/src/discord/handlers/MessageHandler.js index 57784fc4..06a7efab 100644 --- a/src/discord/handlers/MessageHandler.js +++ b/src/discord/handlers/MessageHandler.js @@ -68,7 +68,7 @@ class MessageHandler { this.discord.broadcastMessage(messageData); } catch (error) { - console.log(error); + console.error(error); } } @@ -111,7 +111,7 @@ class MessageHandler { return mentionedUserName ?? null; } catch (error) { - console.log(error); + console.error(error); return null; } } diff --git a/src/discord/handlers/StateHandler.js b/src/discord/handlers/StateHandler.js index 3161d60a..cf57dcbd 100644 --- a/src/discord/handlers/StateHandler.js +++ b/src/discord/handlers/StateHandler.js @@ -1,5 +1,4 @@ const config = require("../../../config.json"); -const Logger = require("../../Logger.js"); class StateHandler { constructor(discord) { @@ -7,17 +6,17 @@ class StateHandler { } async onReady() { - Logger.discordMessage("Client ready, logged in as " + this.discord.client.user.tag); + console.discord("Client ready, logged in as " + this.discord.client.user.tag); this.discord.client.user.setPresence({ activities: [{ name: `/help | by @duckysolucky` }] }); global.guild = await client.guilds.fetch(config.discord.bot.serverID); - Logger.discordMessage("Guild ready, successfully fetched " + guild.name); + console.discord(`Guild ready, successfully fetched ${guild.name}`); const channel = await this.getChannel("Guild"); if (channel === undefined) { - return Logger.errorMessage(`Channel "Guild" not found!`); + return console.error(`Channel "Guild" not found!`); } if (config.verification.autoUpdater) require("../other/updateUsers.js"); @@ -36,7 +35,7 @@ class StateHandler { async onClose() { const channel = await this.getChannel("Guild"); if (channel === undefined) { - return Logger.errorMessage(`Channel "Guild" not found!`); + return console.error(`Channel "Guild" not found!`); } await channel.send({ @@ -51,7 +50,7 @@ class StateHandler { async getChannel(type) { if (typeof type !== "string" || type === undefined) { - return Logger.errorMessage(`Channel type must be a string!`); + return console.error(`Channel type must be a string!`); } switch (type.replace(/§[0-9a-fk-or]/g, "").trim()) { diff --git a/src/discord/other/updateUsers.js b/src/discord/other/updateUsers.js index 56627560..721cf3f2 100644 --- a/src/discord/other/updateUsers.js +++ b/src/discord/other/updateUsers.js @@ -1,17 +1,16 @@ const updateRolesCommand = require("../commands/forceUpdateEveryone.js"); const config = require("../../../config.json"); -const Logger = require("../../Logger.js"); const cron = require("node-cron"); if (config.verification.autoUpdater) { - Logger.discordMessage(`RoleSync ready, executing every ${config.verification.autoUpdaterInterval} hours.`); + console.discord(`RoleSync ready, executing every ${config.verification.autoUpdaterInterval} hours.`); cron.schedule(`0 */${config.verification.autoUpdaterInterval} * * *`, async () => { try { - Logger.discordMessage("Executing RoleSync..."); + console.discord("Executing RoleSync..."); await updateRolesCommand.execute(null, true); - Logger.discordMessage("RoleSync successfully executed."); + console.discord("RoleSync successfully executed."); } catch (error) { - console.log(error); + console.error(error); } }); } diff --git a/src/minecraft/CommandHandler.js b/src/minecraft/CommandHandler.js index c368b17d..f2dbe7b0 100644 --- a/src/minecraft/CommandHandler.js +++ b/src/minecraft/CommandHandler.js @@ -1,6 +1,5 @@ const { Collection } = require("discord.js"); const config = require("../../config.json"); -const Logger = require("../Logger.js"); const axios = require("axios"); const fs = require("fs"); @@ -34,8 +33,8 @@ class CommandHandler { return; } + console.minecraft(`${player} - [${command.name}] ${message}`); command.officer = officer; - Logger.minecraftMessage(`${player} - [${command.name}] ${message}`); command.onCommand(player, message); } else if (message.startsWith("-") && message.startsWith("- ") === false) { if (config.minecraft.commands.soopy === false || message.at(1) === "-") { @@ -49,7 +48,7 @@ class CommandHandler { bot.chat(`/${officer ? "oc" : "gc"} [SOOPY V2] ${message}`); - Logger.minecraftMessage(`${player} - [${command}] ${message}`); + console.minecraft(`${player} - [${command}] ${message}`); (async () => { try { diff --git a/src/minecraft/MinecraftManager.js b/src/minecraft/MinecraftManager.js index 7eae9f57..6a646092 100644 --- a/src/minecraft/MinecraftManager.js +++ b/src/minecraft/MinecraftManager.js @@ -6,8 +6,8 @@ const ChatHandler = require("./handlers/ChatHandler.js"); const CommandHandler = require("./CommandHandler.js"); const config = require("../../config.json"); const mineflayer = require("mineflayer"); -const Logger = require("../Logger.js"); const Filter = require("bad-words"); + const filter = new Filter(); const fileredWords = config.discord.other.filterWords ?? ""; filter.addWords(...fileredWords); @@ -48,7 +48,7 @@ class MinecraftManager extends CommunicationBridge { } async onBroadcast({ channel, username, message, replyingTo, discord }) { - Logger.broadcastMessage(`${username}: ${message}`, "Minecraft"); + console.broadcast(`${username}: ${message}`, "Minecraft"); if (this.bot.player === undefined) { return; } diff --git a/src/minecraft/commands/PlayerCommand.js b/src/minecraft/commands/PlayerCommand.js index 363b45c2..0027ea74 100644 --- a/src/minecraft/commands/PlayerCommand.js +++ b/src/minecraft/commands/PlayerCommand.js @@ -31,7 +31,7 @@ class PlayerCommand extends minecraftCommand { `${rank !== "Default" ? `[${rank}] ` : ""}${nickname}'s level: ${level} | Karma: ${formatNumber(karma, 0)} Achievement Points: ${formatNumber(achievementPoints, 0)} Guild: ${guildName} ` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/auctionHouseCommand.js b/src/minecraft/commands/auctionHouseCommand.js index 6df82405..8dba30ce 100644 --- a/src/minecraft/commands/auctionHouseCommand.js +++ b/src/minecraft/commands/auctionHouseCommand.js @@ -93,7 +93,7 @@ class AuctionHouseCommand extends minecraftCommand { imgurUrl = string; this.send(`${username}'s Active Auctions: Check Discord Bridge for image.`); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/bestiaryCommand.js b/src/minecraft/commands/bestiaryCommand.js index 8114c7d8..afc29982 100644 --- a/src/minecraft/commands/bestiaryCommand.js +++ b/src/minecraft/commands/bestiaryCommand.js @@ -69,7 +69,7 @@ class BestiaryCommand extends minecraftCommand { this.send(`Closest to level up: ${topFiveMobs.join(", ")}`); } } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/catacombsCommand.js b/src/minecraft/commands/catacombsCommand.js index 6ae13889..e2eb9f6a 100644 --- a/src/minecraft/commands/catacombsCommand.js +++ b/src/minecraft/commands/catacombsCommand.js @@ -1,7 +1,7 @@ -const minecraftCommand = require("../../contracts/minecraftCommand.js"); -const getDungeons = require("../../../API/stats/dungeons.js"); const { formatNumber, formatUsername } = require("../../contracts/helperFunctions.js"); const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); +const minecraftCommand = require("../../contracts/minecraftCommand.js"); +const getDungeons = require("../../../API/stats/dungeons.js"); class CatacombsCommand extends minecraftCommand { constructor(minecraft) { @@ -58,7 +58,7 @@ class CatacombsCommand extends minecraftCommand { )} (${SR} S/R)` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/crimsonIsleCommand.js b/src/minecraft/commands/crimsonIsleCommand.js index e7540932..ec0e1897 100644 --- a/src/minecraft/commands/crimsonIsleCommand.js +++ b/src/minecraft/commands/crimsonIsleCommand.js @@ -39,7 +39,7 @@ class CrimsonIsleCommand extends minecraftCommand { )} | Mage Rep: ${formatNumber(profile.reputation.mage)}` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/dojoCommand.js b/src/minecraft/commands/dojoCommand.js index 42217edb..ec431a7e 100644 --- a/src/minecraft/commands/dojoCommand.js +++ b/src/minecraft/commands/dojoCommand.js @@ -45,7 +45,7 @@ class DojoCommand extends minecraftCommand { )}` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/essenceCommand.js b/src/minecraft/commands/essenceCommand.js index 7cf977a4..01af4c07 100644 --- a/src/minecraft/commands/essenceCommand.js +++ b/src/minecraft/commands/essenceCommand.js @@ -48,7 +48,7 @@ class EssenceCommand extends minecraftCommand { )} | Ice: ${formatNumber(dungeons.essence.ice, 0)} | Crimson: ${formatNumber(dungeons.essence.crimson, 0)}` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } diff --git a/src/minecraft/commands/kuudraCommand.js b/src/minecraft/commands/kuudraCommand.js index 19d1edcd..e12cd98f 100644 --- a/src/minecraft/commands/kuudraCommand.js +++ b/src/minecraft/commands/kuudraCommand.js @@ -41,7 +41,7 @@ class KuudraCommand extends minecraftCommand { )} | Infernal: ${formatNumber(profile.kuudra.infernal)}` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/networthCommand.js b/src/minecraft/commands/networthCommand.js index ee9ba3d1..67c87e7b 100644 --- a/src/minecraft/commands/networthCommand.js +++ b/src/minecraft/commands/networthCommand.js @@ -1,7 +1,7 @@ +const { formatNumber, formatUsername } = require("../../contracts/helperFunctions.js"); +const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); const minecraftCommand = require("../../contracts/minecraftCommand.js"); const { getNetworth } = require("skyhelper-networth"); -const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); -const { formatNumber, formatUsername } = require("../../contracts/helperFunctions.js"); class NetWorthCommand extends minecraftCommand { constructor(minecraft) { @@ -48,7 +48,7 @@ class NetWorthCommand extends minecraftCommand { `${username}'s Networth is ${networth} | Unsoulbound Networth: ${unsoulboundNetworth} | Purse: ${purse} | Bank: ${bank} | Museum: ${museum}` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/personalBestCommand.js b/src/minecraft/commands/personalBestCommand.js index 64a4d472..b9b2049b 100644 --- a/src/minecraft/commands/personalBestCommand.js +++ b/src/minecraft/commands/personalBestCommand.js @@ -2,6 +2,7 @@ const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js const { formatUsername } = require("../../contracts/helperFunctions.js"); const minecraftCommand = require("../../contracts/minecraftCommand.js"); const getDungeons = require("../../../API/stats/dungeons.js"); + class PersonalBestCommand extends minecraftCommand { constructor(minecraft) { super(minecraft); @@ -91,7 +92,7 @@ class PersonalBestCommand extends minecraftCommand { this.send(`${username}'s PB on ${floor} with ${rank} rank is ${millisToMinutesAndSeconds(time)}`); } } catch (error) { - console.log(error); + console.error(error); this.send(`ERROR: ${error}`); } } diff --git a/src/minecraft/commands/renderItemsCommand.js b/src/minecraft/commands/renderItemsCommand.js index f34c30af..92d67739 100644 --- a/src/minecraft/commands/renderItemsCommand.js +++ b/src/minecraft/commands/renderItemsCommand.js @@ -1,7 +1,7 @@ -const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); -const { uploadImage } = require("../../contracts/API/imgurAPI.js"); const { decodeData, formatUsername } = require("../../contracts/helperFunctions.js"); +const { getLatestProfile } = require("../../../API/functions/getLatestProfile.js"); const minecraftCommand = require("../../contracts/minecraftCommand.js"); +const { uploadImage } = require("../../contracts/API/imgurAPI.js"); const { renderLore } = require("../../contracts/renderItem.js"); class RenderCommand extends minecraftCommand { @@ -75,7 +75,7 @@ class RenderCommand extends minecraftCommand { imgurUrl = upload.data.link; this.send(`${username}'s item at slot ${itemNumber}: Check Discord Bridge for image.`); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/renderPetCommand.js b/src/minecraft/commands/renderPetCommand.js index e6afc046..beda993c 100644 --- a/src/minecraft/commands/renderPetCommand.js +++ b/src/minecraft/commands/renderPetCommand.js @@ -49,7 +49,7 @@ class RenderCommand extends minecraftCommand { imgurUrl = upload.data.link ?? "Something went Wrong.."; return this.send(`${username}'s Active Pet: Check Discord Bridge for image.`); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/skyblockLevelCommand.js b/src/minecraft/commands/skyblockLevelCommand.js index 510036b5..c60fd2f9 100644 --- a/src/minecraft/commands/skyblockLevelCommand.js +++ b/src/minecraft/commands/skyblockLevelCommand.js @@ -29,8 +29,7 @@ class CatacombsCommand extends minecraftCommand { const experience = data.profile.leveling?.experience ?? 0; this.send(`${username}'s Skyblock Level: ${experience ? experience / 100 : 0}`); } catch (error) { - console.log(error); - + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/commands/trophyFishCommand.js b/src/minecraft/commands/trophyFishCommand.js index 199c6110..461bb78d 100644 --- a/src/minecraft/commands/trophyFishCommand.js +++ b/src/minecraft/commands/trophyFishCommand.js @@ -43,7 +43,7 @@ class TrophyFishCommand extends minecraftCommand { )} / 18` ); } catch (error) { - console.log(error); + console.error(error); this.send(`[ERROR] ${error}`); } } diff --git a/src/minecraft/handlers/ChatHandler.js b/src/minecraft/handlers/ChatHandler.js index 06ef6c3c..41002491 100644 --- a/src/minecraft/handlers/ChatHandler.js +++ b/src/minecraft/handlers/ChatHandler.js @@ -9,7 +9,6 @@ const eventHandler = require("../../contracts/EventHandler.js"); const { isUuid } = require("../../../API/utils/uuid.js"); const messages = require("../../../messages.json"); const config = require("../../../config.json"); -const Logger = require("../../Logger.js"); const { readFileSync } = require("fs"); class StateHandler extends eventHandler { @@ -589,7 +588,7 @@ class StateHandler extends eventHandler { } if (this.isTooFast(message)) { - return Logger.warnMessage(message); + return console.warn(message); } if (this.isPlayerNotFound(message)) { diff --git a/src/minecraft/handlers/ErrorHandler.js b/src/minecraft/handlers/ErrorHandler.js index 7fdbc6d1..bf50eb50 100644 --- a/src/minecraft/handlers/ErrorHandler.js +++ b/src/minecraft/handlers/ErrorHandler.js @@ -19,10 +19,10 @@ class StateHandler extends eventHandler { if (this.isConnectionResetError(error)) return; if (this.isConnectionRefusedError(error)) { - return Logger.errorMessage("Connection refused while attempting to login via the Minecraft client"); + return console.error("Connection refused while attempting to login via the Minecraft client"); } - Logger.warnMessage(error); + console.warn(error); } isConnectionResetError(error) { diff --git a/src/minecraft/handlers/StateHandler.js b/src/minecraft/handlers/StateHandler.js index 53fcf2be..0773fe0f 100644 --- a/src/minecraft/handlers/StateHandler.js +++ b/src/minecraft/handlers/StateHandler.js @@ -1,5 +1,4 @@ const eventHandler = require("../../contracts/EventHandler.js"); -const Logger = require("../../Logger.js"); class StateHandler extends eventHandler { constructor(minecraft) { @@ -19,7 +18,7 @@ class StateHandler extends eventHandler { } onLogin() { - Logger.minecraftMessage("Client ready, logged in as " + this.bot.username); + console.minecraft("Client ready, logged in as " + this.bot.username); this.loginAttempts = 0; this.exactDelay = 0; @@ -31,13 +30,13 @@ class StateHandler extends eventHandler { } const loginDelay = this.exactDelay > 60000 ? 60000 : (this.loginAttempts + 1) * 50000; - Logger.warnMessage(`Minecraft bot has disconnected! Attempting reconnect in ${loginDelay / 1000} seconds`); + console.warn(`Minecraft bot has disconnected! Attempting reconnect in ${loginDelay / 1000} seconds`); setTimeout(() => this.minecraft.connect(), 2500); } onKicked(reason) { - Logger.warnMessage(`Minecraft bot has been kicked from the server for "${reason}"`); + console.warn(`Minecraft bot has been kicked from the server for "${reason}"`); this.loginAttempts++; } diff --git a/src/minecraft/other/eventNotifier.js b/src/minecraft/other/eventNotifier.js index 57d6d002..aa789892 100644 --- a/src/minecraft/other/eventNotifier.js +++ b/src/minecraft/other/eventNotifier.js @@ -48,7 +48,7 @@ if (config.minecraft.skyblockEventsNotifications.enabled) { } } } catch (e) { - console.log(e); + console.error(e); /* empty */ } }, 60000); diff --git a/src/minecraft/other/skyblockNotifier.js b/src/minecraft/other/skyblockNotifier.js index 283a1937..f8f24b51 100644 --- a/src/minecraft/other/skyblockNotifier.js +++ b/src/minecraft/other/skyblockNotifier.js @@ -50,7 +50,7 @@ async function checkForIncidents() { } } } catch (error) { - console.log(error); + console.error(error); } } @@ -91,7 +91,7 @@ async function checkForHypixelUpdates(firstTime = false) { } } } catch (error) { - console.log(error); + console.error(error); } } @@ -112,6 +112,6 @@ async function checkForSkyblockVersion() { skyblockVersion = data.version; } } catch (error) { - console.log(error); + console.error(error); } } diff --git a/src/web/WebsiteManager.js b/src/web/WebsiteManager.js index d5a359df..7f595d29 100644 --- a/src/web/WebsiteManager.js +++ b/src/web/WebsiteManager.js @@ -1,5 +1,4 @@ const config = require("../../config.json"); -const { webMessage } = require("../Logger.js"); const WebSocket = require("ws"); const http = require("http"); @@ -17,7 +16,7 @@ class WebServer { const wss = new WebSocket.Server({ noServer: true }); wss.on("connection", (ws) => { - webMessage("Client has connected to the server."); + console.web("Client has connected to the server."); ws.on("message", (message) => { message = JSON.parse(message); if (typeof message !== "object") { @@ -25,7 +24,7 @@ class WebServer { } if (message.type === "message" && message.token === config.web.token && message.data) { - webMessage(`Received: ${JSON.stringify(message)}`); + console.web(`Received: ${JSON.stringify(message)}`); bot.chat(message.data); } }); @@ -44,7 +43,7 @@ class WebServer { }); server.listen(this.port, () => { - webMessage(`WebSocket running at http://localhost:${this.port}/`); + console.web(`WebSocket running at http://localhost:${this.port}/`); }); server.on("request", (req, res) => {