use coroutines

This commit is contained in:
Simplxs 2024-02-26 18:51:05 +08:00
parent 3e03d4782d
commit 210609bd7b
No known key found for this signature in database
GPG Key ID: 8BD9E2834B275BD3

View File

@ -3,6 +3,7 @@ package moe.fuqiuluo.shamrock.remote.action.handlers
import com.tencent.qqnt.kernel.nativeinterface.MsgConstant
import com.tencent.qqnt.kernel.nativeinterface.MsgRecord
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonElement
@ -23,8 +24,6 @@ import moe.fuqiuluo.shamrock.tools.asString
import moe.fuqiuluo.shamrock.tools.json
import moe.fuqiuluo.shamrock.tools.jsonArray
import moe.fuqiuluo.symbols.OneBotHandler
import java.util.Timer
import kotlin.concurrent.timerTask
@OneBotHandler(".handle_quick_operation_async")
internal object QuickOperation : IActionHandler() {
@ -87,9 +86,10 @@ internal object QuickOperation : IActionHandler() {
if (MsgConstant.KCHATTYPEGROUP == record.chatType && operation["delete"].asBooleanOrNull == true) {
val duration = operation["delay"].asIntOrNull
if (duration != null) {
Timer().schedule(timerTask {
GlobalScope.launch { MsgSvc.recallMsg(msgHash) }
}, duration.toLong())
GlobalScope.launch {
delay(duration.toLong())
MsgSvc.recallMsg(msgHash)
}
} else {
MsgSvc.recallMsg(msgHash)
}