From 3d5f7a6d3801b8fd518630ae503a8592aee5d190 Mon Sep 17 00:00:00 2001 From: Stuart6557 Date: Sat, 14 Oct 2023 12:24:00 -0700 Subject: [PATCH 1/4] changed checkin command parameters --- src/Client.ts | 16 ++++++++-------- src/commands/Checkin.ts | 36 ++++++++++++------------------------ src/config/config.ts | 16 ++++++++-------- src/types/.DS_Store | Bin 0 -> 6148 bytes 4 files changed, 28 insertions(+), 40 deletions(-) create mode 100644 src/types/.DS_Store diff --git a/src/Client.ts b/src/Client.ts index 6cc77b4..3962c9b 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -6,6 +6,7 @@ import Command from './Command'; import ActionManager from './managers/ActionManager'; import configuration from './config/config'; import PortalAPIManager from './managers/PortalAPIManager'; +import { GatewayIntentBits } from 'discord-api-types'; /** * The class representing the Discord bot. @@ -45,14 +46,13 @@ export default class Client extends DiscordClient implements BotClient { super( configuration.clientOptions || { intents: [ - 'GUILDS', - 'GUILD_INTEGRATIONS', - 'GUILD_WEBHOOKS', - 'GUILD_MESSAGES', - 'GUILD_MEMBERS', - 'DIRECT_MESSAGES', - 'GUILD_MESSAGE_REACTIONS', - 'DIRECT_MESSAGE_REACTIONS', + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildIntegrations, + GatewayIntentBits.GuildWebhooks, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.GuildMessageReactions, + GatewayIntentBits.DirectMessageReactions, ], } ); diff --git a/src/commands/Checkin.ts b/src/commands/Checkin.ts index e9b3635..ec51187 100644 --- a/src/commands/Checkin.ts +++ b/src/commands/Checkin.ts @@ -10,11 +10,11 @@ import Logger from '../utils/Logger'; import QR from './QR'; /** - * This Command DM's the caller the checkin code and Express Checkin link for any events - * in today's timeframe. Optional argument `now` makes the embed with the checkin codes - * be returned in the same chat as the Command message, but only for currently running events. - * Argument 'widescreen' allows users to choose if they want a QR code by itself (false) or - * the widescreen slide QR (true). + * 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 + * 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. */ export default class Checkin extends Command { constructor(client: BotClient) { @@ -22,7 +22,7 @@ export default class Checkin extends Command { .setName('checkin') .addBooleanOption(option => option - .setName('now') + .setName('public') .setDescription('If true, send public embed of checking code for live events!') .setRequired(false) ) @@ -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 `now` argument sends public embed of checkin code if any events are now live!", + "Sends a private message with all check-in codes from today's events. Calling with `public` argument sends public embed of checkin code.", category: 'Utility', usage: client.settings.prefix.concat('checkin [now]'), requiredPermissions: ['SEND_MESSAGES'], @@ -66,10 +66,11 @@ export default class Checkin extends Command { */ public async run(interaction: CommandInteraction): Promise { // Get arguments. Get rid of the null types by checking them. - const nowArgument = interaction.options.getBoolean('now'); + const publicArgument = interaction.options.getBoolean('public'); const widescreenArgument = interaction.options.getBoolean('widescreen'); - const isPublic = nowArgument !== null ? nowArgument : false; + // By default, we want the QR code to be DMed to the user. + const isPublic = publicArgument !== null ? publicArgument : false; // By default, we want to include the slide. const needsSlide = widescreenArgument !== null ? widescreenArgument : true; @@ -85,10 +86,6 @@ export default class Checkin extends Command { // // We need two sets of arrays for "checkin": // - all events that have a start time within today's timeframe - // - all events that are live RIGHT NOW - // - // The first set is useful for us to prepare a checkin code beforehand, while the second set - // enables the functionality for `checkin now`. We'll start with the first set. const todayEvents = futureEvents.filter(event => { // get today's midnight const midnightToday = DateTime.now().set({ @@ -112,24 +109,15 @@ export default class Checkin extends Command { return Interval.fromDateTimes(midnightToday, midnightTomorrow).contains(event.start); }); - // Check if current time in between event - const liveEvents = futureEvents.filter(event => - Interval.fromDateTimes(event.start, event.end).contains(DateTime.now()) - ); - // We'll make sure to check if the required set of events by // command arugments is empty; if it is, just return "No events today!" - if (!isPublic && todayEvents.length === 0) { + if (todayEvents.length === 0) { await super.edit(interaction, { content: 'No events today!', ephemeral: true, }); return; } - if (isPublic && liveEvents.length === 0) { - await super.edit(interaction, 'No events right now!'); - return; - } // Now we finally check the command argument. // If we just had `checkin` in our call, no arguments... @@ -149,7 +137,7 @@ export default class Checkin extends Command { } 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(liveEvents, isPublic, needsSlide); + const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide); await super.edit(interaction, publicMessage); } } catch (e) { diff --git a/src/config/config.ts b/src/config/config.ts index 7718fec..49ef5bc 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -1,3 +1,4 @@ +import { GatewayIntentBits } from 'discord-api-types'; import { BotSettings } from '../types'; export default { @@ -9,14 +10,13 @@ export default { clientID: '', clientOptions: { intents: [ - 'GUILDS', - 'GUILD_INTEGRATIONS', - 'GUILD_WEBHOOKS', - 'GUILD_MESSAGES', - 'GUILD_MEMBERS', - 'DIRECT_MESSAGES', - 'GUILD_MESSAGE_REACTIONS', - 'DIRECT_MESSAGE_REACTIONS', + GatewayIntentBits.Guilds, + GatewayIntentBits.GuildIntegrations, + GatewayIntentBits.GuildWebhooks, + GatewayIntentBits.GuildMessages, + GatewayIntentBits.DirectMessages, + GatewayIntentBits.GuildMessageReactions, + GatewayIntentBits.DirectMessageReactions, ], }, portalAPI: { diff --git a/src/types/.DS_Store b/src/types/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5cd873484e7f183457ee83f7a81c5ae6648e98b0 GIT binary patch literal 6148 zcmeHK%}T>S5Z<-bBorYBg&r5Y7HqXt#7l_v1&ruHr6#0kFlI}WnnNk%tS{t~_&m<+ zZop#BB6bFLzxmzGevtiPjB$Sv4;XV9V>UEIj!J`|yD_w7k`XzMkq^Qrs`W6sPNwC= z-8+|A5hmGmt_qTP3MqFtNfyh}my0aURc)XHj$=C$x4T>phohbtoD5byu{=HM_r&mc zv|2g#{=wnd<>Wbi$>f`+lLOmIb`93>4vJaLYcS7JnLUE1&aSfvi2-7O7$62Vn*nn! z*qzO$fmTlp5CaVi;Qk<>A$kTYjcV(F4zJG`ZzH0Bj&BJ>VbC*JX@m#}*QJ2El$$38 z*X7_BCeJfiY1HM6tC?XOGjsiT;c9m93zg2er;&PMfEZY3pruV0&;JYfWf~v(>m_6n z1H`~TV}Q5E!PtjInX~oB^6;z`&>o8hZP3)CUcGgxWFQP8i- Q0qG*32%(M`_yq>O0FM?)egFUf literal 0 HcmV?d00001 From 30a4b4fdbbc1ad7f347b25c649b2f8bfe97721a1 Mon Sep 17 00:00:00 2001 From: Stuart6557 Date: Sat, 14 Oct 2023 12:25:20 -0700 Subject: [PATCH 2/4] linting --- src/Client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Client.ts b/src/Client.ts index 3962c9b..2d4001d 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -1,12 +1,12 @@ 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'; import ActionManager from './managers/ActionManager'; import configuration from './config/config'; import PortalAPIManager from './managers/PortalAPIManager'; -import { GatewayIntentBits } from 'discord-api-types'; /** * The class representing the Discord bot. From d36b4749857421cdcbb7b2d912ebc8fd7ca94a91 Mon Sep 17 00:00:00 2001 From: Vivian Liu <85718304+Stuart6557@users.noreply.github.com> Date: Mon, 16 Oct 2023 18:18:30 -0700 Subject: [PATCH 3/4] Delete src/types/.DS_Store --- src/types/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/types/.DS_Store diff --git a/src/types/.DS_Store b/src/types/.DS_Store deleted file mode 100644 index 5cd873484e7f183457ee83f7a81c5ae6648e98b0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5Z<-bBorYBg&r5Y7HqXt#7l_v1&ruHr6#0kFlI}WnnNk%tS{t~_&m<+ zZop#BB6bFLzxmzGevtiPjB$Sv4;XV9V>UEIj!J`|yD_w7k`XzMkq^Qrs`W6sPNwC= z-8+|A5hmGmt_qTP3MqFtNfyh}my0aURc)XHj$=C$x4T>phohbtoD5byu{=HM_r&mc zv|2g#{=wnd<>Wbi$>f`+lLOmIb`93>4vJaLYcS7JnLUE1&aSfvi2-7O7$62Vn*nn! z*qzO$fmTlp5CaVi;Qk<>A$kTYjcV(F4zJG`ZzH0Bj&BJ>VbC*JX@m#}*QJ2El$$38 z*X7_BCeJfiY1HM6tC?XOGjsiT;c9m93zg2er;&PMfEZY3pruV0&;JYfWf~v(>m_6n z1H`~TV}Q5E!PtjInX~oB^6;z`&>o8hZP3)CUcGgxWFQP8i- Q0qG*32%(M`_yq>O0FM?)egFUf From ad632e4f54beebef62102bb94b77a9a255351e0c Mon Sep 17 00:00:00 2001 From: Stuart6557 Date: Mon, 23 Oct 2023 18:39:23 -0700 Subject: [PATCH 4/4] 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"