Skip to content

Commit

Permalink
Add date option to Checkin command
Browse files Browse the repository at this point in the history
  • Loading branch information
newracket committed Jan 31, 2024
1 parent d828692 commit 1cae561
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/commands/Checkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default class Checkin extends Command {
.addBooleanOption(option =>
option.setName('widescreen').setDescription('Include a slide for the QR code.').setRequired(false)
)
.addStringOption(option =>
option.setName('date').setDescription('The date to check for events.').setRequired(false)
)
.setDescription(
"Sends a DM or embed with all check-in codes from today's events. Includes Express Checkin QR code!"
);
Expand Down Expand Up @@ -68,6 +71,15 @@ export default class Checkin extends Command {
// Get arguments. Get rid of the null types by checking them.
const publicArgument = interaction.options.getBoolean('public');
const widescreenArgument = interaction.options.getBoolean('widescreen');
const dateArgument = interaction.options.getString('date');

// Regex to match dates in the format of MM/DD(/YYYY) or MM-DD(-YYYY).
const regexp = new RegExp('^(\\d{1,2})(/|-)(\\d{1,2})((/|-)(\\d{2}|\\d{4})){0,1}$', 'g');
const dateMatches = regexp.exec(dateArgument!);

const month = dateMatches?.[1] ? parseInt(dateMatches[1], 10) : DateTime.now().month;
const day = dateMatches?.[3] ? parseInt(dateMatches[3], 10) : DateTime.now().day;
const year = dateMatches?.[6] ? parseInt(dateMatches[6], 10) : DateTime.now().year;

// By default, we want the QR code to be DMed to the user.
const isPublic = publicArgument !== null ? publicArgument : false;
Expand All @@ -87,22 +99,10 @@ export default class Checkin extends Command {
// 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({
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
});
const midnightToday = DateTime.local(year, month, day, 0, 0, 0, 0);

// get tomorrow's midnight
const midnightTomorrow = DateTime.now()
.set({
hour: 0,
minute: 0,
second: 0,
millisecond: 0,
})
.plus({ day: 1 });
const midnightTomorrow = midnightToday.plus({ day: 1 });

// check if start time in between
return Interval.fromDateTimes(midnightToday, midnightTomorrow).contains(event.start);
Expand Down

0 comments on commit 1cae561

Please sign in to comment.