Skip to content

Commit

Permalink
feat: catch regex compile errors for custom spam hider and notify
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Dec 17, 2023
1 parent 317ca22 commit cf54512
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package gg.skytils.skytilsmod.gui.components

import gg.essential.api.EssentialAPI
import gg.essential.elementa.UIComponent
import gg.essential.elementa.components.UIBlock
import gg.essential.elementa.components.UIContainer
Expand All @@ -37,6 +38,7 @@ import gg.essential.vigilance.gui.settings.CheckboxComponent
import gg.essential.vigilance.gui.settings.DropDown
import gg.skytils.skytilsmod.features.impl.handlers.SpamHider
import gg.skytils.skytilsmod.utils.toTitleCase
import java.awt.Color

/**
* Based on Vigilance under LGPL 3.0 license
Expand Down Expand Up @@ -114,7 +116,16 @@ class CustomFilterComponent(filter: SpamHider.Filter, dropDown: DropDown) : UICo
grabWindowFocus()
}.onFocusLost {
if ((this as UITextInput).getText() == "") return@onFocusLost
filter.regex = this.getText().replace("", "§").toRegex()
filter.regex = this.getText().replace("", "§").let { text ->
runCatching {
filterName.setColor(VigilancePalette.getBrightText())
text.toRegex()
}.getOrElse {
filterName.setColor(VigilancePalette.getTextWarning())
EssentialAPI.getNotifications().push("Invalid Regex", """${it.message}""".trimIndent(), 3000f)
Regex.escape(text).toRegex()
}
}
}

val skyblockOnly by CheckboxComponent(filter.skyblockOnly)
Expand Down

0 comments on commit cf54512

Please sign in to comment.