From f29c444ba4b2e1d9ab49f9b36c5db53afe03d36e Mon Sep 17 00:00:00 2001 From: Michael Rittmeister Date: Sun, 27 Oct 2024 23:48:41 +0100 Subject: [PATCH] Fix activity emojis & entry command --- .../kotlin/components/SoundContainer.kt | 4 +++- .../tonbrett/app/components/SoundContainer.kt | 23 +++++++++++++++++++ .../tonbrett/app/components/SoundContainer.kt | 6 +++++ .../dev/schlaubi/tonbrett/bot/Plugin.kt | 4 ++-- .../tonbrett/bot/commands/PlayCommand.kt | 1 + gradle/libs.versions.toml | 2 +- 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 app/shared/src/jsMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt create mode 100644 app/shared/src/nonWebMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt diff --git a/app/shared/src/commonMain/kotlin/components/SoundContainer.kt b/app/shared/src/commonMain/kotlin/components/SoundContainer.kt index 5c77f905..7f5cc55f 100644 --- a/app/shared/src/commonMain/kotlin/components/SoundContainer.kt +++ b/app/shared/src/commonMain/kotlin/components/SoundContainer.kt @@ -251,7 +251,7 @@ fun SoundCard( modifier = Modifier.fillMaxSize().padding(horizontal = 3.dp) ) { require(emoji is Sound.Emoji.HasUrl?) { "This emoji is invalid: $emoji" } - OptionalWebImage(emoji?.url, modifier = Modifier.size(32.dp).padding(end = 5.dp)) + OptionalWebImage(emoji?.url?.proxyUrl(), modifier = Modifier.size(32.dp).padding(end = 5.dp)) Text( name, color = ColorScheme.current.textColor, @@ -285,3 +285,5 @@ fun SoundCard( } } } + +expect fun String.proxyUrl(): String diff --git a/app/shared/src/jsMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt b/app/shared/src/jsMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt new file mode 100644 index 00000000..988f3599 --- /dev/null +++ b/app/shared/src/jsMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt @@ -0,0 +1,23 @@ +package dev.schlaubi.tonbrett.app.components + +import io.ktor.http.URLBuilder +import kotlinx.browser.window + +val appId = window.location.host.substringBefore(".") + +actual fun String.proxyUrl(): String { + return if (window.location.host.endsWith("discordsays.com")) { + URLBuilder(this).apply { + val specifier = when (host) { + "cdn.discordapp.com" -> "cdn" + "cdn.jsdelivr.net" -> "jsdelivr" + else -> error("Unknown host: $host") + } + + host = "${appId}.discordsays.com" + pathSegments = listOf(".proxy", specifier) + pathSegments.filter(String::isNotBlank) + }.buildString() + } else { + this + } +} diff --git a/app/shared/src/nonWebMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt b/app/shared/src/nonWebMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt new file mode 100644 index 00000000..7c4229a9 --- /dev/null +++ b/app/shared/src/nonWebMain/kotlin/dev/schlaubi/tonbrett/app/components/SoundContainer.kt @@ -0,0 +1,6 @@ +@file:JvmName("SoundContainerNonWeb") +package dev.schlaubi.tonbrett.app.components + +import kotlin.jvm.JvmName + +actual fun String.proxyUrl() = this diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/Plugin.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/Plugin.kt index 789ff58d..a210fdb1 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/Plugin.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/Plugin.kt @@ -5,7 +5,7 @@ package dev.schlaubi.tonbrett.bot import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder import com.kotlindiscord.kord.extensions.extensions.primaryEntryPointCommand import com.kotlindiscord.kord.extensions.modules.unsafe.annotations.UnsafeAPI -import dev.kord.common.entity.EntryPointCommandHandlerType +import dev.kord.common.entity.PrimaryEntryPointCommandHandlerType import dev.kord.gateway.Intent import dev.schlaubi.mikbot.plugin.api.Plugin import dev.schlaubi.mikbot.plugin.api.PluginContext @@ -44,7 +44,7 @@ private class Module(context: PluginContext) : SubCommandModule(context) { name = "Tonbrett" description = "commands.entry_point.description" - handler = EntryPointCommandHandlerType.DiscordLaunchActivity + handler = PrimaryEntryPointCommandHandlerType.DiscordLaunchActivity } } } diff --git a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/PlayCommand.kt b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/PlayCommand.kt index 2fc49478..2839444e 100644 --- a/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/PlayCommand.kt +++ b/bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/commands/PlayCommand.kt @@ -5,6 +5,7 @@ import dev.schlaubi.mikbot.plugin.api.module.SubCommandModule @OptIn(UnsafeAPI::class) fun SubCommandModule.playCommand() = unsafeSubCommand("play") { + name = "play" description = "commands.play.description" action { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a91e651f..8892ace3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ kotlin = "2.0.21" ktor = "3.0.0" kmongo = "5.1.0" kord = "0.15.0" -mikbot = "3.37.20" +mikbot = "3.37.22" ksp = "2.0.21-1.0.26" kordex = "1.9.12-mikbot-SNAPSHOT" android = "8.7.1"