mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-09 09:50:16 +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,45 +30,41 @@ 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@hookWhile false
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
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 {
|
GroupMessageEvent::class.hookWhile {
|
||||||
return@hookWhile runBlocking {
|
if (session.socket.isClosed()) {
|
||||||
if (session.socket.isClosed()) {
|
return@hookWhile false
|
||||||
return@runBlocking false
|
|
||||||
}
|
|
||||||
|
|
||||||
when {
|
|
||||||
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
|
||||||
}
|
|
||||||
|
|
||||||
return@runBlocking true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when {
|
||||||
|
it.message.contains("复读") -> it.group.sendMessage(it.chain)
|
||||||
|
}
|
||||||
|
|
||||||
|
return@hookWhile true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user