Misc improvements

This commit is contained in:
Him188 2020-02-22 21:12:10 +08:00
parent 7e3ede0de7
commit 7ffbccb9aa
2 changed files with 5 additions and 3 deletions

View File

@ -92,6 +92,8 @@ interface Contact : CoroutineScope {
override fun toString(): String
}
suspend inline fun Contact.sendMessage(message: Message) = sendMessage(message.toChain())
@Suppress("UNCHECKED_CAST")
suspend inline fun <C : Contact> C.sendMessage(message: Message): MessageReceipt<C> =
sendMessage(message.toChain()) as? MessageReceipt<C> ?: error("Internal class cast mistake")
suspend inline fun Contact.sendMessage(plain: String) = sendMessage(plain.toMessage())
suspend inline fun <C : Contact> C.sendMessage(plain: String): MessageReceipt<C> = sendMessage(plain.toMessage())

View File

@ -31,6 +31,7 @@ import java.io.OutputStream
import java.util.stream.Stream
import kotlin.streams.asStream
@UseExperimental(MiraiInternalAPI::class, MiraiExperimentalAPI::class)
internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
@MiraiInternalAPI
override fun getAccount(): BotAccount = bot.account
@ -51,7 +52,6 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
override fun getFriend(id: Long): BlockingQQ = bot.getFriend(id).blocking()
override fun queryGroupList(): Stream<Long> = runBlocking { bot.queryGroupList() }.asStream()
@UseExperimental(MiraiInternalAPI::class)
override fun getGroupList(): List<BlockingGroup> = bot.groups.delegate.toList().map { it.blocking() }
override fun queryGroupInfo(code: Long): GroupInfo = runBlocking { bot.queryGroupInfo(code) }