Skip to content

Commit

Permalink
Fixed bug with filters
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Aug 23, 2024
1 parent 898eef0 commit 68f07ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ abstract class Filter<T, V>(
): Boolean {
val cfg = config.config

val isInverted = config.isInverted ?: return true

return if (isInverted) {
return if (config.isInverted) {
!isMet(data, getValue(cfg, data, "not_$id"), config.compileData)
} else {
isMet(data, getValue(cfg, data, id), config.compileData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ import com.willfp.libreforge.triggers.TriggerData
class FilterBlock<T, V> internal constructor(
val filter: Filter<T, V>,
override val config: Config,
override val compileData: T
override val compileData: T,
val isInverted: Boolean
) : Compiled<T> {
val isInverted: Boolean? by lazy {
val cfg = config

val regularPresent = cfg.has(filter.id)
val inversePresent = cfg.has("not_${filter.id}")

if (!regularPresent && !inversePresent) {
null
} else {
inversePresent
}
}

fun isMet(data: TriggerData) =
filter.isMet(data, this)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,13 @@ object Filters : Registry<Filter<*, *>>() {
val blocks = mutableListOf<FilterBlock<*, *>>()

for (key in config.getKeys(false)) {
val filter = get(key) ?: get(key.removePrefix("not_")) ?: continue
blocks += makeBlock(filter, config, context) ?: continue
if (key.startsWith("not_")) {
val filter = get(key.removePrefix("not_")) ?: continue
blocks += makeBlock(filter, config, true, context) ?: continue
} else {
val filter = get(key) ?: continue
blocks += makeBlock(filter, config, false, context) ?: continue
}
}

return FilterList(blocks)
Expand All @@ -62,6 +67,7 @@ object Filters : Registry<Filter<*, *>>() {
private fun <T, V> makeBlock(
filter: Filter<T, V>,
config: Config,
inverted: Boolean,
context: ViolationContext
): FilterBlock<T, V>? {
if (filter.deprecationMessage != null) {
Expand All @@ -77,14 +83,14 @@ object Filters : Registry<Filter<*, *>>() {
return null
}

val configKey = if (config.has("not_${filter.id}")) {
val configKey = if (inverted) {
"not_${filter.id}"
} else {
filter.id
}

val compileData = filter.makeCompileData(config, context, filter.getValue(config, null, configKey))
return FilterBlock(filter, config, compileData)
return FilterBlock(filter, config, compileData, inverted)
}

init {
Expand Down

0 comments on commit 68f07ea

Please sign in to comment.