mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-24 23:20:09 +08:00
Kotlin coroutine
This commit is contained in:
parent
530fde980b
commit
3ce6096e83
@ -1,6 +1,5 @@
|
|||||||
package net.mamoe.mirai.network.handler
|
package net.mamoe.mirai.network.handler
|
||||||
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import net.mamoe.mirai.contact.Group
|
import net.mamoe.mirai.contact.Group
|
||||||
import net.mamoe.mirai.contact.QQ
|
import net.mamoe.mirai.contact.QQ
|
||||||
import net.mamoe.mirai.event.events.group.GroupMessageEvent
|
import net.mamoe.mirai.event.events.group.GroupMessageEvent
|
||||||
@ -31,9 +30,8 @@ class MessagePacketHandler(session: LoginSession) : PacketHandler(session) {
|
|||||||
init {
|
init {
|
||||||
//todo for test
|
//todo for test
|
||||||
FriendMessageEvent::class.hookWhile {
|
FriendMessageEvent::class.hookWhile {
|
||||||
return@hookWhile runBlocking {
|
|
||||||
if (session.socket.isClosed()) {
|
if (session.socket.isClosed()) {
|
||||||
return@runBlocking false
|
return@hookWhile false
|
||||||
}
|
}
|
||||||
when {
|
when {
|
||||||
it.message valueEquals "你好" -> it.sender.sendMessage("你好!")
|
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"))
|
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 {
|
GroupMessageEvent::class.hookWhile {
|
||||||
return@hookWhile runBlocking {
|
|
||||||
if (session.socket.isClosed()) {
|
if (session.socket.isClosed()) {
|
||||||
return@runBlocking false
|
return@hookWhile false
|
||||||
}
|
}
|
||||||
|
|
||||||
when {
|
when {
|
||||||
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
||||||
}
|
}
|
||||||
|
|
||||||
return@runBlocking true
|
return@hookWhile true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user