Skip to content

Commit

Permalink
Add logging for uninitialized botAsMember on creating new GroupImpl…
Browse files Browse the repository at this point in the history
… instance. helps #1776
  • Loading branch information
Him188 committed Jan 14, 2022
1 parent 7d39712 commit 4a32f03
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 4a32f03

Please sign in to comment.