diff --git a/src/main/kotlin/de/limited_dev/botendo/Bot.kt b/src/main/kotlin/de/limited_dev/botendo/Bot.kt index 9d4b173..daaa19b 100644 --- a/src/main/kotlin/de/limited_dev/botendo/Bot.kt +++ b/src/main/kotlin/de/limited_dev/botendo/Bot.kt @@ -35,8 +35,6 @@ import dev.kord.rest.builder.interaction.integer import dev.kord.rest.builder.interaction.string import dev.schlaubi.lavakord.LavaKord import dev.schlaubi.lavakord.kord.lavakord -import kotlinx.coroutines.async -import kotlinx.coroutines.coroutineScope object Bot { //The kord object gets set at app launch @@ -62,40 +60,38 @@ object Bot { //Register Command Listener kord.on { - //val response = interaction.deferPublicResponse() - coroutineScope { - val deferred = async { interaction.deferPublicResponse() } - val command = interaction.command - Logger.out("Command /${command.rootName} with ${command.options.size} Option${if (command.options.size == 1) "" else "s"}") - for (c in SlashCommandManager.commands) { - if (c.name != command.rootName) - continue - val opt = mutableMapOf() - if (c.options != null) { - for (o in c.options) { - when (o.type) { - OptionType.INT -> - if (command.integers[o.name] != null) - opt[o] = command.integers[o.name].toString() + val deferred = interaction.deferPublicResponse() + //val deferred = async { interaction.deferPublicResponse() } + val command = interaction.command + Logger.out("Command /${command.rootName} with ${command.options.size} Option${if (command.options.size == 1) "" else "s"}") + for (c in SlashCommandManager.commands) { + if (c.name != command.rootName) + continue + val opt = mutableMapOf() + if (c.options != null) { + for (o in c.options) { + when (o.type) { + OptionType.INT -> + if (command.integers[o.name] != null) + opt[o] = command.integers[o.name].toString() - OptionType.STRING -> - if (command.strings[o.name] != null) - opt[o] = command.strings[o.name].toString() + OptionType.STRING -> + if (command.strings[o.name] != null) + opt[o] = command.strings[o.name].toString() - OptionType.BOOLEAN -> - if (command.booleans[o.name] != null) - opt[o] = command.booleans[o.name].toString() - } + OptionType.BOOLEAN -> + if (command.booleans[o.name] != null) + opt[o] = command.booleans[o.name].toString() } } - c.onSlashCommand(interaction, deferred, opt) - return@coroutineScope } - MessageUtil.sendEmbedForInteraction( - interaction, deferred, "Command not found", "Could not find the command, which you just ran.\n" + - "This is 110%ly an error. Please report it to limited_dev#7441." - ) + c.onSlashCommand(interaction, deferred, opt) + return@on } + MessageUtil.sendEmbedForInteraction( + interaction, deferred, "Command not found", "Could not find the command, which you just ran.\n" + + "This is 110%ly an error. Please report it to limited_dev#7441." + ) } //Register Slash Commands at Discord diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/component/SlashCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/component/SlashCommand.kt index e00d964..a0367a1 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/component/SlashCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/component/SlashCommand.kt @@ -22,13 +22,12 @@ package de.limited_dev.botendo.commands.slash.component import de.limited_dev.botendo.commands.slash.component.options.CommandOption import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction -import kotlinx.coroutines.Deferred abstract class SlashCommand(val name: String, val description: String, val options: List? = null) { open suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { } diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/NowPlayingCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/NowPlayingCommand.kt index 3221cc2..36e830e 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/NowPlayingCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/NowPlayingCommand.kt @@ -28,12 +28,11 @@ import de.limited_dev.botendo.util.UrlUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.schlaubi.lavakord.audio.Link -import kotlinx.coroutines.Deferred class NowPlayingCommand : SlashCommand("nowplaying", "Show what's currently playing", null) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { val guildId = interaction.guildId diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/PlayCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/PlayCommand.kt index c579bf8..cc48ceb 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/PlayCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/PlayCommand.kt @@ -28,7 +28,6 @@ import de.limited_dev.botendo.util.MessageUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.schlaubi.lavakord.audio.Link -import kotlinx.coroutines.Deferred class PlayCommand : SlashCommand( "play", @@ -37,7 +36,7 @@ class PlayCommand : SlashCommand( ) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { val guildId = interaction.guildId diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/QueueCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/QueueCommand.kt index 61a7659..e5f0404 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/QueueCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/QueueCommand.kt @@ -28,12 +28,11 @@ import de.limited_dev.botendo.util.TimeUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.schlaubi.lavakord.audio.Link -import kotlinx.coroutines.Deferred class QueueCommand : SlashCommand("queue", "Show whats up next", null) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { val guildId = interaction.guildId diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/SkipCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/SkipCommand.kt index fcaf817..f74a2fd 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/SkipCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/SkipCommand.kt @@ -29,12 +29,11 @@ import de.limited_dev.botendo.util.UrlUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.schlaubi.lavakord.audio.Link -import kotlinx.coroutines.Deferred class SkipCommand : SlashCommand("skip", "Skip to the next song in queue", null) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { val guildId = interaction.guildId diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/StopCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/StopCommand.kt index 9108ee1..cd46ffb 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/StopCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/StopCommand.kt @@ -27,12 +27,11 @@ import de.limited_dev.botendo.util.MessageUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.schlaubi.lavakord.audio.Link -import kotlinx.coroutines.Deferred class StopCommand : SlashCommand("stop", "Stop playing and start leavin'", null) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { val guildId = interaction.guildId diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/component/MusicManager.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/component/MusicManager.kt index ef1a682..e916542 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/component/MusicManager.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/music/component/MusicManager.kt @@ -30,7 +30,6 @@ import dev.schlaubi.lavakord.audio.Link import dev.schlaubi.lavakord.audio.player.Player import dev.schlaubi.lavakord.rest.TrackResponse import dev.schlaubi.lavakord.rest.loadItem -import kotlinx.coroutines.Deferred object MusicManager { private var musicManagerMap: MutableMap = mutableMapOf() @@ -44,7 +43,7 @@ object MusicManager { suspend fun addToQueue( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, link: Link, search: String ) { @@ -53,7 +52,7 @@ object MusicManager { suspend fun addToQueue( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, link: Link, search: String, silent: Boolean diff --git a/src/main/kotlin/de/limited_dev/botendo/commands/slash/util/InfoCommand.kt b/src/main/kotlin/de/limited_dev/botendo/commands/slash/util/InfoCommand.kt index 2376294..7daa0fe 100644 --- a/src/main/kotlin/de/limited_dev/botendo/commands/slash/util/InfoCommand.kt +++ b/src/main/kotlin/de/limited_dev/botendo/commands/slash/util/InfoCommand.kt @@ -25,12 +25,11 @@ import de.limited_dev.botendo.commands.slash.component.options.CommandOption import de.limited_dev.botendo.util.MessageUtil import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteractionResponseBehavior import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction -import kotlinx.coroutines.Deferred class InfoCommand : SlashCommand("info", "Shows infos about the bot", null) { override suspend fun onSlashCommand( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, args: Map ) { MessageUtil.sendEmbedForInteraction(interaction, deferred, "Botendo v5", "ver." + BuildConstants.version) diff --git a/src/main/kotlin/de/limited_dev/botendo/util/MessageUtil.kt b/src/main/kotlin/de/limited_dev/botendo/util/MessageUtil.kt index 6e65232..67f732f 100644 --- a/src/main/kotlin/de/limited_dev/botendo/util/MessageUtil.kt +++ b/src/main/kotlin/de/limited_dev/botendo/util/MessageUtil.kt @@ -23,7 +23,6 @@ import dev.kord.core.behavior.interaction.response.DeferredPublicMessageInteract import dev.kord.core.behavior.interaction.response.respond import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction import dev.kord.rest.builder.message.EmbedBuilder -import kotlinx.coroutines.Deferred import java.time.LocalDateTime import java.time.format.DateTimeFormatter @@ -32,11 +31,11 @@ object MessageUtil { suspend fun sendEmbedForInteraction( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, title: String, description: String ) { - deferred.await().respond { + deferred.respond { embeds = mutableListOf( getEmbed( title, @@ -49,12 +48,12 @@ object MessageUtil { suspend fun sendEmbedForInteractionWithImage( interaction: GuildChatInputCommandInteraction, - deferred: Deferred, + deferred: DeferredPublicMessageInteractionResponseBehavior, title: String, description: String, thumbnailUrl: String ) { - deferred.await().respond { + deferred.respond { embeds = mutableListOf( getEmbedWithImage( title,