Commit b9fdb2e5 authored by Him188's avatar Him188

Add extensions for getting instances of QQ and Group

parent fe3cb837
...@@ -17,6 +17,7 @@ import net.mamoe.mirai.message.internal.readMessageChain ...@@ -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.PacketVersion
import net.mamoe.mirai.network.protocol.tim.packet.action.ImageLink import net.mamoe.mirai.network.protocol.tim.packet.action.ImageLink
import net.mamoe.mirai.utils.* import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.internal.coerceAtLeastOrFail
import net.mamoe.mirai.utils.io.* import net.mamoe.mirai.utils.io.*
import net.mamoe.mirai.withSession import net.mamoe.mirai.withSession
import kotlin.jvm.JvmName import kotlin.jvm.JvmName
...@@ -90,6 +91,16 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : EventPacket ...@@ -90,6 +91,16 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : EventPacket
// endregion // endregion
suspend inline fun At.qq(): QQ = bot.getQQ(this.target) 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 // region group message
......
...@@ -9,7 +9,10 @@ import kotlinx.coroutines.GlobalScope ...@@ -9,7 +9,10 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext 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.MemberPermission
import net.mamoe.mirai.contact.mute import net.mamoe.mirai.contact.mute
import net.mamoe.mirai.event.Subscribable import net.mamoe.mirai.event.Subscribable
...@@ -89,7 +92,7 @@ suspend fun main() { ...@@ -89,7 +92,7 @@ suspend fun main() {
startsWith("profile", removePrefix = true) { startsWith("profile", removePrefix = true) {
val account = it.trim() val account = it.trim()
if (account.isNotEmpty()) { if (account.isNotEmpty()) {
bot.getQQ(account.toUInt()) account.toUInt().qq()
} else { } else {
sender sender
}.queryProfile().toString().reply() }.queryProfile().toString().reply()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment