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/commands/Checkin.ts b/src/commands/Checkin.ts index e9b3635..fb774d7 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. 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. */ 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 in the current channel instead of via DM.", 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<void> { // 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; @@ -83,12 +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 - // - 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. + // 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({ @@ -112,33 +108,21 @@ 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... 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, { @@ -147,9 +131,7 @@ 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(liveEvents, isPublic, needsSlide); + const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide); await super.edit(interaction, publicMessage); } } catch (e) { 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"