Skip to content

Commit

Permalink
fix: argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Nov 27, 2023
1 parent 0977091 commit 7d86f5d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions core/src/main/kotlin/com/mineinabyss/emojy/EmojyHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ fun Component.replaceEmoteIds(player: Player? = null, insert: Boolean = true): C
var msg = GlobalTranslator.render(this, player?.locale() ?: Locale.US)
val serialized = msg.serialize()

emojy.emotes.filter { ":${it.id}.*:".toRegex() in serialized && it.checkPermission(player) }.forEach { emote ->
val colorable = ":${emote.id}\\|(c|colorable):".toRegex() in serialized
val bitmapIndex = ":${emote.id}\\|([0-9]+):".toRegex().find(serialized)?.groupValues?.get(1)?.toIntOrNull() ?: -1
emojy.emotes.filter { ":${it.id}(\\|.*?)?:".toRegex() in serialized && it.checkPermission(player) }.forEach { emote ->
val matches = ":${emote.id}(\\|(c|colorable|\\d+))*:".toRegex().findAll(serialized)
matches.forEach { match ->
val colorable = "\\|(c|colorable)".toRegex() in match.value
val bitmapIndex = "\\|([0-9]+)".toRegex().find(match.value)?.groupValues?.get(1)?.toIntOrNull() ?: -1

msg = msg.replaceText(
TextReplacementConfig.builder()
.match(":${emote.id}.*:")
.replacement(emote.formattedUnicode(insert = insert, colorable = colorable, bitmapIndex = bitmapIndex))
.build()
)
val replacement = emote.formattedUnicode(insert = insert, colorable = colorable, bitmapIndex = bitmapIndex)
msg = msg.replaceText(
TextReplacementConfig.builder()
.matchLiteral(match.value)
.replacement(replacement)
.build()
)
}
}

emojy.gifs.filter { ":${it.id}:" in serialized && it.checkPermission(player) }.forEach { gif ->
Expand Down

0 comments on commit 7d86f5d

Please sign in to comment.