Skip to content

Commit d828692

Browse files
authored
Change checkin args (#45)
* changed checkin command parameters * linting * Delete src/types/.DS_Store * improved code quality
1 parent 9203581 commit d828692

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,4 @@ temp/
113113

114114
config.json
115115
.idea/
116+
.DS_Store

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"lint": "eslint src --ext .ts",
99
"lint:fix": "eslint src --ext .ts --fix",
1010
"test": "echo \"Error: no test specified\" && exit 1",
11-
"start:dev": "tsc && NODE_ENV=development node dist/src/index.js",
11+
"dev": "tsc && NODE_ENV=development node dist/src/index.js",
1212
"start": "tsc && node dist/src/index.js"
1313
},
1414
"repository": {

src/commands/Checkin.ts

+14-32
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ import Logger from '../utils/Logger';
1010
import QR from './QR';
1111

1212
/**
13-
* This Command DM's the caller the checkin code and Express Checkin link for any events
14-
* in today's timeframe. Optional argument `now` makes the embed with the checkin codes
15-
* be returned in the same chat as the Command message, but only for currently running events.
16-
* Argument 'widescreen' allows users to choose if they want a QR code by itself (false) or
17-
* the widescreen slide QR (true).
13+
* This Command DM's the caller the checkin code and Express Checkin link for any current and
14+
* upcoming events in today's timeframe. Optional argument `public` makes the embed with the
15+
* checkin codes be returned in the same chat as the Command message instead of DMs. Optional
16+
* argument 'widescreen' allows users to choose if they want a QR code by itself (false) or
17+
* the widescreen slide QR (true). 'widescreen' is true by default.
1818
*/
1919
export default class Checkin extends Command {
2020
constructor(client: BotClient) {
2121
const definition = new SlashCommandBuilder()
2222
.setName('checkin')
2323
.addBooleanOption(option =>
2424
option
25-
.setName('now')
25+
.setName('public')
2626
.setDescription('If true, send public embed of checking code for live events!')
2727
.setRequired(false)
2828
)
@@ -40,7 +40,7 @@ export default class Checkin extends Command {
4040
boardRequired: true,
4141
enabled: true,
4242
description:
43-
"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!",
43+
"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.",
4444
category: 'Utility',
4545
usage: client.settings.prefix.concat('checkin [now]'),
4646
requiredPermissions: ['SEND_MESSAGES'],
@@ -66,10 +66,11 @@ export default class Checkin extends Command {
6666
*/
6767
public async run(interaction: CommandInteraction): Promise<void> {
6868
// Get arguments. Get rid of the null types by checking them.
69-
const nowArgument = interaction.options.getBoolean('now');
69+
const publicArgument = interaction.options.getBoolean('public');
7070
const widescreenArgument = interaction.options.getBoolean('widescreen');
7171

72-
const isPublic = nowArgument !== null ? nowArgument : false;
72+
// By default, we want the QR code to be DMed to the user.
73+
const isPublic = publicArgument !== null ? publicArgument : false;
7374
// By default, we want to include the slide.
7475
const needsSlide = widescreenArgument !== null ? widescreenArgument : true;
7576

@@ -83,12 +84,7 @@ export default class Checkin extends Command {
8384
// Oh, boy, here come more dates and times to check.
8485
// Luxon makes it much nicer, however.
8586
//
86-
// We need two sets of arrays for "checkin":
87-
// - all events that have a start time within today's timeframe
88-
// - all events that are live RIGHT NOW
89-
//
90-
// The first set is useful for us to prepare a checkin code beforehand, while the second set
91-
// enables the functionality for `checkin now`. We'll start with the first set.
87+
// We need an array to store all events that have a start time within today's timeframe.
9288
const todayEvents = futureEvents.filter(event => {
9389
// get today's midnight
9490
const midnightToday = DateTime.now().set({
@@ -112,33 +108,21 @@ export default class Checkin extends Command {
112108
return Interval.fromDateTimes(midnightToday, midnightTomorrow).contains(event.start);
113109
});
114110

115-
// Check if current time in between event
116-
const liveEvents = futureEvents.filter(event =>
117-
Interval.fromDateTimes(event.start, event.end).contains(DateTime.now())
118-
);
119-
120111
// We'll make sure to check if the required set of events by
121112
// command arugments is empty; if it is, just return "No events today!"
122-
if (!isPublic && todayEvents.length === 0) {
113+
if (todayEvents.length === 0) {
123114
await super.edit(interaction, {
124115
content: 'No events today!',
125116
ephemeral: true,
126117
});
127118
return;
128119
}
129-
if (isPublic && liveEvents.length === 0) {
130-
await super.edit(interaction, 'No events right now!');
131-
return;
132-
}
133120

134121
// Now we finally check the command argument.
135122
// If we just had `checkin` in our call, no arguments...
136123
if (!isPublic) {
137124
const author = await this.client.users.fetch(interaction.member!.user.id);
138-
// What we need now is to construct the Payload to send for `checkin` with no arguments,
139-
// as well as the Payload for when we have `checkin now`.
140-
//
141-
// Since this is private, we can list all of today's events.
125+
// What we need now is to construct the Payload to send for `checkin`.
142126
const privateMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide);
143127
await author.send(privateMessage);
144128
await super.edit(interaction, {
@@ -147,9 +131,7 @@ export default class Checkin extends Command {
147131
});
148132
await interaction.followUp(`**/checkin** was used privately by ${interaction.user}!`);
149133
} else {
150-
// This is public, so we only want to give events that are live RIGHT now (so no one can
151-
// pre-emptively get checkin codes if they're left to be seen).
152-
const publicMessage = await Checkin.getCheckinMessage(liveEvents, isPublic, needsSlide);
134+
const publicMessage = await Checkin.getCheckinMessage(todayEvents, isPublic, needsSlide);
153135
await super.edit(interaction, publicMessage);
154136
}
155137
} catch (e) {

yarn.lock

+17-2
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,11 @@ has-flag@^3.0.0:
15051505
resolved "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
15061506
integrity sha1-tdRU3CGZriJWmfNGfloH87lVuv0=
15071507

1508+
has-flag@^4.0.0:
1509+
version "4.0.0"
1510+
resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
1511+
integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
1512+
15081513
has-symbols@^1.0.1, has-symbols@^1.0.2:
15091514
version "1.0.2"
15101515
resolved "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz"
@@ -2142,6 +2147,11 @@ ms@^2.1.1:
21422147
resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz"
21432148
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
21442149

2150+
nan@^2.14.0:
2151+
version "2.18.0"
2152+
resolved "https://registry.yarnpkg.com/nan/-/nan-2.18.0.tgz#26a6faae7ffbeb293a39660e88a76b82e30b7554"
2153+
integrity sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w==
2154+
21452155
nan@^2.17.0:
21462156
version "2.17.0"
21472157
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:
22342244
resolved "https://registry.npmjs.org/object-inspect/-/object-inspect-1.11.0.tgz"
22352245
integrity sha512-jp7ikS6Sd3GxQfZJPyH3cjcbJF6GZPClgdV+EFygjFLQ5FmW/dRUnTd9PQ9k0JhoNDabWFbpF1yCdSWCC6gexg==
22362246

2237-
object-keys@^1.1.1:
2247+
object-keys@^1.0.12, object-keys@^1.1.1:
22382248
version "1.1.1"
2239-
resolved "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz"
2249+
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
22402250
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
22412251

22422252
object.assign@^4.1.2:
@@ -2388,6 +2398,11 @@ path-type@^3.0.0:
23882398
dependencies:
23892399
pify "^3.0.0"
23902400

2401+
path-type@^4.0.0:
2402+
version "4.0.0"
2403+
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
2404+
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==
2405+
23912406
picocolors@^1.0.0:
23922407
version "1.0.0"
23932408
resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"

0 commit comments

Comments
 (0)