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

Add date option to Checkin command #46

Merged
merged 4 commits into from
Feb 15, 2024
Merged
Changes from 2 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
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. Use MM/DD format.').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;
newracket marked this conversation as resolved.
Show resolved Hide resolved

// 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
Loading