mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-22 13:46:13 +08:00
Add ContactOrBot.inferMessageSourceKind
This commit is contained in:
parent
e826c94546
commit
05aa3c8026
@ -13,6 +13,7 @@ import kotlinx.coroutines.CompletableDeferred
|
|||||||
import kotlinx.coroutines.Deferred
|
import kotlinx.coroutines.Deferred
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
import kotlinx.coroutines.withTimeoutOrNull
|
import kotlinx.coroutines.withTimeoutOrNull
|
||||||
|
import net.mamoe.mirai.Bot
|
||||||
import net.mamoe.mirai.contact.*
|
import net.mamoe.mirai.contact.*
|
||||||
import net.mamoe.mirai.event.EventPriority
|
import net.mamoe.mirai.event.EventPriority
|
||||||
import net.mamoe.mirai.event.GlobalEventChannel
|
import net.mamoe.mirai.event.GlobalEventChannel
|
||||||
@ -51,6 +52,17 @@ import net.mamoe.mirai.message.data.*
|
|||||||
import net.mamoe.mirai.utils.castOrNull
|
import net.mamoe.mirai.utils.castOrNull
|
||||||
import net.mamoe.mirai.utils.currentTimeSeconds
|
import net.mamoe.mirai.utils.currentTimeSeconds
|
||||||
|
|
||||||
|
internal fun ContactOrBot.inferMessageSourceKind(): MessageSourceKind {
|
||||||
|
return when (this) {
|
||||||
|
is Group -> MessageSourceKind.GROUP
|
||||||
|
is Friend -> MessageSourceKind.FRIEND
|
||||||
|
is Member -> MessageSourceKind.TEMP
|
||||||
|
is Stranger -> MessageSourceKind.STRANGER
|
||||||
|
is Bot -> MessageSourceKind.FRIEND
|
||||||
|
else -> error("Unsupported contact: $this")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 处理 mirai 消息系统 `Message` 到协议数据结构的转换.
|
* 处理 mirai 消息系统 `Message` 到协议数据结构的转换.
|
||||||
*
|
*
|
||||||
@ -62,13 +74,7 @@ internal abstract class SendMessageHandler<C : Contact> {
|
|||||||
|
|
||||||
val messageSourceKind: MessageSourceKind
|
val messageSourceKind: MessageSourceKind
|
||||||
get() {
|
get() {
|
||||||
return when (contact) {
|
return contact.inferMessageSourceKind()
|
||||||
is Group -> MessageSourceKind.GROUP
|
|
||||||
is Friend -> MessageSourceKind.FRIEND
|
|
||||||
is Member -> MessageSourceKind.TEMP
|
|
||||||
is Stranger -> MessageSourceKind.STRANGER
|
|
||||||
else -> error("Unsupported contact: $contact")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val bot get() = contact.bot.asQQAndroidBot()
|
val bot get() = contact.bot.asQQAndroidBot()
|
||||||
|
Loading…
Reference in New Issue
Block a user