mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-04 15:40:13 +08:00
Move queryProfile from Bot to IMirai and add User.queryProfile
This commit is contained in:
parent
8da048af63
commit
8e2e259618
@ -39,8 +39,6 @@ public abstract interface class net/mamoe/mirai/Bot : kotlinx/coroutines/Corouti
|
||||
public abstract fun login (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun nudge ()Lnet/mamoe/mirai/message/action/BotNudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/Nudge;
|
||||
public fun queryProfile (J)Lnet/mamoe/mirai/data/UserProfile;
|
||||
public abstract fun queryProfile (JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
}
|
||||
|
||||
public final class net/mamoe/mirai/Bot$Companion {
|
||||
@ -118,6 +116,8 @@ public abstract interface class net/mamoe/mirai/IMirai : net/mamoe/mirai/LowLeve
|
||||
public fun muteAnonymousMember (Lnet/mamoe/mirai/Bot;Ljava/lang/String;Ljava/lang/String;JI)V
|
||||
public fun queryImageUrl (Lnet/mamoe/mirai/Bot;Lnet/mamoe/mirai/message/data/Image;)Ljava/lang/String;
|
||||
public abstract fun queryImageUrl (Lnet/mamoe/mirai/Bot;Lnet/mamoe/mirai/message/data/Image;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun queryProfile (Lnet/mamoe/mirai/Bot;J)Lnet/mamoe/mirai/data/UserProfile;
|
||||
public abstract fun queryProfile (Lnet/mamoe/mirai/Bot;JLkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun recallFriendMessageRaw (Lnet/mamoe/mirai/Bot;J[I[II)Z
|
||||
public fun recallGroupMessageRaw (Lnet/mamoe/mirai/Bot;J[I[I)Z
|
||||
public fun recallGroupTempMessageRaw (Lnet/mamoe/mirai/Bot;JJ[I[II)Z
|
||||
@ -205,6 +205,7 @@ public abstract interface class net/mamoe/mirai/contact/AnonymousMember : net/ma
|
||||
public fun nudge ()Lnet/mamoe/mirai/message/action/MemberNudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/Nudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/UserNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun uploadImage (Lnet/mamoe/mirai/utils/ExternalResource;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
@ -367,6 +368,7 @@ public abstract interface class net/mamoe/mirai/contact/Friend : kotlinx/corouti
|
||||
public fun nudge ()Lnet/mamoe/mirai/message/action/FriendNudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/Nudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/UserNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
@ -430,6 +432,7 @@ public abstract interface class net/mamoe/mirai/contact/Member : net/mamoe/mirai
|
||||
public fun mute (I)V
|
||||
public abstract fun mute (ILkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public abstract fun nudge ()Lnet/mamoe/mirai/message/action/MemberNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public abstract fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public abstract fun sendMessage (Lnet/mamoe/mirai/message/data/Message;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun uploadImage (Lnet/mamoe/mirai/utils/ExternalResource;)Lnet/mamoe/mirai/message/data/Image;
|
||||
@ -483,6 +486,7 @@ public abstract interface class net/mamoe/mirai/contact/NormalMember : net/mamoe
|
||||
public fun nudge ()Lnet/mamoe/mirai/message/action/MemberNudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/Nudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/UserNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
@ -562,6 +566,7 @@ public abstract interface class net/mamoe/mirai/contact/Stranger : kotlinx/corou
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/Nudge;
|
||||
public fun nudge ()Lnet/mamoe/mirai/message/action/StrangerNudge;
|
||||
public synthetic fun nudge ()Lnet/mamoe/mirai/message/action/UserNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
@ -570,6 +575,7 @@ public abstract interface class net/mamoe/mirai/contact/Stranger : kotlinx/corou
|
||||
}
|
||||
|
||||
public abstract interface class net/mamoe/mirai/contact/TempUser : net/mamoe/mirai/contact/User {
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun uploadImage (Lnet/mamoe/mirai/utils/ExternalResource;)Lnet/mamoe/mirai/message/data/Image;
|
||||
@ -580,6 +586,8 @@ public abstract interface class net/mamoe/mirai/contact/User : kotlinx/coroutine
|
||||
public abstract fun getNick ()Ljava/lang/String;
|
||||
public abstract fun getRemark ()Ljava/lang/String;
|
||||
public abstract fun nudge ()Lnet/mamoe/mirai/message/action/UserNudge;
|
||||
public fun queryProfile ()Lnet/mamoe/mirai/data/UserProfile;
|
||||
public fun queryProfile (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Ljava/lang/String;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
public fun sendMessage (Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public fun sendMessage (Lnet/mamoe/mirai/message/data/Message;)Lnet/mamoe/mirai/message/MessageReceipt;
|
||||
|
@ -17,14 +17,12 @@ package net.mamoe.mirai
|
||||
import kotlinx.coroutines.*
|
||||
import net.mamoe.kjbb.JvmBlockingBridge
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.UserProfile
|
||||
import net.mamoe.mirai.event.EventChannel
|
||||
import net.mamoe.mirai.event.events.BotEvent
|
||||
import net.mamoe.mirai.message.action.BotNudge
|
||||
import net.mamoe.mirai.message.action.MemberNudge
|
||||
import net.mamoe.mirai.network.LoginFailedException
|
||||
import net.mamoe.mirai.utils.BotConfiguration
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
@ -174,15 +172,6 @@ public interface Bot : CoroutineScope, ContactOrBot, UserOrBot {
|
||||
public override fun nudge(): BotNudge = BotNudge(this)
|
||||
|
||||
|
||||
/**
|
||||
* 查询某个用户的信息
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@MiraiExperimentalApi
|
||||
@JvmBlockingBridge
|
||||
public suspend fun queryProfile(targetId: Long): UserProfile
|
||||
|
||||
/**
|
||||
* 关闭这个 [Bot], 立即取消 [Bot] 的 [SupervisorJob], 取消与这个 [Bot] 相关的所有有协程联系的任务.
|
||||
*
|
||||
|
@ -17,6 +17,7 @@ import io.ktor.client.*
|
||||
import io.ktor.client.engine.okhttp.*
|
||||
import net.mamoe.kjbb.JvmBlockingBridge
|
||||
import net.mamoe.mirai.contact.*
|
||||
import net.mamoe.mirai.data.UserProfile
|
||||
import net.mamoe.mirai.event.events.BotInvitedJoinGroupRequestEvent
|
||||
import net.mamoe.mirai.event.events.MemberJoinRequestEvent
|
||||
import net.mamoe.mirai.event.events.NewFriendRequestEvent
|
||||
@ -145,6 +146,14 @@ public interface IMirai : LowLevelApiAccessor {
|
||||
@JvmBlockingBridge
|
||||
public suspend fun queryImageUrl(bot: Bot, image: Image): String
|
||||
|
||||
/**
|
||||
* 查询某个用户的信息
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
@JvmBlockingBridge
|
||||
public suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile
|
||||
|
||||
/**
|
||||
* 构造一个 [OfflineMessageSource].
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Mamoe Technologies and contributors.
|
||||
* Copyright 2019-2021 Mamoe Technologies and contributors.
|
||||
*
|
||||
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
|
||||
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
|
||||
@ -14,6 +14,8 @@ package net.mamoe.mirai.contact
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import net.mamoe.kjbb.JvmBlockingBridge
|
||||
import net.mamoe.mirai.Bot
|
||||
import net.mamoe.mirai.Mirai
|
||||
import net.mamoe.mirai.data.UserProfile
|
||||
import net.mamoe.mirai.event.events.EventCancelledException
|
||||
import net.mamoe.mirai.event.events.UserMessagePostSendEvent
|
||||
import net.mamoe.mirai.event.events.UserMessagePreSendEvent
|
||||
@ -87,6 +89,14 @@ public interface User : Contact, UserOrBot, CoroutineScope {
|
||||
* @see Nudge.sendTo 发送这个戳一戳消息
|
||||
*/
|
||||
public override fun nudge(): UserNudge
|
||||
|
||||
/**
|
||||
* 查询用户信息
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
@JvmBlockingBridge
|
||||
public suspend fun queryProfile(): UserProfile = Mirai.queryProfile(bot, this.id)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,9 @@ package net.mamoe.mirai.data
|
||||
|
||||
import net.mamoe.mirai.utils.MiraiExperimentalApi
|
||||
|
||||
/**
|
||||
* 用户详细资料
|
||||
*/
|
||||
@MiraiExperimentalApi
|
||||
public interface UserProfile {
|
||||
public val nickname: String
|
||||
@ -27,6 +30,7 @@ public interface UserProfile {
|
||||
public enum class Sex {
|
||||
MALE,
|
||||
FEMALE,
|
||||
|
||||
/** 保密 */
|
||||
UNKNOWN;
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import net.mamoe.mirai.internal.network.protocol.packet.chat.*
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.voice.PttStore
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.list.FriendList
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.login.StatSvc
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard
|
||||
import net.mamoe.mirai.internal.utils.io.serialization.toByteArray
|
||||
import net.mamoe.mirai.message.MessageSerializers
|
||||
import net.mamoe.mirai.message.action.Nudge
|
||||
@ -910,6 +911,13 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor {
|
||||
else -> error("Internal error: unsupported image class: ${image::class.simpleName}")
|
||||
}
|
||||
|
||||
override suspend fun queryProfile(bot: Bot, targetId: Long): UserProfile {
|
||||
bot.asQQAndroidBot().network.apply {
|
||||
return SummaryCard.ReqSummaryCard(bot.client, targetId)
|
||||
.sendAndExpect<SummaryCard.ReqSummaryCard.RespSummaryCard>()
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun sendNudge(bot: Bot, nudge: Nudge, receiver: Contact): Boolean {
|
||||
if (bot.configuration.protocol != BotConfiguration.MiraiProtocol.ANDROID_PHONE) {
|
||||
throw UnsupportedOperationException("nudge is supported only with protocol ANDROID_PHONE")
|
||||
|
@ -26,7 +26,6 @@ import net.mamoe.mirai.internal.message.*
|
||||
import net.mamoe.mirai.internal.network.QQAndroidBotNetworkHandler
|
||||
import net.mamoe.mirai.internal.network.QQAndroidClient
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.chat.*
|
||||
import net.mamoe.mirai.internal.network.protocol.packet.summarycard.SummaryCard
|
||||
import net.mamoe.mirai.message.data.*
|
||||
import net.mamoe.mirai.network.LoginFailedException
|
||||
import net.mamoe.mirai.utils.*
|
||||
@ -111,12 +110,6 @@ internal class QQAndroidBot constructor(
|
||||
return groups.firstOrNull { it.checkIsGroupImpl(); it.uin == uin }
|
||||
}
|
||||
|
||||
override suspend fun queryProfile(targetId: Long): UserProfile {
|
||||
network.apply {
|
||||
return SummaryCard.ReqSummaryCard(client, targetId)
|
||||
.sendAndExpect<SummaryCard.ReqSummaryCard.RespSummaryCard>()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 获取群公告 所需的 bkn 参数
|
||||
|
Loading…
Reference in New Issue
Block a user