Guard group active-level fetch in name card serialization

member.active.temperature relies on OneBot pulling group honor data,
which throws "Error code: 2" when the upstream is busy/unavailable. That
access sat outside the existing title try/catch, so a failure propagated
through getSystemPrompt -> onMessage and aborted the entire reply.

Wrap the active.temperature access in its own try/catch and degrade
gracefully (omit the lv segment) instead of breaking the whole turn.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-21 20:15:34 +08:00
parent a29cf17361
commit ebb1fbe10c

View File

@@ -1023,11 +1023,16 @@ object JChatGPT : KotlinPlugin(
}
private fun getNameCard(member: Member): String {
val nameCard = StringBuilder()
// 群活跃等级
nameCard.append("【lv").append(member.active.temperature)
val nameCard = StringBuilder("")
// 群活跃等级active 依赖 OneBot 拉取群荣誉数据,繁忙/失败时会抛 "Error code: 2"
// 必须兜底,否则整次回复都会因取名片失败而中断。
try {
nameCard.append("lv").append(member.active.temperature).append(' ')
} catch (e: Throwable) {
logger.warning("获取群活跃等级失败", e)
}
// 真实群身份:始终按实际权限显示,不会被专属头衔覆盖
nameCard.append(' ').append(
nameCard.append(
when (member.permission) {
OWNER -> "群主"
ADMINISTRATOR -> "管理员"