Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change checkin args #45

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,4 @@ temp/

config.json
.idea/
.DS_Store
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
46 changes: 14 additions & 32 deletions src/commands/Checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ 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) {
const definition = new SlashCommandBuilder()
.setName('checkin')
.addBooleanOption(option =>
option
.setName('now')
.setName('public')
.setDescription('If true, send public embed of checking code for live events!')
.setRequired(false)
)
Expand All @@ -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'],
Expand All @@ -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;

Expand All @@ -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({
Expand All @@ -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, {
Expand All @@ -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) {
Expand Down
19 changes: 17 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
Loading