From 24bb7b9a2ac2ef1d4f5d84f65d78f63183f31255 Mon Sep 17 00:00:00 2001 From: jejebecarte <69335633+jejebecarte@users.noreply.github.com> Date: Sun, 1 Dec 2024 15:03:16 +1100 Subject: [PATCH] chore(deps): update eslint/prettier config --- package.json | 2 +- pnpm-lock.yaml | 10 +++---- scripts/setup-files.js | 1 + src/events/discord/interaction-create.ts | 2 +- src/events/mineflayer/handler/end.ts | 5 ++-- src/events/mineflayer/handler/error.ts | 5 ++-- src/events/mineflayer/handler/kicked.ts | 4 +-- src/index.ts | 38 ++---------------------- src/util/logger.ts | 35 ++++++++++++++++++++++ 9 files changed, 51 insertions(+), 51 deletions(-) create mode 100644 src/util/logger.ts diff --git a/package.json b/package.json index efa657af..f784d4ab 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "zod": "^3.23.8" }, "devDependencies": { - "@jejebecarte/eslint-config": "^1.0.6", + "@jejebecarte/eslint-config": "^1.0.7", "@types/node-fetch": "^2.6.11", "eslint": "^8.57.1", "pm2": "^5.4.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ed7a128..5e7425a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -31,8 +31,8 @@ importers: version: 3.23.8 devDependencies: '@jejebecarte/eslint-config': - specifier: ^1.0.6 - version: 1.0.6(eslint@8.57.1)(prettier@2.8.8)(typescript@4.9.5) + specifier: ^1.0.7 + version: 1.0.7(eslint@8.57.1)(prettier@2.8.8)(typescript@4.9.5) '@types/node-fetch': specifier: ^2.6.11 version: 2.6.11 @@ -146,8 +146,8 @@ packages: resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} deprecated: Use @eslint/object-schema instead - '@jejebecarte/eslint-config@1.0.6': - resolution: {integrity: sha512-GhPWxJBu6D6KuzXVu68hS5dAkjep9uG88ckhCMBXQLjIWAkEZH4dUfkPvEyzedWdjH7s7eLuxcZEpF3dEfKrfQ==} + '@jejebecarte/eslint-config@1.0.7': + resolution: {integrity: sha512-NhdK52lAFYn1nfAi55MlM8THZf6ZggeAqjJGoLuQTPHklPUFYhgg2PxxODPYl3xCONs8wpSBzkEgut7O8Uq0LQ==} peerDependencies: eslint: ^8.38.0 prettier: ^2.8.7 @@ -2307,7 +2307,7 @@ snapshots: '@humanwhocodes/object-schema@2.0.3': {} - '@jejebecarte/eslint-config@1.0.6(eslint@8.57.1)(prettier@2.8.8)(typescript@4.9.5)': + '@jejebecarte/eslint-config@1.0.7(eslint@8.57.1)(prettier@2.8.8)(typescript@4.9.5)': dependencies: '@typescript-eslint/eslint-plugin': 5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.57.1)(typescript@4.9.5))(eslint@8.57.1)(typescript@4.9.5) '@typescript-eslint/parser': 5.62.0(eslint@8.57.1)(typescript@4.9.5) diff --git a/scripts/setup-files.js b/scripts/setup-files.js index 4e1aba02..ebc64910 100644 --- a/scripts/setup-files.js +++ b/scripts/setup-files.js @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ const fs = require('fs'); const oldPaths = ['.env.template', 'src/blacklist/_blacklist.json.template']; diff --git a/src/events/discord/interaction-create.ts b/src/events/discord/interaction-create.ts index c3e92fcc..fe27fe87 100644 --- a/src/events/discord/interaction-create.ts +++ b/src/events/discord/interaction-create.ts @@ -49,7 +49,7 @@ export default { ephemeral: true, }); - winston.error(`An error occured in ${interaction.commandName}: ${(e as Error).message}`); + winston.error(`An error occured in ${interaction.commandName}:`, e); } }, } as Event; diff --git a/src/events/mineflayer/handler/end.ts b/src/events/mineflayer/handler/end.ts index 4d9993ed..587a4f5e 100644 --- a/src/events/mineflayer/handler/end.ts +++ b/src/events/mineflayer/handler/end.ts @@ -3,9 +3,8 @@ import winston from 'winston'; export default { name: 'end', runOnce: false, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - run: (bot) => { - winston.error('The bot session has abruptly ended. Restarting the bot in 15 seconds...'); + run: (_bot) => { + winston.error('The bot session has abruptly ended. Exiting in 15 seconds...'); setTimeout(() => { process.exit(1); diff --git a/src/events/mineflayer/handler/error.ts b/src/events/mineflayer/handler/error.ts index 2e14ac33..0e214969 100644 --- a/src/events/mineflayer/handler/error.ts +++ b/src/events/mineflayer/handler/error.ts @@ -3,9 +3,8 @@ import winston from 'winston'; export default { name: 'error', runOnce: false, - run: (bot, error: Error) => { - winston.error('Encountered an unexpected error. Restarting the bot in 15 seconds...'); - winston.error(error); + run: (_bot, error: Error) => { + winston.error('Encountered an unexpected error. Exiting in 15 seconds...', error); setTimeout(() => { process.exit(1); diff --git a/src/events/mineflayer/handler/kicked.ts b/src/events/mineflayer/handler/kicked.ts index e56d13cc..f7c99194 100644 --- a/src/events/mineflayer/handler/kicked.ts +++ b/src/events/mineflayer/handler/kicked.ts @@ -40,11 +40,11 @@ export default { await bot.sendToDiscord( 'gc', - `${Emojis.error} The bot was kicked from the server due to ${message}. Restarting the bot in 15 seconds...` + `${Emojis.error} The bot was kicked from the server due to ${message}. Exiting in 15 seconds...` ); winston.error( - `The bot was kicked from the server. Restarting the bot in 15 seconds...\nReason: ${reason}\nLogged in: ${loggedIn}` + `The bot was kicked from the server. Exiting in 15 seconds...\nReason: ${reason}\nLogged in: ${loggedIn}` ); setTimeout(() => { diff --git a/src/index.ts b/src/index.ts index 0b9e3198..a4adf560 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,38 +1,4 @@ -import winston, { format } from 'winston'; - -//* Uppercasing must be done before colorizing - https://github.com/winstonjs/winston/issues/1345 -const upperCaseLogLevel = format((info) => { - info.level = info.level?.toUpperCase(); - return info; -}); - -winston.configure({ - level: 'info', - format: format.combine(format.timestamp(), format.errors({ stack: true })), - transports: [ - new winston.transports.File({ - filename: 'logs/error.log', - level: 'error', - maxFiles: 10, - maxsize: 10_000_000, // 10MB - format: format.prettyPrint(), - }), - new winston.transports.Console({ - format: format.combine( - upperCaseLogLevel(), - format.colorize(), - format.align(), - format.printf((info) => { - const message = `[${info.level}] ${info.message}`; - - return info.stack - ? message + `\n\t${(info.stack as string).replaceAll('\n', '\n\t')}` - : message; - }) - ), - }), - ], -}); - +import '@util/logger'; import Bot from '@classes/bot'; + export default new Bot(); diff --git a/src/util/logger.ts b/src/util/logger.ts new file mode 100644 index 00000000..55343054 --- /dev/null +++ b/src/util/logger.ts @@ -0,0 +1,35 @@ +import winston, { format } from 'winston'; + +//* Uppercasing must be done before colorizing - https://github.com/winstonjs/winston/issues/1345 +const upperCaseLogLevel = format((info) => { + info.level = info.level?.toUpperCase(); + return info; +}); + +winston.configure({ + level: 'info', + format: format.combine(format.timestamp(), format.errors({ stack: true })), + transports: [ + new winston.transports.File({ + filename: 'logs/error.log', + level: 'error', + maxFiles: 10, + maxsize: 10_000_000, // 10MB + format: format.prettyPrint(), + }), + new winston.transports.Console({ + format: format.combine( + upperCaseLogLevel(), + format.colorize(), + format.align(), + format.printf((info) => { + const message = `[${info.level}] ${info.message}`; + + return info.stack + ? `${message}\n\t${(info.stack as string).replaceAll('\n', '\n\t')}` + : message; + }) + ), + }), + ], +});