1
0
mirror of https://github.com/mamoe/mirai.git synced 2025-04-05 07:10:11 +08:00

Deprecate IMirai.calculateGroupUinByGroupCode, and migrate usages to getUin. Close

This commit is contained in:
Him188 2021-10-30 13:43:40 +01:00
parent 790f37ce05
commit 767475f9ab
4 changed files with 10 additions and 3 deletions
mirai-core-api/src/commonMain/kotlin
mirai-core/src
commonMain/kotlin/message
commonTest/kotlin/notice

View File

@ -113,6 +113,7 @@ public interface IMirai : LowLevelApiAccessor {
*/
public fun getUin(contactOrBot: ContactOrBot): Long {
return if (contactOrBot is Group)
@Suppress("DEPRECATION")
calculateGroupUinByGroupCode(contactOrBot.id)
else contactOrBot.id
}
@ -121,6 +122,10 @@ public interface IMirai : LowLevelApiAccessor {
* 使用 groupCode 计算 groupUin. 这两个值仅在 mirai 内部协议区分, 一般人使用时无需在意.
* @see getUin
*/
@Deprecated(
"The result might be wrong. Consider using getUin",
level = DeprecationLevel.WARNING
) // deprecated since 2.8.0-RC, see #1479
public fun calculateGroupUinByGroupCode(groupCode: Long): Long {
var left: Long = groupCode / 1000000L
when (left) {

View File

@ -17,9 +17,9 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.serialization.Serializable
import net.mamoe.mirai.Bot
import net.mamoe.mirai.Mirai
import net.mamoe.mirai.contact.*
import net.mamoe.mirai.event.asyncFromEventOrNull
import net.mamoe.mirai.internal.contact.uin
import net.mamoe.mirai.internal.network.notice.group.GroupMessageProcessor.SendGroupMessageReceipt
import net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody
import net.mamoe.mirai.internal.network.protocol.data.proto.MsgComm
@ -200,7 +200,7 @@ internal class OnlineMessageSourceToGroupImpl(
ImMsgBody.SourceMsg(
origSeqs = sequenceIds,
senderUin = fromId,
toUin = Mirai.calculateGroupUinByGroupCode(targetId),
toUin = target.uin,
flag = 1,
elems = elements,
type = 0,
@ -211,7 +211,7 @@ internal class OnlineMessageSourceToGroupImpl(
srcMsg = MsgComm.Msg(
msgHead = MsgComm.MsgHead(
fromUin = fromId, // qq
toUin = Mirai.calculateGroupUinByGroupCode(targetId), // group
toUin = target.uin, // group
msgType = 82, // 82?
c2cCmd = 1,
msgSeq = sequenceIds.single(),

View File

@ -134,6 +134,7 @@ internal class Desensitizer private constructor(
rules.forEach { (t, u) ->
if (t.toLongOrNull() != null && u.toLongOrNull() != null) {
addExtraRulesForNumber(t.toLong(), u.toLong())
@Suppress("DEPRECATION")
addExtraRulesForNumber(
Mirai.calculateGroupUinByGroupCode(t.toLong()),
Mirai.calculateGroupUinByGroupCode(u.toLong())

View File

@ -150,6 +150,7 @@ internal interface GroupExtensions {
val impl = GroupImpl(
bot.cast(), coroutineContext, id,
GroupInfo(
@Suppress("DEPRECATION")
Mirai.calculateGroupUinByGroupCode(id), owner, id, memo, name, allowMemberInvite,
allowAnonymousChat, autoApprove, confessTalk, muteAll, botMuteTimestamp
),