Skip to content

Commit

Permalink
Migration to Kordex 2.0
Browse files Browse the repository at this point in the history
- Update project dependencies
- Ignore mikbot dependencies in renovate
- Add compatibility with Gradle Configuration Cache
- Add all dependencies to about command
  • Loading branch information
DRSchlaubi committed Nov 4, 2024
1 parent e469129 commit 3b60870
Show file tree
Hide file tree
Showing 187 changed files with 1,391 additions and 1,968 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ plugins/
**/bin/main
!buildSrc/src/main/kotlin/**
main-dependency-export.txt
# Kordex Data Collection directory
data/kordex
10 changes: 10 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import dev.kordex.gradle.plugins.kordex.InternalAPI
import dev.kordex.gradle.plugins.kordex.base.KordExExtension
import dev.kordex.gradle.plugins.kordex.helpers.I18nHelper
import dev.kordex.gradle.plugins.kordex.i18n.KordExI18nSettings

plugins {
`mikbot-module`
`mikbot-publishing`
Expand Down Expand Up @@ -40,3 +45,15 @@ template {
className = "MikBotInfo"
packageName = "dev.schlaubi.mikbot.plugin.api"
}

val kordExExtension = extensions.create<KordExExtension>("kordex").apply {
i18n {
classPackage = "dev.schlaubi.mikbot.plugin.api"
className = "MikBotTranslations"
translationBundle = "mikbot"
}
}

@Suppress("INVISIBLE_MEMBER")
@OptIn(InternalAPI::class)
I18nHelper.apply(project, kordExExtension.i18n)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.schlaubi.mikbot.plugin.api

import dev.kordex.core.builders.AboutBuilder
import org.pf4j.ExtensionPoint

/**
* Allows to modify the about command.
*/
public interface AboutExtensionPoint : ExtensionPoint {
/**
* Applies this extensions settings to the about page.
*/
public suspend fun AboutBuilder.apply()
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.schlaubi.mikbot.plugin.api

import com.kotlindiscord.kord.extensions.extensions.Extension
import dev.kordex.core.extensions.Extension
import dev.schlaubi.mikbot.plugin.api.module.MikBotModule
import org.pf4j.ExtensionPoint
import kotlin.reflect.KClass
Expand Down
12 changes: 7 additions & 5 deletions api/src/main/kotlin/dev/schlaubi/mikbot/plugin/api/Plugin.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package dev.schlaubi.mikbot.plugin.api

import com.kotlindiscord.kord.extensions.ExtensibleBot
import com.kotlindiscord.kord.extensions.builders.ExtensibleBotBuilder
import com.kotlindiscord.kord.extensions.extensions.Extension
import dev.kordex.core.ExtensibleBot
import dev.kordex.core.builders.ExtensibleBotBuilder
import dev.kordex.core.builders.ExtensionsBuilder
import dev.kordex.core.extensions.Extension
import dev.schlaubi.mikbot.plugin.api.io.Database
import dev.schlaubi.mikbot.plugin.api.module.MikBotModule
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -39,6 +40,7 @@ public abstract class Plugin : Plugin {
* @param wrapper the [PluginWrapper] provided by the plugin engine
*/
@Deprecated("Deprecated by PF4J (Use Plugin#Plugin(PluginContext) instead")
@Suppress("DEPRECATION")
public constructor(wrapper: PF4JPluginWrapper) : super(wrapper) {
context = null
}
Expand Down Expand Up @@ -84,7 +86,7 @@ public abstract class Plugin : Plugin {
/**
* Add new extensions.
*/
public open fun ExtensibleBotBuilder.ExtensionsBuilder.addExtensions(): Unit = Unit
public open fun ExtensionsBuilder.addExtensions(): Unit = Unit

/**
* This is being executed directly after the bot got started.
Expand All @@ -96,6 +98,6 @@ public abstract class Plugin : Plugin {
*
* @see MikBotModule
*/
public fun <T : MikBotModule> ExtensibleBotBuilder.ExtensionsBuilder.add(builder: (PluginContext) -> T): Unit =
public fun <T : MikBotModule> ExtensionsBuilder.add(builder: (PluginContext) -> T): Unit =
add { builder(context ?: error("Please upgrade this plugin to the new context")) }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.schlaubi.mikbot.plugin.api.config

import ch.qos.logback.classic.Level
import com.kotlindiscord.kord.extensions.i18n.SupportedLocales
import dev.kordex.core.i18n.SupportedLocales
import dev.kord.common.entity.Snowflake
import dev.schlaubi.envconf.EnvironmentVariable
import dev.schlaubi.envconf.getEnv
Expand Down Expand Up @@ -43,24 +43,24 @@ public object Config : EnvironmentConfig("") {
/**
* The Sentry token.
*/
public val SENTRY_TOKEN: String? by environment.optional()
public val SENTRY_TOKEN: String? by getEnv().optional()

/**
* The Discord token.
*/
public val DISCORD_TOKEN: String by environment
public val DISCORD_TOKEN: String by this

/**
* The [Mongo connection String](https://docs.mongodb.com/manual/reference/connection-string/) used for the bots Database features.
*/
public val MONGO_URL: String? by environment.optional()
public val MONGO_URL: String? by getEnv().optional()

/**
* The database to use.
*
* **This has to be specified, even if there is a database in [MONGO_URL]**
*/
public val MONGO_DATABASE: String? by environment.optional()
public val MONGO_DATABASE: String? by getEnv().optional()

/**
* The path to the plugins folder.
Expand Down Expand Up @@ -120,7 +120,7 @@ public data class PluginSpec(public val id: String, public val version: String?)
public fun parse(spec: String): PluginSpec {
val at = spec.indexOf('@')
return if (at >= 0) {
PluginSpec(spec.substring(0, at), spec.substring(at + 1, spec.length))
PluginSpec(spec.take(at), spec.substring(at + 1, spec.length))
} else {
PluginSpec(spec, null)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.schlaubi.mikbot.plugin.api.module

import com.kotlindiscord.kord.extensions.extensions.Extension
import dev.kordex.core.extensions.Extension
import dev.schlaubi.mikbot.plugin.api.PluginContext
import dev.schlaubi.mikbot.plugin.api.Plugin

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package dev.schlaubi.mikbot.plugin.api.module

import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.application.slash.*
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.modules.unsafe.annotations.UnsafeAPI
import com.kotlindiscord.kord.extensions.modules.unsafe.commands.UnsafeSlashCommand
import com.kotlindiscord.kord.extensions.modules.unsafe.extensions.unsafeSubCommand
import dev.kordex.core.commands.Arguments
import dev.kordex.core.commands.application.slash.*
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.ephemeralSlashCommand
import dev.kordex.core.i18n.EMPTY_KEY
import dev.kordex.core.i18n.toKey
import dev.kordex.core.i18n.types.Key
import dev.kordex.modules.dev.unsafe.annotations.UnsafeAPI
import dev.kordex.modules.dev.unsafe.commands.slash.UnsafeSlashCommand
import dev.kordex.modules.dev.unsafe.extensions.unsafeSubCommand
import dev.schlaubi.mikbot.plugin.api.PluginContext

/**
Expand All @@ -27,7 +30,7 @@ public abstract class SubCommandModule(context: PluginContext) : MikBotModule(co
/**
* The name of the root command.
*/
public abstract val commandName: String
public abstract val commandName: Key

public fun <T : Arguments> ephemeralSubCommand(
argumentBody: (() -> T),
Expand Down Expand Up @@ -56,18 +59,18 @@ public abstract class SubCommandModule(context: PluginContext) : MikBotModule(co
}

@UnsafeAPI
public fun unsafeSubCommand(name: String, body: UnsafeSlashCommand<Arguments, *>.() -> Unit) {
public fun unsafeSubCommand(body: UnsafeSlashCommand<Arguments, *>.() -> Unit) {
unsafeSubCommandBodies.add(UnsafeCommandPair(null, body))
}

public open fun SlashCommand<*, *, *>.commandSettings() = Unit
public open fun SlashCommand<*, *, *>.commandSettings(): Unit = Unit
@OptIn(UnsafeAPI::class)
final override suspend fun setup() {
overrideSetup()

ephemeralSlashCommand {
name = commandName
description = "<never used>"
description = "<not used>".toKey()
commandSettings()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.schlaubi.mikbot.plugin.api.owner

import com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand
import dev.kordex.core.commands.application.slash.SlashCommand
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.Permission
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package dev.schlaubi.mikbot.plugin.api.settings

import com.kotlindiscord.kord.extensions.commands.application.slash.SlashCommand
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.common.entity.InteractionContextType
import dev.kord.common.entity.Permission
import dev.schlaubi.mikbot.plugin.api.*
import dev.kordex.core.commands.application.slash.SlashCommand
import dev.schlaubi.mikbot.plugin.api.InternalAPI
import dev.schlaubi.mikbot.plugin.api.ModuleExtensionPoint
import dev.schlaubi.mikbot.plugin.api.ModuleExtensionPointImpl
import dev.schlaubi.mikbot.plugin.api.PluginContext

/**
* Extension for settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import dev.kord.core.event.Event
* Event fired when all shards are first connected to Discord.
*/
@OptIn(KordPreview::class)
public class AllShardsReadyEvent constructor(
public class AllShardsReadyEvent(
override val kord: Kord,
override val shard: Int,
override val customContext: Any? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.schlaubi.mikbot.plugin.api.util

import com.kotlindiscord.kord.extensions.ExtensibleBot
import com.kotlindiscord.kord.extensions.commands.CommandContext
import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import dev.kordex.core.ExtensibleBot
import dev.kordex.core.commands.CommandContext
import dev.kordex.core.koin.KordExKoinComponent
import dev.schlaubi.mikbot.plugin.api.io.Database
import org.koin.core.component.KoinComponent

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.schlaubi.mikbot.plugin.api.util

import com.kotlindiscord.kord.extensions.checks.types.CheckContext
import dev.kordex.core.checks.types.CheckContext
import dev.kord.core.event.Event

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.schlaubi.mikbot.plugin.api.util

import com.kotlindiscord.kord.extensions.checks.anyGuild
import com.kotlindiscord.kord.extensions.commands.Command
import com.kotlindiscord.kord.extensions.commands.CommandContext
import dev.kordex.core.checks.anyGuild
import dev.kordex.core.commands.Command
import dev.kordex.core.commands.CommandContext
import dev.kord.core.Kord
import dev.kord.core.behavior.GuildBehavior
import dev.kord.core.behavior.MemberBehavior
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package dev.schlaubi.mikbot.plugin.api.util

import com.kotlindiscord.kord.extensions.commands.CommandContext
import com.kotlindiscord.kord.extensions.commands.application.slash.EphemeralSlashCommandContext
import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashCommandContext
import com.kotlindiscord.kord.extensions.components.components
import com.kotlindiscord.kord.extensions.modules.unsafe.annotations.UnsafeAPI
import com.kotlindiscord.kord.extensions.modules.unsafe.contexts.UnsafeSlashCommandContext
import com.kotlindiscord.kord.extensions.modules.unsafe.types.respondEphemeral
import com.kotlindiscord.kord.extensions.modules.unsafe.types.respondPublic
import com.kotlindiscord.kord.extensions.utils.waitFor
import dev.kordex.core.commands.CommandContext
import dev.kordex.core.commands.application.slash.EphemeralSlashCommandContext
import dev.kordex.core.commands.application.slash.PublicSlashCommandContext
import dev.kordex.core.components.components
import dev.kordex.modules.dev.unsafe.annotations.UnsafeAPI
import dev.kord.common.entity.ButtonStyle
import dev.kord.core.behavior.interaction.followup.FollowupMessageBehavior
import dev.kord.core.behavior.interaction.followup.edit
Expand All @@ -17,6 +13,11 @@ import dev.kord.core.entity.interaction.followup.EphemeralFollowupMessage
import dev.kord.core.entity.interaction.followup.PublicFollowupMessage
import dev.kord.core.event.interaction.InteractionCreateEvent
import dev.kord.rest.builder.message.actionRow
import dev.kordex.core.i18n.withContext
import dev.kordex.core.types.TranslatableContext
import dev.kordex.core.utils.waitFor
import dev.kordex.modules.dev.unsafe.contexts.UnsafeCommandSlashCommandContext
import dev.schlaubi.mikbot.plugin.api.MikBotTranslations
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

Expand Down Expand Up @@ -73,7 +74,7 @@ public suspend fun PublicSlashCommandContext<*, *>.confirmation(
* @return whether the user confirmed the form or not
*/
@UnsafeAPI
public suspend fun UnsafeSlashCommandContext<*, *>.ephemeralConfirmation(
public suspend fun UnsafeCommandSlashCommandContext<*, *>.ephemeralConfirmation(
yesWord: String? = null,
noWord: String? = null,
timeout: Duration = 30.seconds,
Expand All @@ -92,7 +93,7 @@ public suspend fun UnsafeSlashCommandContext<*, *>.ephemeralConfirmation(
* @return whether the user confirmed the form or not
*/
@UnsafeAPI
public suspend fun UnsafeSlashCommandContext<*, *>.publicConfirmation(
public suspend fun UnsafeCommandSlashCommandContext<*, *>.publicConfirmation(
yesWord: String? = null,
noWord: String? = null,
timeout: Duration = 30.seconds,
Expand All @@ -101,7 +102,7 @@ public suspend fun UnsafeSlashCommandContext<*, *>.publicConfirmation(
): Confirmation = unsafeConfirmation(yesWord, noWord, messageBuilder, timeout, acknowledge) { respondPublic { it() } }

@OptIn(UnsafeAPI::class)
private suspend fun UnsafeSlashCommandContext<*, *>.unsafeConfirmation(
private suspend fun UnsafeCommandSlashCommandContext<*, *>.unsafeConfirmation(
yesWord: String?,
noWord: String?,
messageBuilder: MessageBuilder,
Expand All @@ -121,7 +122,7 @@ private suspend fun CommandContext.confirmation(
sendMessage,
timeout,
messageBuilder,
translate = ::translate,
translatableContext = this,
yesWord = yesWord,
noWord = noWord,
acknowledge = acknowledge
Expand All @@ -135,7 +136,7 @@ public suspend fun confirmation(
timeout: Duration? = 30.seconds,
messageBuilder: MessageBuilder,
hasNoOption: Boolean = true,
translate: Translator,
translatableContext: TranslatableContext,
yesWord: String? = null,
noWord: String? = null,
acknowledge: Boolean = true,
Expand All @@ -146,12 +147,16 @@ public suspend fun confirmation(
components {
actionRow {
interactionButton(ButtonStyle.Success, yes) {
label = yesWord ?: translate("general.yes", "general")
label = yesWord ?: MikBotTranslations.General.yes
.withContext(translatableContext)
.translate()
}

if (hasNoOption) {
interactionButton(ButtonStyle.Danger, no) {
label = noWord ?: translate("general.no", "general")
label = noWord ?: MikBotTranslations.General.no
.withContext(translatableContext)
.translate()
}
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit 3b60870

Please sign in to comment.