-
Notifications
You must be signed in to change notification settings - Fork 1
/
FakeMessage.kt
62 lines (47 loc) · 1.64 KB
/
FakeMessage.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package io.noties.blog.gradientmessenger
import io.noties.adapt.Item
import java.util.*
class FakeMessage(private val random: Random) {
private companion object {
// a set of emojis
val EMOJIS = listOf(
String(Character.toChars(0x1F601)),
String(Character.toChars(0x1F602)),
String(Character.toChars(0x1F603)),
String(Character.toChars(0x1F604)),
String(Character.toChars(0x1F605)),
String(Character.toChars(0x1F606)),
String(Character.toChars(0x1F607)))
const val MAX_WORDS = 19
const val MAX_CHARS_IN_WORD = 9
}
fun create(): Item<*> {
val words = random.nextInt(MAX_WORDS)
val builder = StringBuilder()
if (words > 0) {
for (word in 0 until words) {
if (word > 0) {
builder.append(' ')
}
val length = random.nextInt(MAX_CHARS_IN_WORD) + 1
val array = CharArray(length)
for (char in 0 until length) {
array[char] = (97 + random.nextInt(26)).toChar()
}
builder.append(array)
}
}
// add emoji
if (words == 0 || random.nextBoolean()) {
val length = random.nextInt(4) + 1
for (i in 0 until length) {
builder.append(EMOJIS[random.nextInt(EMOJIS.size)])
}
}
val message = builder.toString()
return when (random.nextBoolean()) {
true -> Me(message)
else -> You(message)
}
}
}