mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 17:20:11 +08:00
Kotlin coroutine
This commit is contained in:
parent
530fde980b
commit
3ce6096e83
@ -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,45 +30,41 @@ class MessagePacketHandler(session: LoginSession) : PacketHandler(session) {
|
||||
init {
|
||||
//todo for test
|
||||
FriendMessageEvent::class.hookWhile {
|
||||
return@hookWhile runBlocking {
|
||||
if (session.socket.isClosed()) {
|
||||
return@runBlocking false
|
||||
}
|
||||
when {
|
||||
it.message valueEquals "你好" -> it.sender.sendMessage("你好!")
|
||||
it.message.toString().startsWith("复读") -> it.sender.sendMessage(it.message())
|
||||
it.message.toString().startsWith("发群") -> {
|
||||
it.message().list.toMutableList().let { messages ->
|
||||
messages.removeAt(0)
|
||||
sendGroupMessage(Group(session.bot, 580266363), MessageChain(messages))
|
||||
}
|
||||
}
|
||||
/*it.message valueEquals "发图片群" -> sendGroupMessage(Group(session.bot, 580266363), PlainText("test") + UnsolvedImage(File("C:\\Users\\Him18\\Desktop\\faceImage_1559564477775.jpg")).also { image ->
|
||||
image.upload(session, Group(session.bot, 580266363)).get()
|
||||
})*/
|
||||
it.message valueEquals "发图片群2" -> sendGroupMessage(Group(session.bot, 580266363), Image("{7AA4B3AA-8C3C-0F45-2D9B-7F302A0ACEAA}.jpg").toChain())
|
||||
/* it.message valueEquals "发图片" -> sendFriendMessage(it.sender, PlainText("test") + UnsolvedImage(File("C:\\Users\\Him18\\Desktop\\faceImage_1559564477775.jpg")).also { image ->
|
||||
image.upload(session, it.sender).get()
|
||||
})*/
|
||||
it.message valueEquals "发图片2" -> sendFriendMessage(it.sender, PlainText("test") + Image("{7AA4B3AA-8C3C-0F45-2D9B-7F302A0ACEAA}.jpg"))
|
||||
}
|
||||
|
||||
return@runBlocking true
|
||||
if (session.socket.isClosed()) {
|
||||
return@hookWhile false
|
||||
}
|
||||
when {
|
||||
it.message valueEquals "你好" -> it.sender.sendMessage("你好!")
|
||||
it.message.toString().startsWith("复读") -> it.sender.sendMessage(it.message())
|
||||
it.message.toString().startsWith("发群") -> {
|
||||
it.message().list.toMutableList().let { messages ->
|
||||
messages.removeAt(0)
|
||||
sendGroupMessage(Group(session.bot, 580266363), MessageChain(messages))
|
||||
}
|
||||
}
|
||||
/*it.message valueEquals "发图片群" -> sendGroupMessage(Group(session.bot, 580266363), PlainText("test") + UnsolvedImage(File("C:\\Users\\Him18\\Desktop\\faceImage_1559564477775.jpg")).also { image ->
|
||||
image.upload(session, Group(session.bot, 580266363)).get()
|
||||
})*/
|
||||
it.message valueEquals "发图片群2" -> sendGroupMessage(Group(session.bot, 580266363), Image("{7AA4B3AA-8C3C-0F45-2D9B-7F302A0ACEAA}.jpg").toChain())
|
||||
/* it.message valueEquals "发图片" -> sendFriendMessage(it.sender, PlainText("test") + UnsolvedImage(File("C:\\Users\\Him18\\Desktop\\faceImage_1559564477775.jpg")).also { image ->
|
||||
image.upload(session, it.sender).get()
|
||||
})*/
|
||||
it.message valueEquals "发图片2" -> sendFriendMessage(it.sender, PlainText("test") + Image("{7AA4B3AA-8C3C-0F45-2D9B-7F302A0ACEAA}.jpg"))
|
||||
}
|
||||
|
||||
return@hookWhile true
|
||||
}
|
||||
|
||||
GroupMessageEvent::class.hookWhile {
|
||||
return@hookWhile runBlocking {
|
||||
if (session.socket.isClosed()) {
|
||||
return@runBlocking false
|
||||
}
|
||||
|
||||
when {
|
||||
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
||||
}
|
||||
|
||||
return@runBlocking true
|
||||
if (session.socket.isClosed()) {
|
||||
return@hookWhile false
|
||||
}
|
||||
|
||||
when {
|
||||
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
||||
}
|
||||
|
||||
return@hookWhile true
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user