Skip to content

Commit

Permalink
Fix activity emojis & entry command
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 27, 2024
1 parent 3e29bd2 commit f29c444
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -285,3 +285,5 @@ fun SoundCard(
}
}
}

expect fun String.proxyUrl(): String
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@file:JvmName("SoundContainerNonWeb")
package dev.schlaubi.tonbrett.app.components

import kotlin.jvm.JvmName

actual fun String.proxyUrl() = this
4 changes: 2 additions & 2 deletions bot/src/main/kotlin/dev/schlaubi/tonbrett/bot/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -44,7 +44,7 @@ private class Module(context: PluginContext) : SubCommandModule(context) {
name = "Tonbrett"
description = "commands.entry_point.description"

handler = EntryPointCommandHandlerType.DiscordLaunchActivity
handler = PrimaryEntryPointCommandHandlerType.DiscordLaunchActivity
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f29c444

Please sign in to comment.