Skip to content

Commit

Permalink
Add /calendar list command
Browse files Browse the repository at this point in the history
  • Loading branch information
NovaFox161 committed Dec 10, 2024
1 parent c4e897b commit 1526096
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/resources/commands/global/calendar.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
}
]
},
{
"name": "list",
"type": 1,
"description": "Lists all calendars owned by the guild",
"required": false
},
{
"name": "create",
"type": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit 1526096

Please sign in to comment.