From 1526096857bf0f905ac0bf19c252be278f5875df Mon Sep 17 00:00:00 2001 From: NovaFox161 Date: Mon, 9 Dec 2024 21:00:00 -0600 Subject: [PATCH] Add /calendar list command --- .../client/commands/global/CalendarCommand.kt | 29 +++++++++++++++++++ .../resources/commands/global/calendar.json | 6 ++++ .../i18n/command/calendar/calendar.properties | 4 +++ 3 files changed, 39 insertions(+) diff --git a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt index 659066dd0..cd243d982 100644 --- a/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt +++ b/client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/CalendarCommand.kt @@ -35,6 +35,7 @@ class CalendarCommand( override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message { return when (event.options[0].name) { "view" -> view(event, settings) + "list" -> list(event, settings) "create" -> create(event, settings) "name" -> name(event, settings) "description" -> description(event, settings) @@ -76,6 +77,34 @@ class CalendarCommand( .awaitSingle() } + private suspend fun list(event: ChatInputInteractionEvent, settings: GuildSettings): Message { + val calendars = calendarService.getAllCalendars(settings.guildId) + + if (calendars.isEmpty()) { + return event.createFollowup(getMessage("list.success.none", settings)) + .withEphemeral(ephemeral) + .awaitSingle() + } else if (calendars.size == 1) { + return event.createFollowup(getMessage("list.success.one", settings)) + .withEphemeral(ephemeral) + .withEmbeds(embedService.linkCalendarEmbed(calendars[0])) + .awaitSingle() + } else { + val response = event.createFollowup(getMessage("list.success.many", settings, "${calendars.size}")) + .withEphemeral(ephemeral) + .awaitSingle() + + calendars.forEach { + event.createFollowup() + .withEmbeds(embedService.linkCalendarEmbed(it)) + .withEphemeral(ephemeral) + .awaitSingle() + } + + return response + } + } + private suspend fun create(event: ChatInputInteractionEvent, settings: GuildSettings): Message { val name = event.options[0].getOption("name") .flatMap(ApplicationCommandInteractionOption::getValue) diff --git a/core/src/main/resources/commands/global/calendar.json b/core/src/main/resources/commands/global/calendar.json index f3c976e22..7a2346c84 100644 --- a/core/src/main/resources/commands/global/calendar.json +++ b/core/src/main/resources/commands/global/calendar.json @@ -23,6 +23,12 @@ } ] }, + { + "name": "list", + "type": 1, + "description": "Lists all calendars owned by the guild", + "required": false + }, { "name": "create", "type": 1, diff --git a/core/src/main/resources/i18n/command/calendar/calendar.properties b/core/src/main/resources/i18n/command/calendar/calendar.properties index 6d75e2b8a..22ad12426 100644 --- a/core/src/main/resources/i18n/command/calendar/calendar.properties +++ b/core/src/main/resources/i18n/command/calendar/calendar.properties @@ -11,6 +11,10 @@ meta.description.description=Sets the calendar's description in the wizard meta.description.timezone=Sets the calendar's timezone in the wizard meta.description.edit=Starts the calendar edit wizard +list.success.none=No calendars we found. Start creating one with `/calendar create`. +list.success.one=Single calendar found. +list.success.many={0} calendars were found. There may be a delay in listing all calendars... + create.success=Calendar wizard started! Please supply required information and then confirm the creation of your new \ calendar with `/calendar confirm` create.success.badTimezone=Calendar wizard started! \n However, the timezone provided was not recognized, please \