diff --git a/djs-bot/index.js b/djs-bot/index.js index 634f02b5e..3eabc0dcd 100644 --- a/djs-bot/index.js +++ b/djs-bot/index.js @@ -12,15 +12,14 @@ const colors = require("colors"); const getConfig = require("./util/getConfig"); const { ShardingManager } = require('discord.js'); +const { getCurrentTimeString } = require("./util/dates"); try { // Gets the config file and passes it (as if returned) to the function in `.then( () => {} )` getConfig().then((conf) => { const manager = new ShardingManager('./bot.js', { token: conf.token, respawn: true, totalShards: "auto", timeout: -1 }); manager.on('shardCreate', shard => { - let d = new Date(); - let time = `[${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}]`; - console.log(colors.gray(time) + colors.cyan(" | " + `Spawned shard ${shard.id}`)); + console.log(colors.gray(getCurrentTimeString()) + colors.cyan(`${' '.repeat(9)}| Spawned shard ${shard.id}`)); }); manager.spawn({ amount: "auto", delay: 5500, timeout: -1 }).catch((err) => { console.log(colors.red("\tError spawning shards: " + err)); diff --git a/djs-bot/lib/Bot.js b/djs-bot/lib/Bot.js index 702bb7481..5533d5864 100644 --- a/djs-bot/lib/Bot.js +++ b/djs-bot/lib/Bot.js @@ -112,7 +112,7 @@ class Bot extends Client { this.LoadSchedules(); this.LoadEvents(); - this.warn("Booting up the bot...\n\t" + this.denom); + this.warn("Booting up the bot...\n" + ' '.repeat(31) + this.denom); LoadErrorHandler(this); LoadDebugListeners(this); diff --git a/djs-bot/lib/Logger.js b/djs-bot/lib/Logger.js index 14178097a..5f4cc6461 100644 --- a/djs-bot/lib/Logger.js +++ b/djs-bot/lib/Logger.js @@ -1,5 +1,6 @@ const winston = require("winston"); const colors = require("colors"); +const { getCurrentTimeString } = require("../util/dates"); const map = { log: { level: "debug", message: "info: ", color: "green" }, @@ -22,20 +23,12 @@ class Logger { }); } - /** - * @returns String formatted date for logging - */ - getCurrentTimeString() { - let d = new Date(); - return `[${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}]`; - } - /** * @param {Formatting} formatting * @param {...any} args */ printLog(formatting, ...args) { - const time = this.getCurrentTimeString(); + const time = getCurrentTimeString(); this.logger.log({ time: `${time}`, @@ -45,7 +38,8 @@ class Logger { if (formatting.color) { console.log( - colors.gray(time) + colors[formatting.color || "green"](` [${formatting.level.toUpperCase()}] | `) + args.join(" ") + colors.gray(time) + + colors[formatting.color || "green"](` [${formatting.level.toUpperCase().padEnd(5, ' ')}] | `) + args.join(" ") ); } } diff --git a/djs-bot/util/dates.js b/djs-bot/util/dates.js index fa97b24c6..f3c486b89 100644 --- a/djs-bot/util/dates.js +++ b/djs-bot/util/dates.js @@ -43,7 +43,32 @@ function thisWeek(begOffset = { days: 0 }, endOffset = { days: 0 }) { return dateSpan("week", "week", begOffset, endOffset); } +/** + * Returns formatted time string + * + * @example [10.01.2024 - 21:14] + */ +function getCurrentTimeString() { + const date = new Date(); + + const formatNumber = (num) => num.toLocaleString('en-US', { + minimumIntegerDigits: 2, + useGrouping: false + }); + + const formattedDate = { + date: formatNumber(date.getDate()), + month: formatNumber(date.getMonth() + 1), + year: date.getFullYear(), + hours: formatNumber(date.getHours()), + minutes: formatNumber(date.getMinutes()), + } + + return `[${formattedDate.date}.${formattedDate.month}.${formattedDate.year} - ${formattedDate.hours}:${formattedDate.minutes}]`; +} + module.exports = { thisWeek, dateSpan, -}; \ No newline at end of file + getCurrentTimeString, +};