Add extensions for getting instances of QQ and Group

This commit is contained in:
Him188 2019-12-04 19:15:28 +08:00
parent fe3cb837a5
commit b9fdb2e50e
2 changed files with 16 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import net.mamoe.mirai.message.internal.readMessageChain
import net.mamoe.mirai.network.protocol.tim.packet.PacketVersion
import net.mamoe.mirai.network.protocol.tim.packet.action.ImageLink
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.internal.coerceAtLeastOrFail
import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.withSession
import kotlin.jvm.JvmName
@ -90,6 +91,16 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : EventPacket
// endregion
suspend inline fun At.qq(): QQ = bot.getQQ(this.target)
suspend inline fun Int.qq(): QQ = bot.getQQ(this.coerceAtLeastOrFail(0).toUInt())
suspend inline fun Long.qq(): QQ = bot.getQQ(this.coerceAtLeastOrFail(0))
suspend inline fun UInt.qq(): QQ = bot.getQQ(this)
suspend inline fun Int.group(): Group = bot.getGroup(this.coerceAtLeastOrFail(0).toUInt())
suspend inline fun Long.group(): Group = bot.getGroup(this.coerceAtLeastOrFail(0))
suspend inline fun UInt.group(): Group = bot.getGroup(GroupId(this))
suspend inline fun GroupId.group(): Group = bot.getGroup(this)
suspend inline fun GroupInternalId.group(): Group = bot.getGroup(this)
}
// region group message

View File

@ -9,7 +9,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import net.mamoe.mirai.*
import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotAccount
import net.mamoe.mirai.addFriend
import net.mamoe.mirai.alsoLogin
import net.mamoe.mirai.contact.MemberPermission
import net.mamoe.mirai.contact.mute
import net.mamoe.mirai.event.Subscribable
@ -89,7 +92,7 @@ suspend fun main() {
startsWith("profile", removePrefix = true) {
val account = it.trim()
if (account.isNotEmpty()) {
bot.getQQ(account.toUInt())
account.toUInt().qq()
} else {
sender
}.queryProfile().toString().reply()