From ad632e4f54beebef62102bb94b77a9a255351e0c Mon Sep 17 00:00:00 2001 From: Stuart6557 Date: Mon, 23 Oct 2023 18:39:23 -0700 Subject: [PATCH] improved code quality --- .gitignore | 1 + package.json | 2 +- src/Client.ts | 16 ++++++++-------- src/commands/Checkin.ts | 14 ++++---------- src/config/config.ts | 16 ++++++++-------- yarn.lock | 19 +++++++++++++++++-- 6 files changed, 39 insertions(+), 29 deletions(-) diff --git a/.gitignore b/.gitignore index 3a8598b..3ac23eb 100644 --- a/.gitignore +++ b/.gitignore @@ -113,3 +113,4 @@ temp/ config.json .idea/ +.DS_Store \ No newline at end of file diff --git a/package.json b/package.json index 158fa20..7785f04 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "lint": "eslint src --ext .ts", "lint:fix": "eslint src --ext .ts --fix", "test": "echo \"Error: no test specified\" && exit 1", - "start:dev": "tsc && NODE_ENV=development node dist/src/index.js", + "dev": "tsc && NODE_ENV=development node dist/src/index.js", "start": "tsc && node dist/src/index.js" }, "repository": { diff --git a/src/Client.ts b/src/Client.ts index 2d4001d..6cc77b4 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,6 +1,5 @@ import { Collection, Client as DiscordClient } from 'discord.js'; import { Service } from 'typedi'; -import { GatewayIntentBits } from 'discord-api-types'; import Logger from './utils/Logger'; import { BotSettings, BotClient, BotInitializationError } from './types'; import Command from './Command'; @@ -46,13 +45,14 @@ export default class Client extends DiscordClient implements BotClient { super( configuration.clientOptions || { intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildIntegrations, - GatewayIntentBits.GuildWebhooks, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.DirectMessages, - GatewayIntentBits.GuildMessageReactions, - GatewayIntentBits.DirectMessageReactions, + 'GUILDS', + 'GUILD_INTEGRATIONS', + 'GUILD_WEBHOOKS', + 'GUILD_MESSAGES', + 'GUILD_MEMBERS', + 'DIRECT_MESSAGES', + 'GUILD_MESSAGE_REACTIONS', + 'DIRECT_MESSAGE_REACTIONS', ], } ); diff --git a/src/commands/Checkin.ts b/src/commands/Checkin.ts index ec51187..fb774d7 100644 --- a/src/commands/Checkin.ts +++ b/src/commands/Checkin.ts @@ -12,7 +12,7 @@ import QR from './QR'; /** * This Command DM's the caller the checkin code and Express Checkin link for any current and * upcoming events in today's timeframe. Optional argument `public` makes the embed with the - * checkin codes be returned in the same chat as the Command message instead of DMs. Optinoal + * checkin codes be returned in the same chat as the Command message instead of DMs. Optional * argument 'widescreen' allows users to choose if they want a QR code by itself (false) or * the widescreen slide QR (true). 'widescreen' is true by default. */ @@ -40,7 +40,7 @@ export default class Checkin extends Command { boardRequired: true, enabled: true, description: - "Sends a private message with all check-in codes from today's events. Calling with `public` argument sends public embed of checkin code.", + "Sends a private message with all check-in codes from today's events. Calling with `public` argument sends public embed of checkin code in the current channel instead of via DM.", category: 'Utility', usage: client.settings.prefix.concat('checkin [now]'), requiredPermissions: ['SEND_MESSAGES'], @@ -84,8 +84,7 @@ export default class Checkin extends Command { // Oh, boy, here come more dates and times to check. // Luxon makes it much nicer, however. // - // We need two sets of arrays for "checkin": - // - all events that have a start time within today's timeframe + // We need an array to store all events that have a start time within today's timeframe. const todayEvents = futureEvents.filter(event => { // get today's midnight const midnightToday = DateTime.now().set({ @@ -123,10 +122,7 @@ export default class Checkin extends Command { // If we just had `checkin` in our call, no arguments... if (!isPublic) { const author = await this.client.users.fetch(interaction.member!.user.id); - // What we need now is to construct the Payload to send for `checkin` with no arguments, - // as well as the Payload for when we have `checkin now`. - // - // Since this is private, we can list all of today's events. + // What we need now is to construct the Payload to send for `checkin`. const privateMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide); await author.send(privateMessage); await super.edit(interaction, { @@ -135,8 +131,6 @@ export default class Checkin extends Command { }); await interaction.followUp(`**/checkin** was used privately by ${interaction.user}!`); } else { - // This is public, so we only want to give events that are live RIGHT now (so no one can - // pre-emptively get checkin codes if they're left to be seen). const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide); await super.edit(interaction, publicMessage); } diff --git a/src/config/config.ts b/src/config/config.ts index 49ef5bc..7718fec 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -1,4 +1,3 @@ -import { GatewayIntentBits } from 'discord-api-types'; import { BotSettings } from '../types'; export default { @@ -10,13 +9,14 @@ export default { clientID: '', clientOptions: { intents: [ - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildIntegrations, - GatewayIntentBits.GuildWebhooks, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.DirectMessages, - GatewayIntentBits.GuildMessageReactions, - GatewayIntentBits.DirectMessageReactions, + 'GUILDS', + 'GUILD_INTEGRATIONS', + 'GUILD_WEBHOOKS', + 'GUILD_MESSAGES', + 'GUILD_MEMBERS', + 'DIRECT_MESSAGES', + 'GUILD_MESSAGE_REACTIONS', + 'DIRECT_MESSAGE_REACTIONS', ], }, portalAPI: { diff --git a/yarn.lock b/yarn.lock index c67dfcc..66e882a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1505,6 +1505,11 @@ has-flag@^3.0.0: resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz" integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0= +has-flag@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b" + integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ== + has-symbols@^1.0.1, has-symbols@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz" @@ -2142,6 +2147,11 @@ ms@^2.1.1: resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +nan@^2.14.0: + version "2.18.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.18.0.tgz#26a6faae7ffbeb293a39660e88a76b82e30b7554" + integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w== + nan@^2.17.0: version "2.17.0" resolved "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz" @@ -2234,9 +2244,9 @@ object-inspect@^1.11.0, object-inspect@^1.9.0: resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz" integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg== -object-keys@^1.1.1: +object-keys@^1.0.12, object-keys@^1.1.1: version "1.1.1" - resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz" + resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e" integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA== object.assign@^4.1.2: @@ -2388,6 +2398,11 @@ path-type@^3.0.0: dependencies: pify "^3.0.0" +path-type@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" + integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== + picocolors@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"