feat(playdate-formats): adds format hint and adds partial end entry
This commit is contained in:
parent
b852c06f83
commit
62a32c8222
1 changed files with 47 additions and 5 deletions
|
|
@ -4,7 +4,7 @@ import {
|
|||
ChatInputCommandInteraction,
|
||||
CommandInteraction,
|
||||
EmbedBuilder,
|
||||
GuildMember,
|
||||
GuildMember, hyperlink,
|
||||
MessageFlags,
|
||||
SlashCommandBuilder,
|
||||
time
|
||||
|
|
@ -45,10 +45,12 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
.addStringOption((option) => option
|
||||
.setName("from")
|
||||
.setDescription("Defines the start date & time. Your desired format is probably support.")
|
||||
.setRequired(true)
|
||||
)
|
||||
.addStringOption((option) => option
|
||||
.setName("to")
|
||||
.setDescription("Defines the end date & time. Your desired format is probably support.")
|
||||
.setRequired(true)
|
||||
)
|
||||
)
|
||||
.addSubcommand((subcommand) => subcommand
|
||||
|
|
@ -130,20 +132,54 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
group
|
||||
);
|
||||
|
||||
const fromDateString = <string>interaction.options.get("from")?.value ?? '';
|
||||
const toDateString = <string>interaction.options.get("to")?.value ?? '';
|
||||
|
||||
if (!this.checkDateString(fromDateString) || !this.checkDateString(toDateString)) {
|
||||
throw new UserError(
|
||||
"Please do not use words like 'Uhr', since those may result in values you did not intent.",
|
||||
`Write the time out completely. Either in military time (15:00) or in the 12-hour format (3pm). For more valid formats check this ${hyperlink("list", "https://github.com/kensnyder/any-date-parser?tab=readme-ov-file#exhaustive-list-of-date-formats")}`
|
||||
)
|
||||
}
|
||||
|
||||
const [fromDate, toDate] = timezoneHandler.use(() => {
|
||||
const fromDate = parser.fromString(fromDateString);
|
||||
const toAttempt = parser.attempt(toDateString);
|
||||
|
||||
if (toAttempt.invalid) {
|
||||
throw new UserError(
|
||||
"No date or invalid date format for the to parameter.",
|
||||
`If you want to make sure your format is valid, please check this ${hyperlink("list", "https://github.com/kensnyder/any-date-parser?tab=readme-ov-file#exhaustive-list-of-date-formats")}.`
|
||||
);
|
||||
}
|
||||
|
||||
const toDate = new Date(fromDate.getTime());
|
||||
if (toAttempt.year !== undefined) {
|
||||
toDate.setFullYear(toAttempt.year, toAttempt.month ?? 0, toAttempt.day ?? 0);
|
||||
}
|
||||
if (toAttempt.hour !== undefined) {
|
||||
toDate.setHours(toAttempt.hour, toAttempt.minute ?? 0, toAttempt.second ?? 0);
|
||||
}
|
||||
|
||||
return [
|
||||
parser.fromString(<string>interaction.options.get("from")?.value ?? ''),
|
||||
parser.fromString(<string>interaction.options.get("to")?.value ?? '')
|
||||
fromDate,
|
||||
toDate
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
if (!fromDate.isValid()) {
|
||||
throw new UserError("No date or invalid date format for the from parameter.");
|
||||
throw new UserError(
|
||||
"No date or invalid date format for the from parameter.",
|
||||
`If you want to make sure your format is valid, please check this ${hyperlink("list", "https://github.com/kensnyder/any-date-parser?tab=readme-ov-file#exhaustive-list-of-date-formats")}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (!fromDate.isValid()) {
|
||||
throw new UserError("No date or invalid date format for the to parameter.");
|
||||
throw new UserError(
|
||||
"No date or invalid date format for the to parameter.",
|
||||
`If you want to make sure your format is valid, please check this ${hyperlink("list", "https://github.com/kensnyder/any-date-parser?tab=readme-ov-file#exhaustive-list-of-date-formats")}.`
|
||||
);
|
||||
}
|
||||
|
||||
if (fromDate.getTime() > toDate.getTime()) {
|
||||
|
|
@ -213,6 +249,12 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
)
|
||||
}
|
||||
|
||||
private checkDateString(value: string): boolean {
|
||||
return [
|
||||
'Uhr'
|
||||
].some((section) => value.includes(section));
|
||||
}
|
||||
|
||||
private async list(interaction: ChatInputCommandInteraction, group: GroupModel) {
|
||||
const playdates = Container.get<PlaydateRepository>(PlaydateRepository.name).findFromGroup(group);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue