Kotlin coroutine

This commit is contained in:
Him188moe 2019-09-22 20:07:18 +08:00
parent 530fde980b
commit 3ce6096e83

View File

@ -1,6 +1,5 @@
package net.mamoe.mirai.network.handler
import kotlinx.coroutines.runBlocking
import net.mamoe.mirai.contact.Group
import net.mamoe.mirai.contact.QQ
import net.mamoe.mirai.event.events.group.GroupMessageEvent
@ -31,9 +30,8 @@ class MessagePacketHandler(session: LoginSession) : PacketHandler(session) {
init {
//todo for test
FriendMessageEvent::class.hookWhile {
return@hookWhile runBlocking {
if (session.socket.isClosed()) {
return@runBlocking false
return@hookWhile false
}
when {
it.message valueEquals "你好" -> it.sender.sendMessage("你好!")
@ -54,22 +52,19 @@ class MessagePacketHandler(session: LoginSession) : PacketHandler(session) {
it.message valueEquals "发图片2" -> sendFriendMessage(it.sender, PlainText("test") + Image("{7AA4B3AA-8C3C-0F45-2D9B-7F302A0ACEAA}.jpg"))
}
return@runBlocking true
}
return@hookWhile true
}
GroupMessageEvent::class.hookWhile {
return@hookWhile runBlocking {
if (session.socket.isClosed()) {
return@runBlocking false
return@hookWhile false
}
when {
it.message.contains("复读") -> it.group.sendMessage(it.chain)
}
return@runBlocking true
}
return@hookWhile true
}
}