Skip to content

Commit

Permalink
Update deps, remove double launch, add Kord event filter
Browse files Browse the repository at this point in the history
  • Loading branch information
gdude2002 committed Sep 3, 2024
1 parent b99b0bd commit e42dde8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ junit = "5.11.0"
kaml = "0.61.0"
koin = "3.5.6"
kord = "0.15.0-SNAPSHOT"
ksp = "2.0.20-RC2-1.0.24"
ksp = "2.0.20-1.0.24"
ktor = "2.3.12"
kx-coro = "1.8.1"
kx-ser = "1.7.1"
kx-ser = "1.7.2"
linkie = "1.0.121"
logback = "1.5.7"
logback-groovy = "1.14.5"
Expand Down
14 changes: 12 additions & 2 deletions kord-extensions/src/main/kotlin/dev/kordex/core/ExtensibleBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,20 @@ public open class ExtensibleBot(

settings.cacheBuilder.dataCacheBuilder.invoke(kord, kord.cache)

kord.on<Event> {
kord.launch {
if (settings.kordEventFilter == null) {
logger.debug { "Kord event filter predicate not set." }

kord.on<Event> {
send(this@on)
}
} else {
logger.debug { "Kord event filter predicate set, filtering Kord events." }

kord.on<Event> {
if (settings.kordEventFilter!!(this@on)) {
send(this@on)
}
}
}

addDefaultExtensions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.ChannelBehavior
import dev.kord.core.builder.kord.KordBuilder
import dev.kord.core.entity.interaction.Interaction
import dev.kord.core.event.Event
import dev.kord.gateway.Intent
import dev.kord.gateway.Intents
import dev.kord.gateway.NON_PRIVILEGED
Expand Down Expand Up @@ -139,6 +140,9 @@ public open class ExtensibleBotBuilder {
@OptIn(InternalAPI::class)
public var dataCollectionMode: DataCollection = DATA_COLLECTION

/** @suppress Builder that shouldn't be set directly by the user. **/
public var kordEventFilter: (suspend Event.() -> Boolean)? = null

/** @suppress Builder that shouldn't be set directly by the user. **/
public open val extensionsBuilder: ExtensionsBuilder = ExtensionsBuilder()

Expand Down Expand Up @@ -197,6 +201,14 @@ public open class ExtensibleBotBuilder {
/** Logging level Koin should use, defaulting to ERROR. **/
public var koinLogLevel: Level = Level.ERROR

/**
* Set an event-filtering predicate, which may selectively prevent Kord events from being processed by returning
* `false`.
*/
public fun eventFilter(predicate: suspend Event.() -> Boolean) {
kordEventFilter = predicate
}

/**
* DSL function used to configure information about the bot.
*
Expand Down

0 comments on commit e42dde8

Please sign in to comment.