Skip to content

Commit

Permalink
Merge branch 'refs/heads/root' into k2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukellmann committed Jun 24, 2024
2 parents 9255520 + 6278c24 commit 58bacfb
Show file tree
Hide file tree
Showing 31 changed files with 421 additions and 226 deletions.
3 changes: 3 additions & 0 deletions .idea/compiler.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package com.kotlindiscord.kord.extensions.modules.annotations.converters

import com.google.devtools.ksp.symbol.KSAnnotation
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.kotlindiscord.kord.extensions.modules.annotations.orNull

/**
Expand All @@ -31,8 +31,8 @@ public data class ConverterAnnotationArgs(public val annotation: KSAnnotation) {

/** @suppress **/
public val types: List<ConverterType> =
(argMap["types"]!! as ArrayList<KSType>).mapNotNull {
ConverterType.fromName(it.declaration.simpleName.asString())
(argMap["types"]!! as ArrayList<KSClassDeclaration>).mapNotNull {
ConverterType.fromName(it.simpleName.asString())
}

/** @suppress **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,26 @@ public class ConverterProcessor(
val outputText = buildString {
append(
"""
@file:OptIn(
KordPreview::class,
ConverterToDefaulting::class,
ConverterToMulti::class,
ConverterToOptional::class
)
package ${classDeclaration.packageName.asString()}
// Original converter class, for safety
import ${classDeclaration.qualifiedName!!.asString()}
// Imports that all converters need
import com.kotlindiscord.kord.extensions.InvalidArgumentException
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.*
import com.kotlindiscord.kord.extensions.commands.converters.builders.*
import dev.kord.common.annotation.KordPreview
@file:OptIn(
KordPreview::class,
ConverterToDefaulting::class,
ConverterToMulti::class,
ConverterToOptional::class,
UnexpectedFunctionBehaviour::class,
)
package ${classDeclaration.packageName.asString()}
// Original converter class, for safety
import ${classDeclaration.qualifiedName!!.asString()}
// Imports that all converters need
import com.kotlindiscord.kord.extensions.InvalidArgumentException
import com.kotlindiscord.kord.extensions.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.commands.Arguments
import com.kotlindiscord.kord.extensions.commands.converters.*
import com.kotlindiscord.kord.extensions.commands.converters.builders.*
import dev.kord.common.annotation.KordPreview
""".trimIndent()
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@


argument.api-url.name=api-url
argument.toggle.description=Establezca si la integración de PK debe utilizarse en este servidor
arguments.reset=restablecer
command.pluralkit.name=pluralkit
command.pluralkit.description=Gestionar y ver la configuración de integración de PluralKit para este servidor
command.pluralkit.api-url.description=Establecer una URL de API personalizada, "reset" para restablecer
command.pluralkit.api-url.response.reset=**URL de la API restablecida a la predeterminada:** `{0}`
command.pluralkit.bot.description=Elija su instancia PluralKit personalizada, si tiene una
command.pluralkit.bot.response.current=**Instancia PK actual:** {0}
command.pluralkit.bot.response.updated=**Instancia PK actualizada:** {0}
command.pluralkit.status.response.title=Configuración de la integración de PluralKit
command.pluralkit.toggle-support.description=Desactivar o activar la integración de PluralKit según sea necesario
command.pluralkit.toggle-support.response.current=**Activado:** {0}
command.pluralkit.toggle-support.response.updated=**Toggle actualizado:** {0}
command.pluralkit.toggle-support.name=toggle
argument.api-url.description=Establezca una url para la API alternativa, o "reset" para utilizar la predeterminada
argument.bot.name=bot
argument.bot.description=Seleccione una instancia PK alternativa, si es necesario
argument.toggle.name=activar
command.pluralkit.api-url.name=api-url
command.pluralkit.api-url.response.current=**URL actual de la API:** `{0}`
command.pluralkit.bot.name=bot
command.pluralkit.api-url.response.updated=**URL de la API actualizada: `{0}`
command.pluralkit.status.name=estado
command.pluralkit.status.description=Compruebe la configuración de la integración de PluralKit para este servidor
command.pluralkit.status.response.description=**URL de la API:** '{0}'\n**Instancias PK:**{1}\n**Habilitado:**{2}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
org.gradle.parallel=true
kotlin.incremental=true
ksp.incremental=false
projectVersion=1.8.0-SNAPSHOT
projectVersion=1.8.1-SNAPSHOT
#dokka will run out of memory with the default meta space
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1024m
ksp.useKSP2=true
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromJsonElement
import org.koin.core.component.inject
import org.koin.dsl.bind
import java.lang.IllegalArgumentException
import java.lang.IllegalStateException
import kotlin.concurrent.thread

/**
* An extensible bot, wrapping a Kord instance.
Expand Down Expand Up @@ -96,6 +99,13 @@ public open class ExtensibleBot(
/** @suppress **/
public open val logger: KLogger = KotlinLogging.logger {}

/** @suppress **/
public open val shutdownHook: Thread = thread(false) {
runBlocking {
close()
}
}

/** @suppress Function that sets up the bot early on, called by the builder. **/
public open suspend fun setup() {
val kord = settings.kordBuilder(token) {
Expand Down Expand Up @@ -139,6 +149,15 @@ public open class ExtensibleBot(

if (!initialized) registerListeners()

@Suppress("TooGenericExceptionCaught")
try {
Runtime.getRuntime().addShutdownHook(shutdownHook)
} catch (e: IllegalArgumentException) {
logger.debug(e) { "Shutdown hook already added or thread is running." }
} catch (e: Exception) {
logger.warn(e) { "Unable to add shutdown hook." }
}

getKoin().get<Kord>().login {
this.presence(settings.presenceBuilder)
this.intents = Intents(settings.intentsBuilder!!)
Expand All @@ -148,7 +167,7 @@ public open class ExtensibleBot(
/**
* Stop the bot by logging out [Kord].
*
* This will leave the Koin context intact, so subsequent restarting of the bot is possible.
* This will leave extensions loaded and the Koin context intact, so later restarting of the bot is possible.
*
* @see close
**/
Expand All @@ -157,19 +176,32 @@ public open class ExtensibleBot(
}

/**
* Stop the bot by shutting down [Kord] and removing its Koin context.
* Stop the bot by unloading extensions, shutting down [Kord], and removing its Koin context.
*
* Restarting the bot after closing will result in undefined behavior
* Restarting the bot after closing will result in undefined behaviour
* because the Koin context needed to start will no longer exist.
*
* If a bot has been closed, then it must be fully rebuilt to start again.
*
* If a new bot is going to be built, then the previous bot must be closed first.
* You must fully rebuild closed bots to start again.
* Likewise, you must close previous bots before building a new one.
*
* @see stop
**/
public open suspend fun close() {
@Suppress("TooGenericExceptionCaught")
try {
Runtime.getRuntime().removeShutdownHook(shutdownHook)
} catch (e: IllegalStateException) {
logger.debug { "Shutdown in progress, unable to remove shutdown hook." }
} catch (e: Exception) {
logger.warn(e) { "Failed to remove shutdown hook." }
}

extensions.keys.forEach {
unloadExtension(it)
}

getKoin().get<Kord>().shutdown()

KordExContext.stopKoin()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ package com.kotlindiscord.kord.extensions.annotations

/** Marks a function that may result in unexpected behaviour, and ask the developer to check the docs. **/
@RequiresOptIn(
message = "Calling this function may result in unexpected behaviour. Please ensure you read its documentation " +
"comment before continuing.",
message = "Calling or overriding this function may result in unexpected behaviour. Please ensure you read its " +
"documentation comment before continuing.",
level = RequiresOptIn.Level.WARNING
)
@Target(AnnotationTarget.FUNCTION)
public annotation class UnexpectedBehaviour
public annotation class UnexpectedFunctionBehaviour
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package com.kotlindiscord.kord.extensions.commands

import com.kotlindiscord.kord.extensions.annotations.UnexpectedFunctionBehaviour
import com.kotlindiscord.kord.extensions.commands.converters.*

/**
Expand Down Expand Up @@ -42,7 +43,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: SingleConverter<R>,
Expand All @@ -63,7 +65,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: DefaultingConverter<R>,
Expand All @@ -84,7 +87,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: OptionalConverter<R>,
Expand All @@ -105,7 +109,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: ListConverter<R>,
Expand All @@ -126,7 +131,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: CoalescingConverter<R>,
Expand All @@ -147,7 +153,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: DefaultingCoalescingConverter<R>,
Expand All @@ -168,7 +175,8 @@ public open class Arguments {
*
* @return Argument converter to use as a delegate.
*/
public fun <R : Any> arg(
@UnexpectedFunctionBehaviour
public open fun <R : Any> arg(
displayName: String,
description: String,
converter: OptionalCoalescingConverter<R>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ public abstract class MessageCommand<C : MessageCommandContext<C, M>, M : ModalF

mapOf(
"name" to name,
"type" to "message"
"type" to "message",
"extension" to extension.name,
)
)

context.sentry.context(
"extension", extension.name
)

context.sentry.breadcrumb(BreadcrumbType.User) {
category = "command.application.message"
message = "Message command \"$name\" called."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,30 @@ public abstract class SlashCommand<C : SlashCommandContext<*, A, M>, A : Argumen
/** If enabled, adds the initial Sentry breadcrumb to the given context. **/
public open suspend fun firstSentryBreadcrumb(context: C, commandObj: SlashCommand<*, *, *>) {
if (sentry.enabled) {
val fullName = buildString {
parentCommand?.let {
append(it.name)
append(" ")
}

parentGroup?.let {
append(it.name)
append(" ")
}

append(name)
}

context.sentry.context(
"command",

mapOf(
"name" to name,
"type" to "slash"
"name" to fullName,
"type" to "slash",
"extension" to extension.name
)
)

context.sentry.context(
"extension", extension.name
)

context.sentry.breadcrumb(BreadcrumbType.User) {
category = "command.application.slash"
message = "Slash command \"${commandObj.name}\" called."
Expand Down
Loading

0 comments on commit 58bacfb

Please sign in to comment.