feat(timezone): Adds timezone as option
This commit is contained in:
parent
0b9089ffae
commit
b852c06f83
11 changed files with 278 additions and 22 deletions
|
|
@ -29,6 +29,8 @@ import {PermissionError} from "../PermissionError";
|
|||
import {EmbedLibrary, EmbedType} from "../EmbedLibrary";
|
||||
import {GroupConfigurationModel} from "../../Database/Models/GroupConfigurationModel";
|
||||
import parser from "any-date-parser";
|
||||
import {TimezoneHandler} from "../../Configuration/TimezoneHandler";
|
||||
import _ from "lodash";
|
||||
|
||||
export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInteractionCommand {
|
||||
definition(): SlashCommandBuilder {
|
||||
|
|
@ -123,8 +125,18 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
)
|
||||
}
|
||||
|
||||
const fromDate = parser.fromString(<string>interaction.options.get("from")?.value ?? '');
|
||||
const toDate = parser.fromString(<string>interaction.options.get("to")?.value ?? '');
|
||||
const timezoneHandler = new TimezoneHandler(
|
||||
interaction.guildId ?? '',
|
||||
group
|
||||
);
|
||||
|
||||
const [fromDate, toDate] = timezoneHandler.use(() => {
|
||||
return [
|
||||
parser.fromString(<string>interaction.options.get("from")?.value ?? ''),
|
||||
parser.fromString(<string>interaction.options.get("to")?.value ?? '')
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
if (!fromDate.isValid()) {
|
||||
throw new UserError("No date or invalid date format for the from parameter.");
|
||||
|
|
@ -184,13 +196,19 @@ export class PlaydatesCommand implements Command, AutocompleteCommand, ChatInter
|
|||
|
||||
const group = GroupSelection.getGroup(interaction);
|
||||
|
||||
const timezone = new TimezoneHandler(
|
||||
interaction.guildId ?? '',
|
||||
group
|
||||
);
|
||||
const playdates = Container.get<PlaydateRepository>(PlaydateRepository.name).findFromGroup(group);
|
||||
await interaction.respond(
|
||||
playdates.map(playdate => {
|
||||
return {
|
||||
name: `${playdate.from_time.toLocaleString()} - ${playdate.to_time.toLocaleString()}`,
|
||||
value: <number>playdate.id
|
||||
}
|
||||
timezone.use(() => {
|
||||
return _.slice(playdates, 0, 25).map(playdate => {
|
||||
return {
|
||||
name: `${playdate.from_time.toLocaleString()} - ${playdate.to_time.toLocaleString()}`,
|
||||
value: <number>playdate.id
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue