mirror of
https://github.com/dalbodeule/chibot-chzzk-bot.git
synced 2025-06-08 23:08:20 +00:00
Compare commits
2 Commits
1465716e72
...
30d5edc5fe
Author | SHA1 | Date | |
---|---|---|---|
|
30d5edc5fe | ||
|
0709b8f526 |
@ -1,7 +1,9 @@
|
|||||||
package space.mori.chzzk_bot.chatbot.chzzk
|
package space.mori.chzzk_bot.chatbot.chzzk
|
||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.koin.java.KoinJavaComponent.inject
|
import org.koin.java.KoinJavaComponent.inject
|
||||||
@ -25,6 +27,7 @@ import xyz.r2turntrue.chzzk4j.types.channel.live.ChzzkLiveStatus
|
|||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import java.net.SocketTimeoutException
|
import java.net.SocketTimeoutException
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
import java.nio.charset.Charset
|
||||||
|
|
||||||
object ChzzkHandler {
|
object ChzzkHandler {
|
||||||
private val handlers = mutableListOf<UserHandler>()
|
private val handlers = mutableListOf<UserHandler>()
|
||||||
@ -325,7 +328,21 @@ class UserHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.limitUtf8Length(maxBytes: Int): String {
|
||||||
|
val bytes = this.toByteArray(Charset.forName("UTF-8"))
|
||||||
|
if (bytes.size <= maxBytes) return this
|
||||||
|
var truncatedString = this
|
||||||
|
while (truncatedString.toByteArray(Charset.forName("UTF-8")).size > maxBytes) {
|
||||||
|
truncatedString = truncatedString.substring(0, truncatedString.length - 1)
|
||||||
|
}
|
||||||
|
return truncatedString
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(DelicateCoroutinesApi::class)
|
||||||
internal fun sendChat(msg: String) {
|
internal fun sendChat(msg: String) {
|
||||||
client.sendChatToLoggedInChannel(msg)
|
GlobalScope.launch {
|
||||||
|
delay(100L)
|
||||||
|
client.sendChatToLoggedInChannel(msg.limitUtf8Length(100))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user