From 011619983832f9032382b08bbdc6cdf9716621cc Mon Sep 17 00:00:00 2001 From: Cilly Leang Date: Tue, 17 Feb 2026 22:45:01 +1100 Subject: [PATCH] fix(Scout): fix discord's has filter typo also refactored a few things into `fix...()` methods instead --- .../kotlin/moe/lava/awoocord/scout/Scout.kt | 75 ++++++++++++------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/plugins/Scout/src/main/kotlin/moe/lava/awoocord/scout/Scout.kt b/plugins/Scout/src/main/kotlin/moe/lava/awoocord/scout/Scout.kt index 50e99e6..a197429 100644 --- a/plugins/Scout/src/main/kotlin/moe/lava/awoocord/scout/Scout.kt +++ b/plugins/Scout/src/main/kotlin/moe/lava/awoocord/scout/Scout.kt @@ -107,12 +107,14 @@ class Scout : Plugin() { override fun start(context: Context) { extendFilterType() extendHasAnswerOption() + fixFiltersKeying() + fixHasFilterSuggestion() + fixSearchPadding() patchHasAnswerOption() patchHasNode() patchQuery() patchQueryParser() patchSearchUI(context) - patchSearchPadding() patchThreadSupport() patchUsernameDiscriminator() } @@ -226,6 +228,49 @@ class Scout : Plugin() { origHasAnswerOptions = null } + // Patch to key filters properly for smoother recycling + // Thank u discord for keying every filter type the same thing!! /s + private fun fixFiltersKeying() { + patcher.instead( + "getFilterItem", + FilterSuggestion::class.java, + ) { (_, suggestion: FilterSuggestion) -> + SingleTypePayload(suggestion, suggestion.filterType.name, 2) // 2 = WidgetSearchSuggestionsAdapter.TYPE_FILTER + } + } + + // YES DISCORD TYPO'ED THIS HAHAHAHAHAHAFAUHFAIUFHAIFBHUKFHYRISFSUOIRN + private fun fixHasFilterSuggestion() { + patcher.before( + "getStringRepresentation", + FilterType::class.java, + SearchStringProvider::class.java, + ) { (param, filter: FilterType, provider: SearchStringProvider) -> + if (filter == FilterType.HAS) { + param.result = provider.hasFilterString + ":" + } + } + } + + // Patch out the gigantic padding in search results + private fun fixSearchPadding() { + patcher.after("onViewBound", View::class.java) { + view?.run { + fitsSystemWindows = false + setPadding(paddingLeft, 16.dp, paddingRight, paddingBottom) + } + } + + patcher.after("onViewBound", View::class.java) { + // Being a bit sneaky and reset the expanded flag here + optionsExpanded = false + view?.run { + fitsSystemWindows = false + setPadding(paddingLeft, 16.dp, paddingRight, paddingBottom) + } + } + } + // Patches various methods that use HasAnswerOption to include our new options private fun patchHasAnswerOption() { patcher.before( @@ -604,15 +649,6 @@ class Scout : Plugin() { } ) - // Patch to key filters properly for smoother recycling - // Thank u discord for keying every filter type the same thing!! /s - patcher.instead( - "getFilterItem", - FilterSuggestion::class.java, - ) { (_, suggestion: FilterSuggestion) -> - SingleTypePayload(suggestion, suggestion.filterType.name, 2) // 2 = WidgetSearchSuggestionsAdapter.TYPE_FILTER - } - // Patch to manually configure expander, need to do this to update the suggestions widget patcher.before( "onConfigure", @@ -666,25 +702,6 @@ class Scout : Plugin() { } } - // Patch out the gigantic padding in search results - private fun patchSearchPadding() { - patcher.after("onViewBound", View::class.java) { - view?.run { - fitsSystemWindows = false - setPadding(paddingLeft, 16.dp, paddingRight, paddingBottom) - } - } - - patcher.after("onViewBound", View::class.java) { - // Being a bit sneaky and reset the expanded flag here - optionsExpanded = false - view?.run { - fitsSystemWindows = false - setPadding(paddingLeft, 16.dp, paddingRight, paddingBottom) - } - } - } - // Adds support for searching in threads private fun patchThreadSupport() { // Patch query parser for in: to support names with spaces, by wrapping them in quotes