From c32cf15b1b8db56ffce2a18d30a6db992f8628bd Mon Sep 17 00:00:00 2001 From: jejebecarte <69335633+jejebecarte@users.noreply.github.com> Date: Mon, 2 Dec 2024 15:22:56 +1100 Subject: [PATCH] Remove error channel (#228) * remove ERROR_CHANNEL_ID and associated config * update prettier/eslint config * add winston for logging * remove the capitalise-string util --- .env.template | 1 - package.json | 6 +- pnpm-lock.yaml | 185 ++++++++++++++++-- scripts/setup-files.js | 8 +- src/classes/bot.ts | 22 +-- src/commands/promote-demote.ts | 3 +- src/commands/reboot.ts | 4 +- src/commands/toggle-mute.ts | 3 +- src/events/discord/interaction-create.ts | 6 +- src/events/discord/message.ts | 6 +- src/events/mineflayer/chat/comment-blocked.ts | 4 +- src/events/mineflayer/chat/join-limbo.ts | 4 +- src/events/mineflayer/chat/member-kick.ts | 8 +- src/events/mineflayer/chat/promote-demote.ts | 6 +- src/events/mineflayer/handler/end.ts | 7 +- src/events/mineflayer/handler/error.ts | 7 +- src/events/mineflayer/handler/kicked.ts | 8 +- src/events/mineflayer/handler/message.ts | 6 +- src/events/regex.ts | 10 +- src/index.ts | 1 + src/util/capitalise-string.ts | 1 - src/util/emojis.ts | 31 --- src/util/env.ts | 5 +- src/util/log-error.ts | 14 -- src/util/logger.ts | 35 ++++ src/util/recursive-walk-dir.ts | 8 +- src/util/write-to-json-file.ts | 5 +- 27 files changed, 271 insertions(+), 133 deletions(-) delete mode 100644 src/util/capitalise-string.ts delete mode 100644 src/util/log-error.ts create mode 100644 src/util/logger.ts diff --git a/.env.template b/.env.template index 89aae17b..a859cf4d 100644 --- a/.env.template +++ b/.env.template @@ -29,6 +29,5 @@ DISCORD_SERVER_ID= MEMBER_CHANNEL_ID= OFFICER_CHANNEL_ID= BLACKLIST_CHANNEL_ID= -ERROR_CHANNEL_ID= BOT_OWNER_ID= STAFF_ROLE_ID= diff --git a/package.json b/package.json index e70ba564..f784d4ab 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "bridge-bot", + "name": "bridge", "version": "1.0.0", "main": "dist", "license": "MIT", @@ -16,16 +16,16 @@ "start": "node ." }, "dependencies": { - "consola": "^2.15.3", "discord.js": "14.10.2", "dotenv": "^16.4.5", "mineflayer": "^4.20.1", "obscenity": "^0.1.4", "prismarine-chat": "^1.10.1", + "winston": "^3.17.0", "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 71242faf..5e7425a1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: dependencies: - consola: - specifier: ^2.15.3 - version: 2.15.3 discord.js: specifier: 14.10.2 version: 14.10.2 @@ -26,13 +23,16 @@ importers: prismarine-chat: specifier: ^1.10.1 version: 1.10.1 + winston: + specifier: ^3.17.0 + version: 3.17.0 zod: specifier: ^3.23.8 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 @@ -68,10 +68,17 @@ packages: resolution: {integrity: sha512-rrfzIpG3Q1rHjVYZmHAEDidWAZZ2cgkxlIcMQ8dHebRISaZ2KCV33Q8Vs+uaV6lxweROabNxKFlR2lIKagZqYg==} engines: {node: '>=16'} + '@colors/colors@1.6.0': + resolution: {integrity: sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==} + engines: {node: '>=0.1.90'} + '@cspotcode/source-map-support@0.8.1': resolution: {integrity: sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==} engines: {node: '>=12'} + '@dabh/diagnostics@2.0.3': + resolution: {integrity: sha512-hrlQOIi7hAfzsMqlGSFyVucrx38O+j6wiGOf//H2ecvIEqYN4ADBSS2iLMh5UFyDunCNniUIPk/q3riFv45xRA==} + '@discordjs/builders@1.9.0': resolution: {integrity: sha512-0zx8DePNVvQibh5ly5kCEei5wtPBIUbSoE9n+91Rlladz4tgtFbJ36PZMxxZrTEOQ7AHMZ/b0crT/0fCy6FTKg==} engines: {node: '>=18'} @@ -139,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 @@ -238,6 +245,9 @@ packages: '@types/strip-json-comments@0.0.30': resolution: {integrity: sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==} + '@types/triple-beam@1.3.5': + resolution: {integrity: sha512-6WaYesThRMCl19iryMYP7/x2OVgCtbIVflDGFpWnb9irXI3UjYE4AzmYuiUKY1AJstGijoY+MgUszMgRxIYTYw==} + '@types/ws@8.5.12': resolution: {integrity: sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==} @@ -510,13 +520,28 @@ packages: resolution: {integrity: sha512-he+WTicka9cl0Fg/y+YyxcN6/bfQ/1O3QmgxRXDhABKqLzvoOSM4fMzp39uMyLBulAFuywD2N7UaoQE7WaADxQ==} engines: {node: '>=8.10.0'} + color-convert@1.9.3: + resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} + color-convert@2.0.1: resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} engines: {node: '>=7.0.0'} + color-name@1.1.3: + resolution: {integrity: sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==} + color-name@1.1.4: resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} + color-string@1.9.1: + resolution: {integrity: sha512-shrVawQFojnZv6xM40anx4CkoDP+fZsw/ZerEMsW/pyzsRbElpsL/DBVW7q3ExxwusdNXI3lXpuhEZkzs8p5Eg==} + + color@3.2.1: + resolution: {integrity: sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==} + + colorspace@1.1.4: + resolution: {integrity: sha512-BgvKJiuVu1igBUF2kEjRCZXol6wiiGbY5ipL/oVPwm0BL9sIpMIzM8IK7vwuxIIzOXMV3Ey5w+vxhm0rR/TN8w==} + combined-stream@1.0.8: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} @@ -537,9 +562,6 @@ packages: confusing-browser-globals@1.0.11: resolution: {integrity: sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==} - consola@2.15.3: - resolution: {integrity: sha512-9vAdYbHj6x2fLKC4+oPH0kFzY/orMZyG2Aj+kNylHxKGJ/Ed4dpNyAQYwJOdqO4zdM7XpVHmyejQDcQHrnuXbw==} - create-require@1.1.1: resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==} @@ -663,6 +685,9 @@ packages: emoji-regex@9.2.2: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} + enabled@2.0.0: + resolution: {integrity: sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ==} + endian-toggle@0.0.0: resolution: {integrity: sha512-ShfqhXeHRE4TmggSlHXG8CMGIcsOsqDw/GcoPcosToE59Rm9e4aXaMhEQf2kPBsBRrKem1bbOAv5gOKnkliMFQ==} @@ -890,6 +915,9 @@ packages: fclone@1.0.11: resolution: {integrity: sha512-GDqVQezKzRABdeqflsgMr7ktzgF9CyS+p2oe0jJqUY6izSSbhPIQJDpoU4PtGcD7VPM9xh/dVrTu6z1nwgmEGw==} + fecha@4.2.3: + resolution: {integrity: sha512-OP2IUU6HeYKJi3i0z4A19kHMQoLVs4Hc+DPqqxI2h/DPZHTm/vjsfC6P0b4jCMy14XizLBqvndQ+UilD7707Jw==} + file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -913,6 +941,9 @@ packages: flatted@3.3.1: resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} + fn.name@1.1.0: + resolution: {integrity: sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw==} + follow-redirects@1.15.9: resolution: {integrity: sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==} engines: {node: '>=4.0'} @@ -1086,6 +1117,9 @@ packages: resolution: {integrity: sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==} engines: {node: '>= 0.4'} + is-arrayish@0.3.2: + resolution: {integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==} + is-async-function@2.0.0: resolution: {integrity: sha512-Y1JXKrfykRJGdlDwdKlLpLyMIiWqWvuSd17TvZk68PLAOGOoF4Xyav1z0Xhoi+gCYjZVeC5SI+hYFOfvXmGRCA==} engines: {node: '>= 0.4'} @@ -1164,6 +1198,10 @@ packages: resolution: {integrity: sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==} engines: {node: '>= 0.4'} + is-stream@2.0.1: + resolution: {integrity: sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==} + engines: {node: '>=8'} + is-string@1.0.7: resolution: {integrity: sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==} engines: {node: '>= 0.4'} @@ -1253,6 +1291,9 @@ packages: keyv@4.5.4: resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==} + kuler@2.0.0: + resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==} + language-subtag-registry@0.3.23: resolution: {integrity: sha512-0K65Lea881pHotoGEa5gDlMxt3pctLi2RplBb7Ezh4rRdLEOtgi7n4EwK9lamnUCkKBqaeKRVebTq6BAxSkpXQ==} @@ -1308,6 +1349,10 @@ packages: lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + logform@2.7.0: + resolution: {integrity: sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==} + engines: {node: '>= 12.0.0'} + loose-envify@1.4.0: resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} hasBin: true @@ -1468,6 +1513,9 @@ packages: once@1.4.0: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} + one-time@1.0.0: + resolution: {integrity: sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g==} + optionator@0.9.4: resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==} engines: {node: '>= 0.8.0'} @@ -1750,6 +1798,10 @@ packages: resolution: {integrity: sha512-CdASjNJPvRa7roO6Ra/gLYBTzYzzPyyBXxIMdGW3USQLyjWEls2RgW5UBTXaQVp+OrpeCK3bLem8smtmheoRuw==} engines: {node: '>= 0.4'} + safe-stable-stringify@2.5.0: + resolution: {integrity: sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA==} + engines: {node: '>=10'} + safer-buffer@2.1.2: resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} @@ -1796,6 +1848,9 @@ packages: signal-exit@3.0.7: resolution: {integrity: sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==} + simple-swizzle@0.2.2: + resolution: {integrity: sha512-JA//kQgZtbuY83m+xT+tXJkmJncGMTFT+C+g2h2R9uxkYIrE2yy9sgmcLhCnw57/WSD+Eh3J97FPEDFnbXnDUg==} + slash@3.0.0: resolution: {integrity: sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==} engines: {node: '>=8'} @@ -1825,6 +1880,9 @@ packages: sprintf-js@1.1.3: resolution: {integrity: sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==} + stack-trace@0.0.10: + resolution: {integrity: sha512-KGzahc7puUKkzyMt+IqAep+TVNbKP+k2Lmwhub39m1AsTSkaDutx56aDCo+HLDzf/D26BIHTJWNiTG1KAJiQCg==} + stop-iteration-iterator@1.0.0: resolution: {integrity: sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==} engines: {node: '>= 0.4'} @@ -1887,6 +1945,9 @@ packages: os: [darwin, linux, win32, freebsd, openbsd, netbsd, sunos, android] hasBin: true + text-hex@1.0.0: + resolution: {integrity: sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg==} + text-table@0.2.0: resolution: {integrity: sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==} @@ -1905,6 +1966,10 @@ packages: resolution: {integrity: sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==} hasBin: true + triple-beam@1.4.1: + resolution: {integrity: sha512-aZbgViZrg1QNcG+LULa7nhZpJTZSLm/mXnHXnbAbjmN5aSa0y7V+wvv6+4WaBtpISJzThKy+PIPxc1Nq1EJ9mg==} + engines: {node: '>= 14.0.0'} + ts-mixer@6.0.4: resolution: {integrity: sha512-ufKpbmrugz5Aou4wcr5Wc1UUFWOLhq+Fm6qa6P0w0K5Qw2yhaUoiWszhCVuNQyNwrlGiscHOmqYoAox1PtvgjA==} @@ -2070,6 +2135,14 @@ packages: engines: {node: '>= 8'} hasBin: true + winston-transport@4.9.0: + resolution: {integrity: sha512-8drMJ4rkgaPo1Me4zD/3WLfI/zPdA9o2IipKODunnGDcuqbHwjsbB79ylv04LCGGzU0xQ6vTznOMpQGaLhhm6A==} + engines: {node: '>= 12.0.0'} + + winston@3.17.0: + resolution: {integrity: sha512-DLiFIXYC5fMPxaRg832S6F5mJYvePtmO5G9v9IgUFPhXm9/GkXarH/TUrBAVzhTCzAj9anE/+GjrgXp/54nOgw==} + engines: {node: '>= 12.0.0'} + word-wrap@1.2.5: resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==} engines: {node: '>=0.10.0'} @@ -2135,10 +2208,18 @@ snapshots: jsonwebtoken: 9.0.2 uuid: 8.3.2 + '@colors/colors@1.6.0': {} + '@cspotcode/source-map-support@0.8.1': dependencies: '@jridgewell/trace-mapping': 0.3.9 + '@dabh/diagnostics@2.0.3': + dependencies: + colorspace: 1.1.4 + enabled: 2.0.0 + kuler: 2.0.0 + '@discordjs/builders@1.9.0': dependencies: '@discordjs/formatters': 0.5.0 @@ -2226,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) @@ -2366,6 +2447,8 @@ snapshots: '@types/strip-json-comments@0.0.30': {} + '@types/triple-beam@1.3.5': {} + '@types/ws@8.5.12': dependencies: '@types/node': 22.5.5 @@ -2690,12 +2773,33 @@ snapshots: dependencies: chalk: 3.0.0 + color-convert@1.9.3: + dependencies: + color-name: 1.1.3 + color-convert@2.0.1: dependencies: color-name: 1.1.4 + color-name@1.1.3: {} + color-name@1.1.4: {} + color-string@1.9.1: + dependencies: + color-name: 1.1.4 + simple-swizzle: 0.2.2 + + color@3.2.1: + dependencies: + color-convert: 1.9.3 + color-string: 1.9.1 + + colorspace@1.1.4: + dependencies: + color: 3.2.1 + text-hex: 1.0.0 + combined-stream@1.0.8: dependencies: delayed-stream: 1.0.0 @@ -2710,8 +2814,6 @@ snapshots: confusing-browser-globals@1.0.11: {} - consola@2.15.3: {} - create-require@1.1.1: {} croner@4.1.97: {} @@ -2855,6 +2957,8 @@ snapshots: emoji-regex@9.2.2: {} + enabled@2.0.0: {} + endian-toggle@0.0.0: {} enquirer@2.3.6: @@ -3222,6 +3326,8 @@ snapshots: fclone@1.0.11: {} + fecha@4.2.3: {} + file-entry-cache@6.0.1: dependencies: flat-cache: 3.2.0 @@ -3249,6 +3355,8 @@ snapshots: flatted@3.3.1: {} + fn.name@1.1.0: {} + follow-redirects@1.15.9(debug@4.3.7): optionalDependencies: debug: 4.3.7 @@ -3436,6 +3544,8 @@ snapshots: call-bind: 1.0.7 get-intrinsic: 1.2.4 + is-arrayish@0.3.2: {} + is-async-function@2.0.0: dependencies: has-tostringtag: 1.0.2 @@ -3504,6 +3614,8 @@ snapshots: dependencies: call-bind: 1.0.7 + is-stream@2.0.1: {} + is-string@1.0.7: dependencies: has-tostringtag: 1.0.2 @@ -3612,6 +3724,8 @@ snapshots: dependencies: json-buffer: 3.0.1 + kuler@2.0.0: {} + language-subtag-registry@0.3.23: {} language-tags@1.0.9: @@ -3653,6 +3767,15 @@ snapshots: lodash@4.17.21: {} + logform@2.7.0: + dependencies: + '@colors/colors': 1.6.0 + '@types/triple-beam': 1.3.5 + fecha: 4.2.3 + ms: 2.1.3 + safe-stable-stringify: 2.5.0 + triple-beam: 1.4.1 + loose-envify@1.4.0: dependencies: js-tokens: 4.0.0 @@ -3839,6 +3962,10 @@ snapshots: dependencies: wrappy: 1.0.2 + one-time@1.0.0: + dependencies: + fn.name: 1.1.0 + optionator@0.9.4: dependencies: deep-is: 0.1.4 @@ -4239,6 +4366,8 @@ snapshots: es-errors: 1.3.0 is-regex: 1.1.4 + safe-stable-stringify@2.5.0: {} + safer-buffer@2.1.2: {} sax@1.4.1: {} @@ -4284,6 +4413,10 @@ snapshots: signal-exit@3.0.7: {} + simple-swizzle@0.2.2: + dependencies: + is-arrayish: 0.3.2 + slash@3.0.0: {} smart-buffer@4.2.0: {} @@ -4312,6 +4445,8 @@ snapshots: sprintf-js@1.1.3: {} + stack-trace@0.0.10: {} + stop-iteration-iterator@1.0.0: dependencies: internal-slot: 1.0.7 @@ -4388,6 +4523,8 @@ snapshots: systeminformation@5.23.5: optional: true + text-hex@1.0.0: {} + text-table@0.2.0: {} to-regex-range@5.0.1: @@ -4403,6 +4540,8 @@ snapshots: tree-kill@1.2.2: {} + triple-beam@1.4.1: {} + ts-mixer@6.0.4: {} ts-node-dev@2.0.0(@types/node@22.5.5)(typescript@4.9.5): @@ -4623,6 +4762,26 @@ snapshots: dependencies: isexe: 2.0.0 + winston-transport@4.9.0: + dependencies: + logform: 2.7.0 + readable-stream: 3.6.2 + triple-beam: 1.4.1 + + winston@3.17.0: + dependencies: + '@colors/colors': 1.6.0 + '@dabh/diagnostics': 2.0.3 + async: 3.2.6 + is-stream: 2.0.1 + logform: 2.7.0 + one-time: 1.0.0 + readable-stream: 3.6.2 + safe-stable-stringify: 2.5.0 + stack-trace: 0.0.10 + triple-beam: 1.4.1 + winston-transport: 4.9.0 + word-wrap@1.2.5: {} wrappy@1.0.2: {} diff --git a/scripts/setup-files.js b/scripts/setup-files.js index d63c88f8..ebc64910 100644 --- a/scripts/setup-files.js +++ b/scripts/setup-files.js @@ -1,11 +1,11 @@ -const logger = require('consola'); +/* eslint-disable no-console */ const fs = require('fs'); const oldPaths = ['.env.template', 'src/blacklist/_blacklist.json.template']; oldPaths.forEach((path) => { if (!fs.existsSync(path)) { - logger.warn( - `File '${path}' does not exist. If you have NOT run this command before, you may need to repair your installation.` + console.warn( + `'${path}' does not exist. If you have NOT run this command before, you may need to repair your installation.` ); return; @@ -13,7 +13,7 @@ oldPaths.forEach((path) => { const newPath = path.substring(0, path.indexOf('.template')); if (fs.existsSync(newPath)) { - logger.warn(`File '${newPath}' already exists.`); + console.warn(`'${newPath}' already exists.`); } else { fs.copyFileSync(path, newPath, fs.constants.COPYFILE_EXCL); } diff --git a/src/classes/bot.ts b/src/classes/bot.ts index 1e7d88b6..2cb823d7 100644 --- a/src/classes/bot.ts +++ b/src/classes/bot.ts @@ -6,11 +6,10 @@ import { TextChannel, } from 'discord.js'; import { BotEvents, createBot } from 'mineflayer'; -import logger from 'consola'; +import winston from 'winston'; import EventEmitter from 'events'; import path from 'path'; import isObjKey from '@util/is-obj-key'; -import logError from '@util/log-error'; import recursiveWalkDir from '@util/recursive-walk-dir'; import regex from '@events/regex'; import env from '@util/env'; @@ -46,7 +45,7 @@ class Bot { try { this.start(); } catch (error) { - logger.error(error); + winston.error(error); } } @@ -107,7 +106,7 @@ class Bot { if (this.limboTries < SPAM_THRESHOLD) { const triesBeforeSpam = SPAM_THRESHOLD - this.limboTries; - logger.info( + winston.info( `Sending to Limbo. Attempting disconnect.spam in ${triesBeforeSpam} ${ SPAM_THRESHOLD - this.limboTries === 1 ? 'try' : 'tries' }` @@ -116,7 +115,7 @@ class Bot { this.executeCommand('ยง'); this.limboTries++; } else if (this.limboTries === SPAM_THRESHOLD) { - logger.info('Attempting disconnect.spam'); + winston.info('Attempting disconnect.spam'); for (let i = 0; i < 11; i++) { this.executeCommand('/'); @@ -124,7 +123,7 @@ class Bot { this.limboTries++; } else if (this.limboTries === SPAM_THRESHOLD + 1) { - logger.warn('Limbo warp failed. Waiting for AFK kick'); + winston.warn('Limbo warp failed. Waiting for AFK kick'); this.limboTries++; } } @@ -149,12 +148,12 @@ class Bot { const command = (await import(path.join(currentDir, file))).default as Command; if (!command.data) { - logger.warn(`The command ${path.join(currentDir, file)} doesn't have a name!`); + winston.warn(`The command ${path.join(currentDir, file)} doesn't have a name!`); return; } if (!command.run) { - logger.warn( + winston.warn( `The command ${command.data.name} doesn't have an executable function!` ); return; @@ -178,12 +177,12 @@ class Bot { .default as Event; if (!name) { - logger.warn(`The event ${path.join(currentDir, file)} doesn't have a name!`); + winston.warn(`The event ${path.join(currentDir, file)} doesn't have a name!`); return; } if (!run) { - logger.warn(`The event ${name} doesn't have an executable function!`); + winston.warn(`The event ${name} doesn't have an executable function!`); return; } @@ -219,6 +218,7 @@ class Bot { } } -process.on('uncaughtException', logError).on('unhandledRejection', logError); +const handleError = (e: Error) => winston.error(e); +process.on('uncaughtException', handleError).on('unhandledRejection', handleError); export default Bot; diff --git a/src/commands/promote-demote.ts b/src/commands/promote-demote.ts index eba20e91..b325480d 100644 --- a/src/commands/promote-demote.ts +++ b/src/commands/promote-demote.ts @@ -1,5 +1,4 @@ import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; -import capitaliseString from '@util/capitalise-string'; export default { data: { @@ -39,7 +38,7 @@ export default { await bot.executeTask(`/g ${type} ${user}`); embed .setColor(type === 'promote' ? 'Green' : 'Red') - .setTitle(capitaliseString(`${type}d!`)) + .setTitle(type === 'promote' ? 'Promoted!' : 'Demoted!') .setDescription(`${user} has been ${type}d!`); } catch (e) { embed diff --git a/src/commands/reboot.ts b/src/commands/reboot.ts index b452e21e..652eea0d 100644 --- a/src/commands/reboot.ts +++ b/src/commands/reboot.ts @@ -1,4 +1,4 @@ -import logger from 'consola'; +import winston from 'winston'; import { EmbedBuilder } from 'discord.js'; export default { @@ -14,7 +14,7 @@ export default { .setDescription('Rebooting in 15 seconds...'); bot.sendGuildMessage('gc', 'Rebooting in 15 seconds...'); - logger.info( + winston.info( `Rebooting due to ${interaction.member?.user.username} running the reboot command.` ); diff --git a/src/commands/toggle-mute.ts b/src/commands/toggle-mute.ts index 3663eb35..d9e6b63e 100644 --- a/src/commands/toggle-mute.ts +++ b/src/commands/toggle-mute.ts @@ -1,5 +1,4 @@ import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; -import capitaliseString from '@util/capitalise-string'; export default { data: { @@ -49,7 +48,7 @@ export default { try { await bot.executeTask(`/g ${type} ${user} ${duration}`); embed - .setTitle(capitaliseString(`${type}d!`)) + .setTitle(type === 'mute' ? 'Muted!' : 'Unmuted!') .setDescription( `${user} was ${type}d${type === 'mute' ? ` for ${duration}!` : '!'}` ) diff --git a/src/events/discord/interaction-create.ts b/src/events/discord/interaction-create.ts index 639e8bf9..fe27fe87 100644 --- a/src/events/discord/interaction-create.ts +++ b/src/events/discord/interaction-create.ts @@ -1,5 +1,5 @@ -import logger from 'consola'; import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, Interaction } from 'discord.js'; +import winston from 'winston'; import env from '@util/env'; export default { @@ -11,7 +11,7 @@ export default { const command = bot.discord.commands.get(interaction.commandName); if (!command) { - logger.error(`Unknown slash command: ${interaction.commandName}`); + winston.error(`Unknown slash command: ${interaction.commandName}`); return; } @@ -49,7 +49,7 @@ export default { ephemeral: true, }); - logger.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/discord/message.ts b/src/events/discord/message.ts index 37b6e2e3..2b340700 100644 --- a/src/events/discord/message.ts +++ b/src/events/discord/message.ts @@ -1,6 +1,6 @@ -import logger from 'consola'; import { Message } from 'discord.js'; import { DataSet, RegExpMatcher, englishDataset, englishRecommendedTransformers } from 'obscenity'; +import winston from 'winston'; import emojis from '@util/emojis'; import env from '@util/env'; @@ -46,14 +46,14 @@ export default { await message.channel.send( `${emojis.warning} ${message.author.username}, could not delete message.` ); - logger.error(e); + winston.error(e); } if (profanityMatcher?.hasMatch(message.content)) { await message.channel.send( `${emojis.warning} ${message.author.username}, you may not use profane language!` ); - logger.warn(`Comment blocked: ${message.content}`); + winston.warn(`Comment blocked: ${message.content}`); bot.sendToDiscord( 'oc', `${emojis.warning} <@${message.author.id}> tried to say "${message.content}" but was blocked. This message was not sent to Hypixel.` diff --git a/src/events/mineflayer/chat/comment-blocked.ts b/src/events/mineflayer/chat/comment-blocked.ts index 8648ccda..2153010e 100644 --- a/src/events/mineflayer/chat/comment-blocked.ts +++ b/src/events/mineflayer/chat/comment-blocked.ts @@ -1,11 +1,11 @@ -import logger from 'consola'; +import winston from 'winston'; import Emojis from '@util/emojis'; export default { name: 'chat:commentBlocked', runOnce: false, run: async (bot, comment: string, reason: string) => { - logger.warn(`Comment blocked by Hypixel: ${comment} (${reason})`); + winston.warn(`Comment blocked by Hypixel: ${comment} (${reason})`); await bot.sendToDiscord( 'oc', `${Emojis.alert} "${comment}" was blocked by Hypixel because **${reason}**. Developers will not take responsibility for banned accounts.` diff --git a/src/events/mineflayer/chat/join-limbo.ts b/src/events/mineflayer/chat/join-limbo.ts index 6239ff15..067b2905 100644 --- a/src/events/mineflayer/chat/join-limbo.ts +++ b/src/events/mineflayer/chat/join-limbo.ts @@ -1,10 +1,10 @@ -import logger from 'consola'; +import winston from 'winston'; export default { name: 'chat:joinLimbo', runOnce: false, run: (bot) => { - logger.info('Bot has joined Limbo!'); + winston.info('Bot has joined Limbo!'); bot.limboTries = 0; }, } as Event; diff --git a/src/events/mineflayer/chat/member-kick.ts b/src/events/mineflayer/chat/member-kick.ts index 7d855f54..addb406a 100644 --- a/src/events/mineflayer/chat/member-kick.ts +++ b/src/events/mineflayer/chat/member-kick.ts @@ -8,15 +8,15 @@ export default { bot, rank: string | undefined, playerName: string, - kickedByRank: string | undefined, - kickedByPlayerName: string + kickerRank: string | undefined, + kickerName: string ) => { await bot.sendToDiscord( 'gc', `${Emojis.negativeGuildEvent} **${rank ? `${rank} ` : ''}${escapeMarkdown( playerName - )}** was kicked by **${kickedByRank ? `${kickedByRank} ` : ''}${escapeMarkdown( - kickedByPlayerName + )}** was kicked by **${kickerRank ? `${kickerRank} ` : ''}${escapeMarkdown( + kickerName )}**`, undefined, true diff --git a/src/events/mineflayer/chat/promote-demote.ts b/src/events/mineflayer/chat/promote-demote.ts index 637b7d80..7829b1f1 100644 --- a/src/events/mineflayer/chat/promote-demote.ts +++ b/src/events/mineflayer/chat/promote-demote.ts @@ -10,14 +10,14 @@ export default { rank: string | undefined, playerName: string, type: 'promoted' | 'demoted', - guildRankFrom: string, - guildRankTo: string + originalRank: string, + newRank: string ) => { await bot.sendToDiscord( 'gc', `${type === 'promoted' ? Emojis.positiveGuildEvent : Emojis.negativeGuildEvent} **${ rank ? `${rank} ` : '' - }${escapeMarkdown(playerName)}** was ${type} to ${guildRankTo} from ${guildRankFrom}!`, + }${escapeMarkdown(playerName)}** was ${type} to ${newRank} from ${originalRank}!`, getRankColor(rank), true ); diff --git a/src/events/mineflayer/handler/end.ts b/src/events/mineflayer/handler/end.ts index d216e2ed..587a4f5e 100644 --- a/src/events/mineflayer/handler/end.ts +++ b/src/events/mineflayer/handler/end.ts @@ -1,11 +1,10 @@ -import logger from 'consola'; +import winston from 'winston'; export default { name: 'end', runOnce: false, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - run: (bot) => { - logger.fatal('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 08fa0cc0..0e214969 100644 --- a/src/events/mineflayer/handler/error.ts +++ b/src/events/mineflayer/handler/error.ts @@ -1,11 +1,10 @@ -import logger from 'consola'; +import winston from 'winston'; export default { name: 'error', runOnce: false, - run: (bot, error: Error) => { - logger.fatal('Encountered an unexpected error. Restarting the bot in 15 seconds...'); - logger.fatal(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 e217d4e2..f7c99194 100644 --- a/src/events/mineflayer/handler/kicked.ts +++ b/src/events/mineflayer/handler/kicked.ts @@ -1,4 +1,4 @@ -import logger from 'consola'; +import winston from 'winston'; import Emojis from '@util/emojis'; export default { @@ -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...` ); - logger.error( - `The bot was kicked from the server. Restarting the bot in 15 seconds...\nReason: ${reason}\nLogged in: ${loggedIn}` + winston.error( + `The bot was kicked from the server. Exiting in 15 seconds...\nReason: ${reason}\nLogged in: ${loggedIn}` ); setTimeout(() => { diff --git a/src/events/mineflayer/handler/message.ts b/src/events/mineflayer/handler/message.ts index ff1aad7f..2c09a3c7 100644 --- a/src/events/mineflayer/handler/message.ts +++ b/src/events/mineflayer/handler/message.ts @@ -1,11 +1,11 @@ -import logger from 'consola'; +import winston from 'winston'; import { ChatMessage } from 'prismarine-chat'; export default { name: 'message', runOnce: false, - run: (bot, message: ChatMessage) => { + run: (_bot, message: ChatMessage) => { // Log color chat to console - logger.log(message.toAnsi()); + winston.info(message.toAnsi()); }, } as Event; diff --git a/src/events/regex.ts b/src/events/regex.ts index dcdbad2c..7819baca 100644 --- a/src/events/regex.ts +++ b/src/events/regex.ts @@ -35,7 +35,7 @@ export default { * Returns: * - Hypixel Rank * - Player Name - * - muted / unmuted + * - Type (muted / unmuted) * - Muter Hypixel Rank * - Muter Player Name * - Muter Player Name @@ -49,7 +49,7 @@ export default { * * Returns: * - Player Name - * - joined / left + * - Type (joined / left) */ 'chat:joinLeave': /^Guild > (\w{2,17}).*? (joined|left)\.$/, @@ -76,7 +76,7 @@ export default { * When "/g online" is typed, and the online and total member count is shown * * Returns: - * - Online / Total + * - Type (Online / Total) * - Member Count */ 'chat:memberCount': /^(Online|Total) Members: (\d+)$/, @@ -87,7 +87,7 @@ export default { * Returns: * - Hypixel Rank * - Player Name - * - joined / left + * - Type (joined / left) */ 'chat:memberJoinLeave': /^(\[.*])?\s*(\w{2,17}).*? (joined|left) the guild!$/, @@ -109,7 +109,7 @@ export default { * Returns: * - Hypixel Rank * - Player Name - * - promoted / demoted + * - Type (promoted / demoted) * - From Rank * - To Rank */ diff --git a/src/index.ts b/src/index.ts index 270f9ce3..a4adf560 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import '@util/logger'; import Bot from '@classes/bot'; export default new Bot(); diff --git a/src/util/capitalise-string.ts b/src/util/capitalise-string.ts deleted file mode 100644 index cb99705e..00000000 --- a/src/util/capitalise-string.ts +++ /dev/null @@ -1 +0,0 @@ -export default (str: string) => str.charAt(0).toUpperCase() + str.slice(1); diff --git a/src/util/emojis.ts b/src/util/emojis.ts index 87718e35..8f18c494 100644 --- a/src/util/emojis.ts +++ b/src/util/emojis.ts @@ -1,41 +1,10 @@ export default { - /** - * Join Emoji - */ join: '๐Ÿ“ฅ', - - /** - * Leave Emoji - */ leave: '๐Ÿ“ค', - - /** - * Success Emoji - */ success: 'โœ…', - - /** - * Error Emoji - */ error: 'โŒ', - - /** - * Warning Emoji - */ warning: 'โš ๏ธ', - - /** - * Alert Emoji - */ alert: '๐Ÿšจ', - - /** - * Positive Guild Event Emoji - */ positiveGuildEvent: '๐ŸŽ‰', - - /** - * Negative Guild Event Emoji - */ negativeGuildEvent: '๐Ÿ‘‹', }; diff --git a/src/util/env.ts b/src/util/env.ts index 0f1e1174..5989b01e 100644 --- a/src/util/env.ts +++ b/src/util/env.ts @@ -1,4 +1,4 @@ -import logger from 'consola'; +import winston from 'winston'; import { config } from 'dotenv'; import { z } from 'zod'; @@ -29,7 +29,6 @@ const envSchema = z MEMBER_CHANNEL_ID: SNOWFLAKE_SCHEMA, OFFICER_CHANNEL_ID: SNOWFLAKE_SCHEMA, BLACKLIST_CHANNEL_ID: SNOWFLAKE_SCHEMA, - ERROR_CHANNEL_ID: SNOWFLAKE_SCHEMA, BOT_OWNER_ID: SNOWFLAKE_SCHEMA, STAFF_ROLE_ID: SNOWFLAKE_SCHEMA, }) @@ -42,7 +41,7 @@ config(); const env = envSchema.safeParse(process.env); if (!env.success) { - logger.fatal('Invalid configuration:', env.error.formErrors.fieldErrors); + winston.error('Invalid configuration:', env.error.formErrors.fieldErrors); process.exit(1); } diff --git a/src/util/log-error.ts b/src/util/log-error.ts deleted file mode 100644 index 02d51ae2..00000000 --- a/src/util/log-error.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { TextChannel } from 'discord.js'; -import logger from 'consola'; -import env from '@util/env'; -import bot from '..'; - -export default async (err: Error, message?: string) => { - logger.error(err, message ? `\n\n${message}` : undefined); - - if (bot.discord.isReady()) { - ((await bot.discord.channels.fetch(env.ERROR_CHANNEL_ID)) as TextChannel).send( - err.stack ?? `${err.name}: ${err.message}` - ); - } -}; 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; + }) + ), + }), + ], +}); diff --git a/src/util/recursive-walk-dir.ts b/src/util/recursive-walk-dir.ts index e31c7282..1a2c9d66 100644 --- a/src/util/recursive-walk-dir.ts +++ b/src/util/recursive-walk-dir.ts @@ -1,6 +1,6 @@ -import logger from 'consola'; import fs from 'fs/promises'; import path from 'path'; +import winston from 'winston'; /** * @@ -27,11 +27,7 @@ async function recursiveWalkDir( try { await Promise.all(promises); } catch (e: unknown) { - logger.error(errMessage); - - if (e instanceof Error) { - logger.error(e); - } + winston.error(errMessage, e); } } diff --git a/src/util/write-to-json-file.ts b/src/util/write-to-json-file.ts index 73574393..93c8478b 100644 --- a/src/util/write-to-json-file.ts +++ b/src/util/write-to-json-file.ts @@ -1,6 +1,6 @@ import { CommandInteraction, EmbedBuilder } from 'discord.js'; import { writeFile } from 'fs'; -import logError from './log-error'; +import winston from 'winston'; /** * @param path The path to the target file. Path must begin from the path root. @@ -8,7 +8,6 @@ import logError from './log-error'; * @param interaction The interaction to reply to in case of failure. * @param successEmbed The embed to reply with if successful. */ - export default ( path: string, data: any, @@ -25,7 +24,7 @@ export default ( return; } - logError(err, 'Failed to write to file'); + winston.error('Failed to write to file:', err); const embed = new EmbedBuilder() .setColor('Red') .setTitle('Error')