mirror of
https://github.com/DreamExposure/DisCal-Discord-Bot.git
synced 2026-01-26 05:48:29 -06:00
Add backwards compatibility for suspend/reactive commands
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package org.dreamexposure.discal.client.commands
|
||||
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
import discord4j.core.`object`.entity.Message
|
||||
import kotlinx.coroutines.reactor.awaitSingle
|
||||
import kotlinx.coroutines.reactor.mono
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.utils.MessageSourceLoader
|
||||
import reactor.core.publisher.Mono
|
||||
@@ -11,7 +13,14 @@ interface SlashCommand {
|
||||
|
||||
val ephemeral: Boolean
|
||||
|
||||
fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message>
|
||||
@Deprecated("Use new handleSuspend for K-coroutines")
|
||||
fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
return mono { suspendHandle(event, settings) }
|
||||
}
|
||||
|
||||
suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {
|
||||
return handle(event, settings).awaitSingle()
|
||||
}
|
||||
|
||||
fun getMessage(key: String, settings: GuildSettings, vararg args: String): String {
|
||||
val src = MessageSourceLoader.getSourceByPath("command/$name/$name")
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.dreamexposure.discal.client.commands.global
|
||||
|
||||
import discord4j.core.event.domain.interaction.ChatInputInteractionEvent
|
||||
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 kotlinx.coroutines.reactor.awaitSingle
|
||||
import org.dreamexposure.discal.client.commands.SlashCommand
|
||||
import org.dreamexposure.discal.client.message.embed.CalendarEmbed
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.extensions.discord4j.followupEphemeral
|
||||
import org.dreamexposure.discal.core.`object`.GuildSettings
|
||||
import org.dreamexposure.discal.core.utils.getCommonMsg
|
||||
import org.springframework.stereotype.Component
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Component
|
||||
class TimeCommand : SlashCommand {
|
||||
override val name = "time"
|
||||
override val ephemeral = true
|
||||
|
||||
override fun handle(event: ChatInputInteractionEvent, settings: GuildSettings): Mono<Message> {
|
||||
override suspend fun suspendHandle(event: ChatInputInteractionEvent, settings: GuildSettings): Message {
|
||||
val calendarNumber = event.getOption("calendar")
|
||||
.flatMap(ApplicationCommandInteractionOption::getValue)
|
||||
.map(ApplicationCommandInteractionOptionValue::asLong)
|
||||
@@ -28,6 +28,6 @@ class TimeCommand : SlashCommand {
|
||||
CalendarEmbed.time(guild, settings, calendarNumber).flatMap {
|
||||
event.followupEphemeral(it)
|
||||
}
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings)))
|
||||
}.switchIfEmpty(event.followupEphemeral(getCommonMsg("error.notFound.calendar", settings))).awaitSingle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ class SlashCommandListener(
|
||||
|
||||
try {
|
||||
val settings = DatabaseManager.getSettings(event.interaction.guildId.get()).awaitSingle()
|
||||
command.handle(event, settings).awaitSingleOrNull()
|
||||
|
||||
command.suspendHandle(event, settings)
|
||||
} catch (e: Exception) {
|
||||
LOGGER.error(DEFAULT, "Error handling slash command | $event", e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user