Skip to content

Commit

Permalink
Allow disabling auto links
Browse files Browse the repository at this point in the history
  • Loading branch information
Erdragh committed Apr 27, 2024
1 parent e91bb5f commit a309731
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ object AstralBotConfig {
*/
val ENABLE_MARKDOWN_PARSING: ForgeConfigSpec.BooleanValue

/**
* Enables converting detected URLs into clickable links, requires
* [ENABLE_MARKDOWN_PARSING] to be enabled to do anything
*/
val ENABLE_AUTO_LINKS: ForgeConfigSpec.BooleanValue

init {
val builder = ForgeConfigSpec.Builder()

Expand Down Expand Up @@ -158,7 +164,9 @@ object AstralBotConfig {
}

ENABLE_MARKDOWN_PARSING = builder.comment("Parse Discord messages into Minecraft's Chat Components")
.define("enableMarkdownParsing", true)
.define(listOf("markdown", "enabled"), true)
ENABLE_AUTO_LINKS = builder.comment("Automatically convert detected URLs into clickable links")
.define(listOf("markdown", "autoLinks"), true)

SPEC = builder.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class ComponentRenderer : AbstractVisitor(), NodeRenderer {

val literal = text.literal

if (!AstralBotConfig.ENABLE_AUTO_LINKS.get()) {
append(literal)
return
}

val matcher = urlPattern.matcher(text.literal)
var lastEnd = 0
for (result in matcher.results()) {
Expand Down

0 comments on commit a309731

Please sign in to comment.