From 4a32f03797f8fa95292873f3015128bf2b760b0b Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 14 Jan 2022 18:45:10 +0000 Subject: [PATCH] Add logging for uninitialized `botAsMember` on creating new GroupImpl instance. helps #1776 --- .../commonMain/kotlin/contact/GroupImpl.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index 4b1d29795d1..bcda8acab19 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 Mamoe Technologies and contributors. + * Copyright 2019-2022 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. @@ -90,9 +90,26 @@ internal fun GroupImpl( this@Group.members.delegate.add(member) } } + }.apply { + if (!botAsMemberInitialized) { + logger.error( + contextualBugReportException("GroupImpl", """ + groupId: ${groupInfo.groupCode.takeIf { it != 0L } ?: id} + groupUin: ${groupInfo.uin} + membersCount: ${members.count()} + botId: ${bot.id} + owner: ${kotlin.runCatching { owner }.getOrNull()?.id} + """.trimIndent(), additional = "并告知此时 Bot 是否为群管理员或群主, 和是否刚刚加入或离开这个群" + ) + ) + } } } +private val logger by lazy { + MiraiLogger.Factory.create(GroupImpl::class.java, "Group") +} + @Suppress("PropertyName") internal class GroupImpl constructor( bot: QQAndroidBot, @@ -109,6 +126,7 @@ internal class GroupImpl constructor( override lateinit var owner: NormalMemberImpl override lateinit var botAsMember: NormalMemberImpl + internal val botAsMemberInitialized = ::botAsMember.isInitialized @Suppress("DEPRECATION") @Deprecated("Please use files instead.", replaceWith = ReplaceWith("files.root"), level = DeprecationLevel.WARNING)