Skip to content

Commit

Permalink
fix: add runtime hints for kord until kordlib/kord/issues/786 is merg…
Browse files Browse the repository at this point in the history
…ed (#67)
  • Loading branch information
DarkAtra authored Apr 23, 2023
1 parent 2521f2e commit f6c41a8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
6 changes: 0 additions & 6 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
{
"matchPackagePatterns": "*",
"allowedVersions": "!/-.+\\.[0-9]+$/"
},
{
"matchPackagePatterns": [
"dev.kord:kord-core"
],
"enabled": false
}
]
}
41 changes: 41 additions & 0 deletions src/main/kotlin/de/darkatra/vrising/discord/BotRuntimeHints.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package de.darkatra.vrising.discord

import dev.kord.core.cache.data.ApplicationCommandData
import dev.kord.core.cache.data.AutoModerationRuleData
import dev.kord.core.cache.data.ChannelData
import dev.kord.core.cache.data.EmojiData
import dev.kord.core.cache.data.GuildApplicationCommandPermissionsData
import dev.kord.core.cache.data.GuildData
import dev.kord.core.cache.data.MemberData
import dev.kord.core.cache.data.MessageData
import dev.kord.core.cache.data.PresenceData
import dev.kord.core.cache.data.RoleData
import dev.kord.core.cache.data.StickerData
import dev.kord.core.cache.data.StickerPackData
import dev.kord.core.cache.data.ThreadMemberData
import dev.kord.core.cache.data.UserData
import dev.kord.core.cache.data.VoiceStateData
import dev.kord.core.cache.data.WebhookData
import io.ktor.network.selector.InterestSuspensionsMap
import io.ktor.utils.io.pool.DefaultPool
import org.dizitart.no2.Document
Expand All @@ -8,6 +24,7 @@ import org.dizitart.no2.NitriteId
import org.dizitart.no2.meta.Attributes
import org.h2.store.fs.FilePathDisk
import org.h2.store.fs.FilePathNio
import org.springframework.aot.hint.BindingReflectionHintsRegistrar
import org.springframework.aot.hint.MemberCategory
import org.springframework.aot.hint.RuntimeHints
import org.springframework.aot.hint.RuntimeHintsRegistrar
Expand All @@ -21,6 +38,8 @@ import java.util.concurrent.atomic.AtomicBoolean
*/
class BotRuntimeHints : RuntimeHintsRegistrar {

private val bindingReflectionHintsRegistrar = BindingReflectionHintsRegistrar()

override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {

// required by nitrite to create a database with password
Expand All @@ -42,10 +61,32 @@ class BotRuntimeHints : RuntimeHintsRegistrar {
hints.serialization().registerType(NitriteId::class.java)
hints.serialization().registerType(TypeReference.of("java.lang.String"))

// reflection hints for kord (remove once https://github.com/kordlib/kord/issues/786 is merged)
bindingReflectionHintsRegistrar.registerReflectionHints(
hints.reflection(),
ApplicationCommandData::class.java,
AutoModerationRuleData::class.java,
ChannelData::class.java,
EmojiData::class.java,
GuildData::class.java,
MemberData::class.java,
MessageData::class.java,
PresenceData::class.java,
RoleData::class.java,
StickerData::class.java,
ThreadMemberData::class.java,
UserData::class.java,
VoiceStateData::class.java,
WebhookData::class.java
)

hints.reflection()
// required by nitrite to create and open file based databases
.registerType(FilePathDisk::class.java, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
.registerType(FilePathNio::class.java, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
// required by kord (remove once https://github.com/kordlib/kord/issues/786 is merged)
.registerType(GuildApplicationCommandPermissionsData::class.java)
.registerType(StickerPackData::class.java)
// required by kotlin coroutines (dependency of kord)
.registerType(TypeReference.of("kotlin.internal.jdk8.JDK8PlatformImplementations"), MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
// required by ktor (dependency of kord)
Expand Down

0 comments on commit f6c41a8

Please sign in to comment.