mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-12 14:00:12 +08:00
Rename getQQ
to getFriend
Add deprecation message
This commit is contained in:
parent
102da76a32
commit
d3d7e530a9
@ -33,7 +33,7 @@ internal abstract class QQAndroidBotBase constructor(
|
|||||||
|
|
||||||
val selfQQ: QQ by lazy { QQ(uin) }
|
val selfQQ: QQ by lazy { QQ(uin) }
|
||||||
|
|
||||||
override fun getQQ(id: Long): QQ {
|
override fun getFriend(id: Long): QQ {
|
||||||
return qqs.delegate.filteringGetOrAdd({ it.id == id }, { QQImpl(this as QQAndroidBot, coroutineContext, id) })
|
return qqs.delegate.filteringGetOrAdd({ it.id == id }, { QQImpl(this as QQAndroidBot, coroutineContext, id) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ internal class QQAndroidBotNetworkHandler(bot: QQAndroidBot) : BotNetworkHandler
|
|||||||
totalFriendCount = data.totalFriendCount
|
totalFriendCount = data.totalFriendCount
|
||||||
data.friendList.forEach {
|
data.friendList.forEach {
|
||||||
// atomic add
|
// atomic add
|
||||||
bot.qqs.delegate.addLast(bot.getQQ(it.friendUin).also {
|
bot.qqs.delegate.addLast(bot.getFriend(it.friendUin).also {
|
||||||
currentFriendCount++
|
currentFriendCount++
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -123,14 +123,11 @@ internal class MessageSvc {
|
|||||||
|
|
||||||
val messages = resp.uinPairMsgs.asSequence().filterNot { it.msg == null }.flatMap { it.msg!!.asSequence() }.mapNotNull {
|
val messages = resp.uinPairMsgs.asSequence().filterNot { it.msg == null }.flatMap { it.msg!!.asSequence() }.mapNotNull {
|
||||||
when (it.msgHead.msgType) {
|
when (it.msgHead.msgType) {
|
||||||
166 -> {
|
166 -> FriendMessage(
|
||||||
FriendMessage(
|
bot,
|
||||||
bot,
|
bot.getFriend(it.msgHead.fromUin),
|
||||||
false, // TODO: 2020/1/29 PREVIOUS??
|
it.msgBody.richText.toMessageChain()
|
||||||
bot.getQQ(it.msgHead.fromUin),
|
)
|
||||||
it.msgBody.richText.toMessageChain()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
@ -176,7 +173,7 @@ internal class MessageSvc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
data class Failed(val errorCode: Int, val errorMessage: String) : Response() {
|
data class Failed(val errorCode: Int, val errorMessage: String) : Response() {
|
||||||
override fun toString(): String = "MessageSvc.PbSendMsg.Response.FAILED(errorCode=$errorCode, errorMessage=$errorMessage"
|
override fun toString(): String = "MessageSvc.PbSendMsg.Response.Failed(errorCode=$errorCode, errorMessage=$errorMessage"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,7 +221,7 @@ internal class MessageSvc {
|
|||||||
///return@buildOutgoingUniPacket
|
///return@buildOutgoingUniPacket
|
||||||
writeProtoBuf(
|
writeProtoBuf(
|
||||||
MsgSvc.PbSendMsgReq.serializer(), MsgSvc.PbSendMsgReq(
|
MsgSvc.PbSendMsgReq.serializer(), MsgSvc.PbSendMsgReq(
|
||||||
routingHead = MsgSvc.RoutingHead(grp = MsgSvc.Grp(groupCode = groupCode)), // TODO: 2020/1/30 确认这里是 id 还是 internalId
|
routingHead = MsgSvc.RoutingHead(grp = MsgSvc.Grp(groupCode = groupCode)),
|
||||||
contentHead = MsgComm.ContentHead(pkgNum = 1, divSeq = seq),
|
contentHead = MsgComm.ContentHead(pkgNum = 1, divSeq = seq),
|
||||||
msgBody = ImMsgBody.MsgBody(
|
msgBody = ImMsgBody.MsgBody(
|
||||||
richText = ImMsgBody.RichText(
|
richText = ImMsgBody.RichText(
|
||||||
|
@ -58,9 +58,15 @@ abstract class Bot : CoroutineScope {
|
|||||||
abstract val qqs: ContactList<QQ>
|
abstract val qqs: ContactList<QQ>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取一个好友对象. 若没有这个好友, 则会抛出异常[NoSuchElementException]
|
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
|
||||||
*/
|
*/
|
||||||
abstract fun getQQ(id: Long): QQ
|
@Deprecated(message = "这个函数有歧义. 它获取的是好友, 却名为 getQQ", replaceWith = ReplaceWith("getFriend(id)"))
|
||||||
|
fun getQQ(id: Long): QQ = getFriend(id)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个好友对象. 若没有这个好友, 则会抛出异常 [NoSuchElementException]
|
||||||
|
*/
|
||||||
|
abstract fun getFriend(id: Long): QQ
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
* 构造一个 [QQ] 对象. 它持有对 [Bot] 的弱引用([WeakRef]).
|
||||||
@ -133,8 +139,8 @@ abstract class Bot : CoroutineScope {
|
|||||||
|
|
||||||
// region extensions
|
// region extensions
|
||||||
|
|
||||||
fun Int.qq(): QQ = getQQ(this.toLong())
|
fun Int.qq(): QQ = getFriend(this.toLong())
|
||||||
fun Long.qq(): QQ = getQQ(this)
|
fun Long.qq(): QQ = getFriend(this)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +11,7 @@ import net.mamoe.mirai.data.Profile
|
|||||||
/**
|
/**
|
||||||
* QQ 对象.
|
* QQ 对象.
|
||||||
* 注意: 一个 [QQ] 实例并不是独立的, 它属于一个 [Bot].
|
* 注意: 一个 [QQ] 实例并不是独立的, 它属于一个 [Bot].
|
||||||
* 它不能被直接构造. 任何时候都应从 [Bot.getQQ] 或事件中获取.
|
* 它不能被直接构造. 任何时候都应从 [Bot.getFriend] 或事件中获取.
|
||||||
*
|
*
|
||||||
* 对于同一个 [Bot] 任何一个人的 [QQ] 实例都是单一的.
|
* 对于同一个 [Bot] 任何一个人的 [QQ] 实例都是单一的.
|
||||||
*
|
*
|
||||||
|
@ -23,7 +23,7 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot {
|
|||||||
@UseExperimental(MiraiInternalAPI::class)
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
override fun getQQs(): List<BlockingQQ> = bot.qqs.delegate.toList().map { it.blocking() }
|
override fun getQQs(): List<BlockingQQ> = bot.qqs.delegate.toList().map { it.blocking() }
|
||||||
|
|
||||||
override fun getQQ(id: Long): BlockingQQ = bot.getQQ(id).blocking()
|
override fun getQQ(id: Long): BlockingQQ = bot.getFriend(id).blocking()
|
||||||
@UseExperimental(MiraiInternalAPI::class)
|
@UseExperimental(MiraiInternalAPI::class)
|
||||||
override fun getGroups(): List<BlockingGroup> = bot.groups.delegate.toList().map { it.blocking() }
|
override fun getGroups(): List<BlockingGroup> = bot.groups.delegate.toList().map { it.blocking() }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user