From 686a86063d3eabd193fa9699bf7589881b3539a3 Mon Sep 17 00:00:00 2001 From: schlaubi Date: Tue, 17 Sep 2024 12:10:19 +0200 Subject: [PATCH] Fix issues with user-installable apps --- .../schlaubi/mikbot/plugin/api/module/SubCommandModule.kt | 2 ++ gradle/libs.versions.toml | 6 +++--- .../kotlin/dev/schlaubi/mikmusic/commands/ClearCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/FixCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/MoveCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/NextCommand.kt | 2 ++ .../dev/schlaubi/mikmusic/commands/NowPlayingCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/PauseCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/PlayCommand.kt | 3 +++ .../kotlin/dev/schlaubi/mikmusic/commands/QueueCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/RemoveCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/ReplayCommand.kt | 2 ++ .../dev/schlaubi/mikmusic/commands/SchedulerCommands.kt | 4 ++++ .../kotlin/dev/schlaubi/mikmusic/commands/SeekCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/SkipCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/StopCommand.kt | 2 ++ .../kotlin/dev/schlaubi/mikmusic/commands/VolumeCommand.kt | 2 ++ .../dev/schlaubi/mikmusic/playlist/commands/Common.kt | 6 ++++++ runtime/build.gradle.kts | 3 ++- 19 files changed, 46 insertions(+), 4 deletions(-) diff --git a/api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/module/SubCommandModule.kt b/api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/module/SubCommandModule.kt index 1fd10d782..17d058288 100644 --- a/api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/module/SubCommandModule.kt +++ b/api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/module/SubCommandModule.kt @@ -50,12 +50,14 @@ public abstract class SubCommandModule(context: PluginContext) : MikBotModule(co groupBodies.add(GroupPair(name, body)) } + public open fun SlashCommand<*, *, *>.commandSettings() = Unit final override suspend fun setup() { overrideSetup() ephemeralSlashCommand { name = commandName description = "" + commandSettings() ephemeralSubCommandBodies.forEach { with(it) { add() } } publicSubCommandBodies.forEach { with(it) { add() } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6d98d53ff..a4301f979 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] kotlin = "2.0.0" -kordex = "1.9.1-mikbot-SNAPSHOT" +kordex = "1.9.2-mikbot-SNAPSHOT" kmongo = "5.1.0" coroutines = "1.8.1" serialization = "1.7.1" ktor = "2.3.11" -kord = "feature-user-apps-20240825.234248-3" -api = "3.36.3" +kord = "feature-user-apps-20240917.091252-4" +api = "3.36.4" ksp = "2.0.0-1.0.22" lavakord = "7.1.0" diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ClearCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ClearCommand.kt index 77ada5ff9..faab032a9 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ClearCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ClearCommand.kt @@ -1,10 +1,12 @@ package dev.schlaubi.mikmusic.commands import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts suspend fun MusicModule.clearCommand() = ephemeralControlSlashCommand { name = "clear" description = "commands.clear.description" + musicControlContexts() action { musicPlayer.queue.clear() diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/FixCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/FixCommand.kt index 4e2c06e9e..6d40d1d7a 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/FixCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/FixCommand.kt @@ -11,6 +11,7 @@ import dev.schlaubi.lavakord.audio.Link import dev.schlaubi.lavakord.kord.connectAudio import dev.schlaubi.mikbot.plugin.api.util.safeGuild import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.MusicPlayer import kotlinx.coroutines.delay import kotlinx.coroutines.flow.map @@ -21,6 +22,7 @@ import kotlin.time.Duration.Companion.seconds suspend fun MusicModule.fixCommand() = ephemeralControlSlashCommand { name = "fix" description = "commands.fix.description" + musicControlContexts() check { requireBotPermissions(Permission.ManageGuild) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/MoveCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/MoveCommand.kt index 9ab90cff5..639654b0d 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/MoveCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/MoveCommand.kt @@ -7,6 +7,7 @@ import com.kotlindiscord.kord.extensions.commands.application.slash.ephemeralSub import com.kotlindiscord.kord.extensions.commands.converters.impl.int import dev.arbjerg.lavalink.protocol.v4.Track import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts class SingleSongMoveArguments : Arguments() { val song by int { @@ -63,6 +64,7 @@ suspend fun MusicModule.moveCommand() { ephemeralControlSlashCommand { name = "move" description = "commands.move.description" + musicControlContexts() ephemeralSubCommand(::SingleSongMoveArguments) { name = "top" diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NextCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NextCommand.kt index 2cb835b4d..2dfc7f681 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NextCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NextCommand.kt @@ -2,11 +2,13 @@ package dev.schlaubi.mikmusic.commands import dev.schlaubi.mikmusic.checks.anyMusicPlaying import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.ChapterQueuedTrack suspend fun MusicModule.nextCommand() = ephemeralControlSlashCommand { name = "next" description = "commands.next.description" + musicControlContexts() check { anyMusicPlaying(this@nextCommand) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NowPlayingCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NowPlayingCommand.kt index 7a82f1f8e..4fb166c20 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NowPlayingCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/NowPlayingCommand.kt @@ -7,6 +7,7 @@ import dev.kord.rest.builder.message.embed import dev.schlaubi.mikmusic.checks.anyMusicPlaying import dev.schlaubi.mikmusic.checks.musicQuizAntiCheat import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.util.addSong import kotlin.time.DurationUnit import kotlin.time.toDuration @@ -23,6 +24,7 @@ private val regex = """\.[0-9]*""".toRegex() suspend fun MusicModule.nowPlayingCommand() = publicSlashCommand(::NowPlayingArguments) { name = "now-playing" description = "commands.now_playing.description" + musicControlContexts() check { anyMusicPlaying(this@nowPlayingCommand) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PauseCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PauseCommand.kt index 95a57962f..eeafb17ec 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PauseCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PauseCommand.kt @@ -1,10 +1,12 @@ package dev.schlaubi.mikmusic.commands import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts suspend fun MusicModule.pauseCommand() = ephemeralControlSlashCommand { name = "pause" description = "commands.pause.description" + musicControlContexts() action { musicPlayer.pause(!link.player.paused) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PlayCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PlayCommand.kt index 1ec613d74..66db86e84 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PlayCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/PlayCommand.kt @@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.defaultingBool import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand import dev.schlaubi.mikmusic.checks.joinSameChannelCheck import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.queue.QueueArguments import dev.schlaubi.mikmusic.player.queue.queueTracks @@ -17,6 +18,8 @@ class PlayArguments : QueueArguments() { suspend fun MusicModule.playCommand() { ephemeralSlashCommand(::PlayArguments) { + musicControlContexts() + name = "play" description = "commands.play.description" diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/QueueCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/QueueCommand.kt index 07a68fb8d..3d6212a48 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/QueueCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/QueueCommand.kt @@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand import dev.schlaubi.mikbot.plugin.api.util.forList import dev.schlaubi.mikmusic.checks.anyMusicPlaying import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.QueuedTrack import dev.schlaubi.mikmusic.player.addAutoPlaySongs import dev.schlaubi.mikmusic.util.format @@ -11,6 +12,7 @@ import dev.schlaubi.mikmusic.util.format suspend fun MusicModule.queueCommand() = ephemeralSlashCommand { name = "queue" description = "commands.queue.description" + musicControlContexts() check { anyMusicPlaying(this@queueCommand) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/RemoveCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/RemoveCommand.kt index 99af36ac5..f0e732e86 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/RemoveCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/RemoveCommand.kt @@ -10,6 +10,7 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalInt import dev.kord.common.entity.Snowflake import dev.schlaubi.mikbot.plugin.api.util.safeGuild import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.toList @@ -35,6 +36,7 @@ class RemoveRangeSongArguments : Arguments() { suspend fun MusicModule.removeCommand() = ephemeralControlSlashCommand { name = "remove" description = "commands.remove.description" + musicControlContexts() suspend fun EphemeralSlashCommand.doRemove( remove: suspend EphemeralSlashCommandContext.() -> Int diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ReplayCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ReplayCommand.kt index f6be7583c..2f555de8e 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ReplayCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/ReplayCommand.kt @@ -1,10 +1,12 @@ package dev.schlaubi.mikmusic.commands import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts suspend fun MusicModule.replayCommand() = ephemeralControlSlashCommand { name = "replay" description = "commands.replay.description" + musicControlContexts() action { player.seekTo(0) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SchedulerCommands.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SchedulerCommands.kt index 00960a308..07380b7a0 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SchedulerCommands.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SchedulerCommands.kt @@ -2,6 +2,7 @@ package dev.schlaubi.mikmusic.commands import com.kotlindiscord.kord.extensions.commands.application.slash.EphemeralSlashCommandContext import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.MusicPlayer import kotlin.reflect.KMutableProperty1 @@ -27,6 +28,7 @@ suspend fun MusicModule.schedulerCommands() { ephemeralControlSlashCommand { name = "repeat" description = "Toggles repeat mode" + musicControlContexts() action { schedulerOption( @@ -41,6 +43,7 @@ suspend fun MusicModule.schedulerCommands() { ephemeralControlSlashCommand { name = "loop-queue" description = "Toggles loop queueTracks mode (Looping the queueTracks over and over)" + musicControlContexts() action { schedulerOption( @@ -55,6 +58,7 @@ suspend fun MusicModule.schedulerCommands() { ephemeralControlSlashCommand { name = "shuffle" description = "Toggles shuffle mode" + musicControlContexts() action { schedulerOption( diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SeekCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SeekCommand.kt index 248efc35a..b195d3bdf 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SeekCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SeekCommand.kt @@ -6,6 +6,7 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.string import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand import dev.schlaubi.mikmusic.checks.anyMusicPlaying import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds @@ -27,6 +28,7 @@ class SeekArguments : Arguments() { suspend fun MusicModule.seekCommand() = ephemeralSlashCommand(::SeekArguments) { name = "seek" description = "commands.seek.description" + musicControlContexts() check { anyMusicPlaying(this@seekCommand) diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SkipCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SkipCommand.kt index 7e30745f7..f45ccafb6 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SkipCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/SkipCommand.kt @@ -3,6 +3,7 @@ package dev.schlaubi.mikmusic.commands import com.kotlindiscord.kord.extensions.commands.Arguments import com.kotlindiscord.kord.extensions.commands.converters.impl.defaultingInt import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts class SkipArguments : Arguments() { val to by defaultingInt { @@ -15,6 +16,7 @@ class SkipArguments : Arguments() { suspend fun MusicModule.skipCommand() = ephemeralControlSlashCommand(::SkipArguments) { name = "skip" description = "commands.skip.description" + musicControlContexts() action { if (!musicPlayer.canSkip) { diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/StopCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/StopCommand.kt index 670a16d2a..4b9cfe226 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/StopCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/StopCommand.kt @@ -1,11 +1,13 @@ package dev.schlaubi.mikmusic.commands import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts suspend fun MusicModule.stopCommand() = ephemeralControlSlashCommand { name = "die" description = "commands.stop.description" + musicControlContexts() action { musicPlayer.stop() diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/VolumeCommand.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/VolumeCommand.kt index b04f426ff..c46162a93 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/VolumeCommand.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/commands/VolumeCommand.kt @@ -3,6 +3,7 @@ package dev.schlaubi.mikmusic.commands import com.kotlindiscord.kord.extensions.commands.Arguments import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalInt import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts class VolumeArguments : Arguments() { val volume by optionalInt { @@ -16,6 +17,7 @@ class VolumeArguments : Arguments() { suspend fun MusicModule.volumeCommand() = ephemeralControlSlashCommand(::VolumeArguments) { name = "volume" description = "commands.volume.description" + musicControlContexts() action { val volume = arguments.volume diff --git a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/playlist/commands/Common.kt b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/playlist/commands/Common.kt index 9e2cd1677..c3a20ca11 100644 --- a/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/playlist/commands/Common.kt +++ b/music/commands/src/main/kotlin/dev/schlaubi/mikmusic/playlist/commands/Common.kt @@ -4,6 +4,7 @@ import com.kotlindiscord.kord.extensions.DiscordRelayedException import com.kotlindiscord.kord.extensions.commands.Arguments import com.kotlindiscord.kord.extensions.commands.CommandContext import com.kotlindiscord.kord.extensions.commands.application.slash.EphemeralSlashCommandContext +import com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand import com.kotlindiscord.kord.extensions.commands.converters.impl.string import dev.kord.core.behavior.UserBehavior import dev.kord.core.behavior.interaction.suggestString @@ -12,6 +13,7 @@ import dev.schlaubi.mikbot.plugin.api.PluginContext import dev.schlaubi.mikbot.plugin.api.module.SubCommandModule import dev.schlaubi.mikbot.plugin.api.util.extension import dev.schlaubi.mikmusic.core.MusicModule +import dev.schlaubi.mikmusic.core.musicControlContexts import dev.schlaubi.mikmusic.player.MusicPlayer import dev.schlaubi.mikmusic.playlist.Playlist import dev.schlaubi.mikmusic.playlist.PlaylistDatabase @@ -87,6 +89,10 @@ class PlaylistModule(context: PluginContext) : SubCommandModule(context) { val CommandContext.node: Node get() = with(musicModule) { node } + override fun SlashCommand<*, *, *>.commandSettings() { + musicControlContexts() + } + override suspend fun overrideSetup() { loadCommand() saveCommand() diff --git a/runtime/build.gradle.kts b/runtime/build.gradle.kts index fe980911b..0fb9e8432 100644 --- a/runtime/build.gradle.kts +++ b/runtime/build.gradle.kts @@ -31,7 +31,8 @@ dependencies { // otherwise we would add entire Gradle in here isTransitive = false } - implementation("dev.kord:kord-common-jvm:feature-user-apps-20240825.234248-3") + implementation("dev.kord:kord-common-jvm:feature-user-apps-20240917.091252-4") + implementation("dev.kord:kord-rest-jvm:feature-user-apps-20240917.091252-4") // Util implementation(libs.kotlinx.serialization.json)