Skip to content

Commit aab8214

Browse files
committed
feat: Updated Discord WebHooks implementation to Components v2
1 parent 40c1b5f commit aab8214

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
group = io.github._4drian3d
2-
version = 3.2.3
2+
version = 3.2.4-SNAPSHOT
33
description = A simple Velocity plugin to catch the client version

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bstats = { module = "org.bstats:bstats-velocity", version.ref = "bstats" }
2222
configurate-kotlin = { module = "org.spongepowered:configurate-extra-kotlin", version.ref = "configurate" }
2323
miniplaceholders-api = { group = "io.github.miniplaceholders", name = "miniplaceholders-api", version.ref = "miniplaceholders" }
2424
miniplaceholders-kotlin = { group = "io.github.miniplaceholders", name = "miniplaceholders-kotlin-ext", version.ref = "miniplaceholders" }
25-
jdwebhooks = { group = "io.github.4drian3d", name = "jdwebhooks", version = "1.1.0" }
25+
jdwebhooks = { group = "io.github.4drian3d", name = "jdwebhooks", version = "2.0.0" }
2626

2727
[plugins]
2828

src/main/kotlin/io/github/_4drian3d/clientcatcher/ClientCatcher.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import io.github._4drian3d.clientcatcher.configuration.Messages
1616
import io.github._4drian3d.clientcatcher.configuration.load
1717
import io.github._4drian3d.clientcatcher.listener.BrandListener
1818
import io.github._4drian3d.clientcatcher.listener.ModListener
19-
import io.github._4drian3d.jdwebhooks.WebHookClient
19+
import io.github._4drian3d.jdwebhooks.webhook.WebHookClient
2020
import net.kyori.adventure.text.logger.slf4j.ComponentLogger
2121
import org.bstats.velocity.Metrics
2222
import java.nio.file.Path
@@ -64,7 +64,7 @@ class ClientCatcher @Inject constructor(
6464
}
6565
}
6666

67-
fun loadConfig() = CompletableFuture.supplyAsync {
67+
fun loadConfig(): CompletableFuture<Boolean> = CompletableFuture.supplyAsync {
6868
configuration = load(path)
6969
messages = load(path)
7070
if ((configuration.webHook.client.enabled || configuration.webHook.mods.enabled) && webHookClient == null) {

src/main/kotlin/io/github/_4drian3d/clientcatcher/Extensions.kt

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import com.velocitypowered.api.proxy.ConsoleCommandSource
55
import com.velocitypowered.api.proxy.ProxyServer
66
import io.github._4drian3d.clientcatcher.configuration.Configuration
77
import io.github._4drian3d.clientcatcher.webhook.Replacer
8-
import io.github._4drian3d.jdwebhooks.Embed
9-
import io.github._4drian3d.jdwebhooks.WebHook
8+
import io.github._4drian3d.jdwebhooks.component.Component
9+
import io.github._4drian3d.jdwebhooks.component.SeparatorComponent.Spacing
10+
import io.github._4drian3d.jdwebhooks.webhook.WebHookExecution
1011
import io.github.miniplaceholders.api.MiniPlaceholders
1112
import net.kyori.adventure.text.logger.slf4j.ComponentLogger
1213
import net.kyori.adventure.text.minimessage.MiniMessage
@@ -75,21 +76,26 @@ fun sendWebHook(plugin: ClientCatcher, replacer: Replacer, config: Configuration
7576
val client = plugin.webHookClient
7677
if (client != null && config.enabled) {
7778
CompletableFuture.supplyAsync {
78-
val builder = WebHook.builder()
79-
.content(replacer.replace(config.content))
79+
val builder = WebHookExecution.builder()
8080
.username(replacer.replace(config.username))
8181
.avatarURL(config.avatarURL)
8282
val embedConfig = config.embed
83-
builder.embed(
84-
Embed.builder()
85-
.fields(embedConfig.fields.map {
86-
Embed.Field(it.inline, replacer.replace(it.name), replacer.replace(it.value))
87-
})
88-
.title(replacer.replace(embedConfig.title))
89-
.description(replacer.replace(embedConfig.description))
90-
.build()
91-
)
92-
builder.build()
93-
}.thenCompose { client.sendWebHook(it) }
83+
builder.component(Component.textDisplay(replacer.replace(config.content)))
84+
val containerBuilder = Component.container()
85+
.components(
86+
Component.textDisplay("## " + replacer.replace(embedConfig.title)),
87+
Component.textDisplay(replacer.replace(embedConfig.description))
88+
)
89+
.component(Component.separator().divider(true).spacing(Spacing.SMALL).build())
90+
embedConfig.fields.map {
91+
containerBuilder
92+
.component(
93+
Component.textDisplay("### " + replacer.replace(it.name))
94+
)
95+
.component(Component.textDisplay(replacer.replace(it.value)))
96+
}
97+
98+
builder.components(containerBuilder.build()).build()
99+
}.thenCompose { client.executeWebHook(it) }
94100
}
95101
}

src/main/kotlin/io/github/_4drian3d/clientcatcher/configuration/Configuration.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Configuration {
133133
var enabled = false
134134
var content = "Content"
135135
var username = "ClientCatcher"
136-
var avatarURL = "https://cdn.modrinth.com/data/Dhqd1a7j/0a4240c54efdcabcd18e7ff47aaffdb79a7c92fd.png"
136+
var avatarURL = "https://cdn.modrinth.com/data/Dhqd1a7j/ac20497103cb4b3cce6bf85e553bca4e4e7a2209.webp"
137137
var embed = Embed()
138138

139139
@ConfigSerializable
@@ -146,7 +146,6 @@ class Configuration {
146146

147147
@ConfigSerializable
148148
class Field {
149-
var inline = false
150149
var name = "Name"
151150
var value = "<player>"
152151
}

0 commit comments

Comments
 (0)