fix: changed back to old defer method

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-04-07 12:31:36 +02:00
parent 9f5d34c74a
commit bf44095346
10 changed files with 39 additions and 52 deletions

View file

@ -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,9 +60,8 @@ object Bot {
//Register Command Listener
kord.on<GuildChatInputCommandInteractionCreateEvent> {
//val response = interaction.deferPublicResponse()
coroutineScope {
val deferred = async { interaction.deferPublicResponse() }
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) {
@ -89,14 +86,13 @@ object Bot {
}
}
c.onSlashCommand(interaction, deferred, opt)
return@coroutineScope
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
kord.createGlobalApplicationCommands {

View file

@ -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<CommandOption>? = null) {
open suspend fun onSlashCommand(
interaction: GuildChatInputCommandInteraction,
deferred: Deferred<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
}

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
val guildId = interaction.guildId

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
val guildId = interaction.guildId

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
val guildId = interaction.guildId

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
val guildId = interaction.guildId

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
val guildId = interaction.guildId

View file

@ -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<Snowflake, GuildTrackScheduler> = mutableMapOf()
@ -44,7 +43,7 @@ object MusicManager {
suspend fun addToQueue(
interaction: GuildChatInputCommandInteraction,
deferred: Deferred<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
link: Link,
search: String
) {
@ -53,7 +52,7 @@ object MusicManager {
suspend fun addToQueue(
interaction: GuildChatInputCommandInteraction,
deferred: Deferred<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
link: Link,
search: String,
silent: Boolean

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
args: Map<CommandOption, String>
) {
MessageUtil.sendEmbedForInteraction(interaction, deferred, "Botendo v5", "ver." + BuildConstants.version)

View file

@ -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<DeferredPublicMessageInteractionResponseBehavior>,
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<DeferredPublicMessageInteractionResponseBehavior>,
deferred: DeferredPublicMessageInteractionResponseBehavior,
title: String,
description: String,
thumbnailUrl: String
) {
deferred.await().respond {
deferred.respond {
embeds = mutableListOf(
getEmbedWithImage(
title,