mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-05-05 00:29:29 -05:00
Trying to fix unexpected empty mono stuff
This commit is contained in:
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.entity.Guild
|
||||
import discord4j.core.`object`.entity.Member
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.core.`object`.BotSettings
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -17,7 +18,7 @@ class AddCalCommand : SlashCommand {
|
||||
override val name = "addcal"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
//TODO: Remove dev-only and switch to patron-only once this is completed
|
||||
return if (settings.devGuild) {
|
||||
Mono.justOrEmpty(event.interaction.member).filterWhen(Member::hasElevatedPermissions).flatMap {
|
||||
@@ -26,9 +27,8 @@ class AddCalCommand : SlashCommand {
|
||||
event.followupEphemeral(getMessage("response.start", settings, getLink(settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.calendar.max", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
.then()
|
||||
} else {
|
||||
event.followupEphemeral(getCommonMsg("error.disabled", settings)).then()
|
||||
event.followupEphemeral(getCommonMsg("error.disabled", settings))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+20
-19
@@ -3,6 +3,7 @@ package org.dreamexposure.discal.client.commands
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Guild
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import discord4j.core.spec.InteractionReplyEditSpec
|
||||
import org.dreamexposure.discal.client.message.embed.CalendarEmbed
|
||||
@@ -24,7 +25,7 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
override val name = "calendar"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return when (event.options[0].name) {
|
||||
"create" -> create(event, settings)
|
||||
"name" -> name(event, settings)
|
||||
@@ -39,7 +40,7 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun create(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun create(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val name = event.options[0].getOption("name")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
@@ -67,10 +68,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
.map { CalendarEmbed.pre(it, settings, wizard.get(settings.guildID)!!) }
|
||||
.flatMap { event.followupEphemeral(getMessage("error.wizard.started", settings), it) }
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun name(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun name(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val name = event.options[0].getOption("name")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
@@ -86,10 +87,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
} else {
|
||||
event.followupEphemeral(getMessage("error.wizard.notStarted", settings))
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun description(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun description(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val desc = event.options[0].getOption("description")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
@@ -105,10 +106,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
} else {
|
||||
event.followupEphemeral(getMessage("error.wizard.notStarted", settings))
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun timezone(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun timezone(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val timezone = event.options[0].getOption("timezone")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
@@ -130,10 +131,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
} else {
|
||||
event.followupEphemeral(getMessage("error.wizard.notStarted", settings))
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun review(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun review(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.interaction.member.get().hasElevatedPermissions().filter { it }.flatMap {
|
||||
val pre = wizard.get(settings.guildID)
|
||||
if (pre != null) {
|
||||
@@ -143,10 +144,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
} else {
|
||||
event.followupEphemeral(getMessage("error.wizard.notStarted", settings))
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun confirm(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun confirm(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.interaction.member.get().hasElevatedPermissions().filter { it }.flatMap {
|
||||
val pre = wizard.get(settings.guildID)
|
||||
if (pre != null) {
|
||||
@@ -183,18 +184,18 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
} else {
|
||||
event.followupEphemeral(getMessage("error.wizard.notStarted", settings))
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun cancel(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun cancel(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.interaction.member.get().hasElevatedPermissions().filter { it }.flatMap {
|
||||
wizard.remove(settings.guildID)
|
||||
|
||||
event.followupEphemeral(getMessage("cancel.success", settings))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun delete(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun delete(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -207,10 +208,10 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
.flatMap { it.delete() }
|
||||
.flatMap { event.followupEphemeral(getMessage("delete.success", settings)) }
|
||||
.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
|
||||
private fun edit(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun edit(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -232,6 +233,6 @@ class CalendarCommand(val wizard: CalendarWizard) : SlashCommand {
|
||||
.map { CalendarEmbed.pre(it, settings, wizard.get(settings.guildID)!!) }
|
||||
.flatMap { event.followupEphemeral(getMessage("error.wizard.started", settings), it) }
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.`object`.web.UserAPIAccount
|
||||
@@ -18,9 +19,9 @@ class DevCommand : SlashCommand {
|
||||
override val name = "dev"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
if (!GlobalVal.devUserIds.contains(event.interaction.user.id)) {
|
||||
return event.followupEphemeral(getMessage("error.notDeveloper", settings)).then()
|
||||
return event.followupEphemeral(getMessage("error.notDeveloper", settings))
|
||||
}
|
||||
|
||||
return when (event.options[0].name) {
|
||||
@@ -33,7 +34,7 @@ class DevCommand : SlashCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun patronSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun patronSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val guildId = event.options[0].getOption("guild")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asSnowflake)
|
||||
@@ -47,10 +48,9 @@ class DevCommand : SlashCommand {
|
||||
)
|
||||
}.doOnError { LOGGER.error("[cmd] patron failure", it) }
|
||||
.onErrorResume { event.followupEphemeral(getMessage("patron.failure.badId", settings)) }
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun devSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun devSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val guildId = event.options[0].getOption("guild")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asSnowflake)
|
||||
@@ -64,10 +64,9 @@ class DevCommand : SlashCommand {
|
||||
)
|
||||
}.doOnError { LOGGER.error("[cmd] dev failure", it) }
|
||||
.onErrorResume { event.followupEphemeral(getMessage("dev.failure.badId", settings)) }
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun maxCalSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun maxCalSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val guildId = event.options[0].getOption("guild")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asSnowflake)
|
||||
@@ -84,10 +83,10 @@ class DevCommand : SlashCommand {
|
||||
}
|
||||
.onErrorResume {
|
||||
event.followupEphemeral(getMessage("maxcal.failure.badInput", settings))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun apiRegisterSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun apiRegisterSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return Mono.justOrEmpty(event.options[0].getOption("user").flatMap { it.value })
|
||||
.flatMap(ApplicationCommandInteractionOptionValue::asUser)
|
||||
.flatMap { user ->
|
||||
@@ -106,10 +105,9 @@ class DevCommand : SlashCommand {
|
||||
}
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getMessage("apiRegister.failure.empty", settings)))
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun apiBlockSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun apiBlockSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return Mono.justOrEmpty(event.options[0].getOption("key").flatMap { it.value })
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
.flatMap(DatabaseManager::getAPIAccount)
|
||||
@@ -120,6 +118,6 @@ class DevCommand : SlashCommand {
|
||||
.switchIfEmpty(event.followupEphemeral(getMessage("apiBlock.failure.notFound", settings)))
|
||||
.onErrorResume {
|
||||
event.followupEphemeral(getMessage("apiBlock.failure.other", settings))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.DiscalEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -12,10 +13,9 @@ class DiscalCommand : SlashCommand {
|
||||
override val name = "discal"
|
||||
override val ephemeral = false
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.interaction.guild
|
||||
.flatMap(DiscalEmbed::info)
|
||||
.flatMap(event::followup)
|
||||
.then()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.EventEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -23,7 +24,7 @@ class EventsCommand : SlashCommand {
|
||||
override val name = "events"
|
||||
override val ephemeral = false
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return when (event.options[0].name) {
|
||||
"upcoming" -> upcomingEventsSubcommand(event, settings)
|
||||
"ongoing" -> ongoingEventsSubcommand(event, settings)
|
||||
@@ -33,7 +34,7 @@ class EventsCommand : SlashCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun upcomingEventsSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun upcomingEventsSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -48,7 +49,7 @@ class EventsCommand : SlashCommand {
|
||||
|
||||
|
||||
if (amount < 1 || amount > 15) {
|
||||
return event.followup(getMessage("upcoming.failure.outOfRange", settings)).then()
|
||||
return event.followup(getMessage("upcoming.failure.outOfRange", settings))
|
||||
}
|
||||
|
||||
return event.interaction.guild.flatMap { guild ->
|
||||
@@ -68,14 +69,14 @@ class EventsCommand : SlashCommand {
|
||||
Flux.fromIterable(events)
|
||||
}.concatMap {
|
||||
event.followup(EventEmbed.getCondensed(guild, settings, it))
|
||||
}.then(Mono.just(""))
|
||||
}.last()
|
||||
}
|
||||
}
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings))).then()
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}
|
||||
}
|
||||
|
||||
private fun ongoingEventsSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun ongoingEventsSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -99,14 +100,14 @@ class EventsCommand : SlashCommand {
|
||||
Flux.fromIterable(events)
|
||||
}.concatMap {
|
||||
event.followup(EventEmbed.getCondensed(guild, settings, it))
|
||||
}.then(Mono.just(""))
|
||||
}.last()
|
||||
}
|
||||
}
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun eventsTodaySubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun eventsTodaySubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -130,14 +131,14 @@ class EventsCommand : SlashCommand {
|
||||
Flux.fromIterable(events)
|
||||
}.concatMap {
|
||||
event.followup(EventEmbed.getCondensed(guild, settings, it))
|
||||
}.then(Mono.just(""))
|
||||
}.last()
|
||||
}
|
||||
}
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun eventsRangeSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun eventsRangeSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val gMono = event.interaction.guild.cache()
|
||||
|
||||
val calMono = Mono.justOrEmpty(event.options[0].getOption("calendar").flatMap { it.value })
|
||||
@@ -189,12 +190,12 @@ class EventsCommand : SlashCommand {
|
||||
Flux.fromIterable(events)
|
||||
}.concatMap {
|
||||
event.followup(EventEmbed.getCondensed(guild, settings, it))
|
||||
}.then(Mono.just(""))
|
||||
}.last()
|
||||
}
|
||||
}
|
||||
}).switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings)))
|
||||
.onErrorResume(DateTimeParseException::class.java) {
|
||||
event.followup(getCommonMsg("error.format.date", settings))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.core.`object`.BotSettings
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -12,9 +13,9 @@ class HelpCommand : SlashCommand {
|
||||
override val name = "help"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.followupEphemeral(
|
||||
getMessage("error.workInProgress", settings, "${BotSettings.BASE_URL.get()}/commands")
|
||||
).then()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.CalendarEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -15,7 +16,7 @@ class LinkCalendarCommand : SlashCommand {
|
||||
override val name = "linkcal"
|
||||
override val ephemeral = false
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -25,6 +26,6 @@ class LinkCalendarCommand : SlashCommand {
|
||||
return event.interaction.guild.flatMap { guild ->
|
||||
CalendarEmbed.link(guild, settings, calendarNumber)
|
||||
.flatMap(event::followup)
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings))).then()
|
||||
}.switchIfEmpty(event.followup(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.dreamexposure.discal.client.commands
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Member
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.RsvpEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -20,7 +21,7 @@ class RsvpCommand : SlashCommand {
|
||||
override val name = "rsvp"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return when (event.options[0].name) {
|
||||
"ontime" -> onTime(event, settings)
|
||||
"late" -> late(event, settings)
|
||||
@@ -34,7 +35,7 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onTime(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun onTime(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -65,10 +66,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun late(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun late(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -99,10 +100,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun unsure(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun unsure(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -132,10 +133,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notGoing(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun notGoing(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -165,10 +166,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun remove(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun remove(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -197,10 +198,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun list(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun list(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -218,10 +219,10 @@ class RsvpCommand : SlashCommand {
|
||||
RsvpEmbed.list(guild, settings, calEvent).flatMap { event.followupEphemeral(it) }
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun limit(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun limit(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -258,10 +259,10 @@ class RsvpCommand : SlashCommand {
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.privileged", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.privileged", settings)))
|
||||
}
|
||||
|
||||
private fun role(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun role(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.options[0].getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -315,6 +316,6 @@ class RsvpCommand : SlashCommand {
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.event", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)))
|
||||
}).then()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
+11
-15
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.SettingsEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -20,7 +21,7 @@ class SettingsCommand : SlashCommand {
|
||||
override val name = "settings"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
//Check if user has permission to use this
|
||||
return event.interaction.member.get().hasElevatedPermissions().flatMap { hasPerm ->
|
||||
if (hasPerm) {
|
||||
@@ -34,19 +35,18 @@ class SettingsCommand : SlashCommand {
|
||||
else -> Mono.empty() //Never can reach this, makes compiler happy.
|
||||
}
|
||||
} else {
|
||||
event.followupEphemeral(getCommonMsg("error.perms.elevated", settings)).then()
|
||||
event.followupEphemeral(getCommonMsg("error.perms.elevated", settings))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun viewSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun viewSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return event.interaction.guild
|
||||
.flatMap { SettingsEmbed.getView(it, settings) }
|
||||
.flatMap(event::followup)
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun roleSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun roleSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return Mono.justOrEmpty(event.options[0].getOption("role"))
|
||||
.map { it.value.get() }
|
||||
.flatMap(ApplicationCommandInteractionOptionValue::asRole)
|
||||
@@ -55,10 +55,10 @@ class SettingsCommand : SlashCommand {
|
||||
DatabaseManager.updateSettings(settings).then(
|
||||
event.followupEphemeral(getMessage("role.success", settings, role.name))
|
||||
)
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
private fun announcementStyleSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun announcementStyleSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val announcementStyle = event.options[0].getOption("style")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -70,10 +70,9 @@ class SettingsCommand : SlashCommand {
|
||||
|
||||
return DatabaseManager.updateSettings(settings)
|
||||
.flatMap { event.followupEphemeral(getMessage("style.success", settings, announcementStyle.name)) }
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun languageSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun languageSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val lang = event.options[0].getOption("lang")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asString)
|
||||
@@ -83,10 +82,9 @@ class SettingsCommand : SlashCommand {
|
||||
|
||||
return DatabaseManager.updateSettings(settings)
|
||||
.flatMap { event.followupEphemeral(getMessage("lang.success", settings)) }
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun timeFormatSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun timeFormatSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val timeFormat = event.options[0].getOption("format")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -98,10 +96,9 @@ class SettingsCommand : SlashCommand {
|
||||
|
||||
return DatabaseManager.updateSettings(settings)
|
||||
.flatMap { event.followupEphemeral(getMessage("format.success", settings, timeFormat.name)) }
|
||||
.then()
|
||||
}
|
||||
|
||||
private fun brandingSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
private fun brandingSubcommand(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return if (settings.patronGuild) {
|
||||
val useBranding = event.options[0].getOption("use")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
@@ -112,9 +109,8 @@ class SettingsCommand : SlashCommand {
|
||||
|
||||
DatabaseManager.updateSettings(settings)
|
||||
.flatMap { event.followupEphemeral(getMessage("brand.success", settings, "$useBranding")) }
|
||||
.then()
|
||||
} else {
|
||||
event.followupEphemeral(getCommonMsg("error.patronOnly", settings)).then()
|
||||
event.followupEphemeral(getCommonMsg("error.patronOnly", settings))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.utils.MessageSourceLoader
|
||||
@@ -10,7 +11,7 @@ interface SlashCommand {
|
||||
|
||||
val ephemeral: Boolean
|
||||
|
||||
fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void>
|
||||
fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message>
|
||||
|
||||
fun getMessage(key: String, settings: GuildSettings, vararg args: String): String {
|
||||
val src = MessageSourceLoader.getSourceByPath("command/$name/$name")
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOption
|
||||
import discord4j.core.`object`.command.ApplicationCommandInteractionOptionValue
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.message.embed.CalendarEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
@@ -15,7 +16,7 @@ class TimeCommand : SlashCommand {
|
||||
override val name = "time"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Void> {
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
val calendarNumber = event.getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -26,6 +27,6 @@ class TimeCommand : SlashCommand {
|
||||
CalendarEmbed.time(guild, settings, calendarNumber).flatMap {
|
||||
event.followupEphemeral(it)
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings))).then()
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -3,7 +3,9 @@ package org.dreamexposure.discal.client.listeners.discord
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import org.dreamexposure.discal.client.commands.SlashCommand
|
||||
import org.dreamexposure.discal.core.database.DatabaseManager
|
||||
import org.dreamexposure.discal.core.extensions.discord4j.followupEphemeral
|
||||
import org.dreamexposure.discal.core.logger.LOGGER
|
||||
import org.dreamexposure.discal.core.utils.getCommonMsg
|
||||
import org.springframework.context.ApplicationContext
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
@@ -24,10 +26,13 @@ class SlashCommandListener(applicationContext: ApplicationContext) {
|
||||
if (command.ephemeral) event.deferReply().withEphemeral(true)
|
||||
else event.deferReply()
|
||||
|
||||
mono.then(DatabaseManager.getSettings(event.interaction.guildId.get()))
|
||||
.flatMap { command.handle(event, it) }
|
||||
mono.then(DatabaseManager.getSettings(event.interaction.guildId.get())).flatMap {
|
||||
command.handle(event, it).switchIfEmpty(event.followupEphemeral(getCommonMsg("error.unknown", it)))
|
||||
}
|
||||
}.doOnError {
|
||||
LOGGER.error("Unhandled slash command error", it)
|
||||
}.onErrorResume { Mono.empty() }
|
||||
}.onErrorResume {
|
||||
Mono.empty()
|
||||
}.then()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
bot.name=DisCal
|
||||
|
||||
error.unknown=Sorry, an unknown error has occurred.
|
||||
|
||||
error.notFound.event=No event with that ID was found. There may be a typo or it was deleted.
|
||||
error.notFound.calendar=Calendar not found. There may be a typo or it may it deleted
|
||||
error.notFound.announcement=No announcement with that ID was found. There may be a typo or it was deleted.
|
||||
|
||||
Reference in New Issue
Block a user