Skip to content

Commit

Permalink
Fix issues with sentry extension v2
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Sep 22, 2024
1 parent ad547fa commit d542182
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ subprojects {
version = projectVersion

tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.contracts.ExperimentalContracts"
compilerOptions.freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
compilerOptions.freeCompilerArgs.add("-opt-in=kotlin.contracts.ExperimentalContracts")
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ kotlin.incremental=true
ksp.incremental=false
ksp.useKSP2=true

projectVersion=1.9.5-mikbot-SNAPSHOT
projectVersion=1.9.6-mikbot-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.utils.MutableStringKeyedMap
import com.kotlindiscord.kord.extensions.utils.getLocale
import dev.kord.common.entity.ApplicationCommandType
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.core.event.interaction.MessageCommandInteractionCreateEvent
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
Expand Down Expand Up @@ -130,7 +131,9 @@ public abstract class MessageCommand<C : MessageCommandContext<C, M>, M : ModalF

val sentryId = context.sentry.captureThrowable(t) {
user = context.user.asUserOrNull()
channel = context.channel.asChannelOrNull()
if (context.event.interaction.authorizingIntegrationOwners.containsKey(ApplicationIntegrationType.GuildInstall)) {
channel = context.channel.asChannelOrNull()
}
}

val errorMessage = if (sentryId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ public abstract class SlashCommand<C : SlashCommandContext<*, A, M>, A : Argumen
kxLogger.trace { "Submitting error to sentry." }

val sentryId = context.sentry.captureThrowable(t) {
channel = context.channel.asChannelOrNull()
if (context.event.interaction.authorizingIntegrationOwners.containsKey(ApplicationIntegrationType.GuildInstall)) {
channel = context.channel.asChannelOrNull()
}
user = context.user.asUserOrNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public abstract class UserCommand<C : UserCommandContext<C, M>, M : ModalForm>(

val sentryId = context.sentry.captureThrowable(t) {
user = context.user.asUserOrNull()
channel = context.channel.asChannelOrNull()
if (context.event.interaction.authorizingIntegrationOwners.containsKey(ApplicationIntegrationType.GuildInstall)) {
channel = context.channel.asChannelOrNull()
}
}

val errorMessage = if (sentryId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.kotlindiscord.kord.extensions.components.types.HasPartialEmoji
import com.kotlindiscord.kord.extensions.sentry.BreadcrumbType
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.common.entity.DiscordPartialEmoji
import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import io.github.oshai.kotlinlogging.KLogger
Expand Down Expand Up @@ -72,7 +73,9 @@ public abstract class InteractionButtonWithAction<C : InteractionButtonContext,
logger.trace { "Submitting error to sentry." }

val sentryId = context.sentry.captureThrowable(t) {
channel = context.channel.asChannelOrNull()
if (context.event.interaction.authorizingIntegrationOwners.containsKey(ApplicationIntegrationType.GuildInstall)) {
channel = context.channel.asChannelOrNull()
}
user = context.user.asUserOrNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.sentry.BreadcrumbType
import com.kotlindiscord.kord.extensions.types.FailureReason
import com.kotlindiscord.kord.extensions.utils.scheduling.Task
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.core.event.interaction.SelectMenuInteractionCreateEvent
import io.github.oshai.kotlinlogging.KLogger
import io.github.oshai.kotlinlogging.KotlinLogging
Expand Down Expand Up @@ -93,7 +94,9 @@ public abstract class SelectMenu<C : SelectMenuContext, M : ModalForm>(
logger.trace { "Submitting error to sentry." }

val sentryId = context.sentry.captureThrowable(t) {
channel = context.channel.asChannelOrNull()
if (context.event.interaction.authorizingIntegrationOwners.containsKey(ApplicationIntegrationType.GuildInstall)) {
channel = context.channel.asChannelOrNull()
}
user = context.user.asUserOrNull()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public suspend fun main() {
}

applicationCommands {
defaultGuild(TEST_SERVER_ID)
}

intents {
Expand All @@ -61,31 +60,31 @@ public suspend fun main() {
}

extensions {
web {
hostname = "localhost:8080"
siteTitle = "KordEx Testing"

oauth {
clientId = env("OAUTH_CLIENT_ID")
clientSecret = env("OAUTH_CLIENT_SECRET")
}
}
// web {
// hostname = "localhost:8080"
// siteTitle = "KordEx Testing"
//
// oauth {
// clientId = env("OAUTH_CLIENT_ID")
// clientSecret = env("OAUTH_CLIENT_SECRET")
// }
// }

help {
paginatorTimeout = 30
}

extPhishing {
logChannelName = "alerts"
}

if (envOrNull("PLURALKIT_TESTING") != null) {
extPluralKit()
}

if (envOrNull("MAPPINGS_TESTING") != null) {
extMappings { }
}
// extPhishing {
// logChannelName = "alerts"
// }
//
// if (envOrNull("PLURALKIT_TESTING") != null) {
// extPluralKit()
// }
//
// if (envOrNull("MAPPINGS_TESTING") != null) {
// extMappings { }
// }

add(::ArgumentTestExtension)
add(::I18nTestExtension)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import com.kotlindiscord.kord.extensions.commands.application.slash.publicSubCom
import com.kotlindiscord.kord.extensions.components.*
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import dev.kord.common.entity.ApplicationIntegrationType
import dev.kord.common.entity.ChannelType
import dev.kord.common.entity.InteractionContextType
import dev.kord.core.behavior.channel.asChannelOf
import dev.kord.core.entity.channel.TextChannel

Expand All @@ -22,6 +24,8 @@ public class SelectorTestExtension : Extension() {
publicSlashCommand {
name = "selector"
description = "Test selectors."
allowedContexts.addAll(InteractionContextType.entries)
allowedInstallTypes.addAll(ApplicationIntegrationType.entries)

publicSubCommand {
name = "public"
Expand Down

0 comments on commit d542182

Please sign in to comment.