Skip to content

Commit 382d527

Browse files
committed
fix: not properly checking embed desc length
1 parent 1308a0a commit 382d527

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

build.gradle.kts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class DiscordWebhook(
9191
var defaultThumbnail: Boolean = true
9292
) {
9393

94+
companion object {
95+
private const val MAX_EMBED_DESCRIPTION_LENGTH = 4096
96+
}
97+
9498
var message: String = "content"
9599
var username: String = "BreweryX Updates"
96100
var avatarUrl: String = "https://github.com/breweryteam.png"
@@ -136,7 +140,7 @@ class DiscordWebhook(
136140
}
137141

138142
private fun createEmbeds(): List<JsonObject> {
139-
if (embedDescription.length <= 2000) {
143+
if (embedDescription.length <= MAX_EMBED_DESCRIPTION_LENGTH) {
140144
return listOf(JsonObject().apply {
141145
addProperty("title", embedTitle)
142146
addProperty("description", embedDescription)
@@ -156,8 +160,9 @@ class DiscordWebhook(
156160
val embeds = mutableListOf<JsonObject>()
157161
var description = embedDescription
158162
while (description.isNotEmpty()) {
159-
val chunk = description.substring(0, 2000)
160-
description = description.substring(2000)
163+
val chunkLength = minOf(MAX_EMBED_DESCRIPTION_LENGTH, description.length)
164+
val chunk = description.substring(0, chunkLength)
165+
description = description.substring(chunkLength)
161166
embeds.add(JsonObject().apply {
162167
addProperty("title", embedTitle)
163168
addProperty("description", chunk)

0 commit comments

Comments
 (0)