Adding secret emojis to reactions

This commit is contained in:
Vitor Pamplona
2025-03-05 18:24:03 -05:00
parent 8722f37fa5
commit 9cd73c2663
7 changed files with 225 additions and 16 deletions

View File

@@ -106,4 +106,27 @@ object EmojiCoder {
val decodedArray = ByteArray(decoded.size) { decoded[it].toByte() }
return String(decodedArray, Charsets.UTF_8)
}
@JvmStatic
fun cropToFirstMessage(text: String): String {
val decoded = mutableListOf<Int>()
var i = 0
while (i < text.length) {
val codePoint = text.codePointAt(i)
val byte = fromVariationSelector(codePoint)
if (byte == null && decoded.isNotEmpty()) {
break
} else if (byte == null) {
i += Character.charCount(codePoint) // Advance index by correct number of chars
continue
}
decoded.add(byte)
i += Character.charCount(codePoint) // Advance index by correct number of chars
}
return text.substring(0, i)
}
}

View File

@@ -38,6 +38,7 @@ class EmojiCoderTest {
)
val HELLO_WORLD = "\uD83D\uDE00\uDB40\uDD38\uDB40\uDD55\uDB40\uDD5C\uDB40\uDD5C\uDB40\uDD5F\uDB40\uDD1C\uDB40\uDD10\uDB40\uDD47\uDB40\uDD5F\uDB40\uDD62\uDB40\uDD5C\uDB40\uDD54\uDB40\uDD11"
val HELLO_WORLD_WITH_EXTRAS = HELLO_WORLD + "askfasdf"
}
@Test
@@ -55,6 +56,11 @@ class EmojiCoderTest {
assertEquals("Hello, World!", EmojiCoder.decode(HELLO_WORLD))
}
@Test
fun testCrop() {
assertEquals(HELLO_WORLD, EmojiCoder.cropToFirstMessage(HELLO_WORLD_WITH_EXTRAS))
}
@Test
fun testEncodeDecode() {
for (emoji in EMOJI_LIST) {