Repository: sealdice/sealdice-core (language: go)

Issue:
[Bug]: 仅限于 gocq 适配器，在未初始化的群中触发“戳一戳”事件时报错
如题，原因是

https://github.com/sealdice/sealdice-core/blob/2b6335cdd5a5f8e010a2ce564078865ba742c5f9/dice/im_helpers.go#L117-L119

如果未获取到 GroupInfo 直接返回 nil，而在 packTempCtx 中并没有做 nil 检查

https://github.com/sealdice/sealdice-core/blob/2b6335cdd5a5f8e010a2ce564078865ba742c5f9/dice/platform_adapter_gocq.go#L1264



Discussion / hints:
本来想在这里补上初始化的逻辑，但是发现一个久远的 TODO

https://github.com/sealdice/sealdice-core/blob/2b6335cdd5a5f8e010a2ce564078865ba742c5f9/dice/platform_adapter_gocq.go#L542-L543

不太熟悉这里的逻辑，担心直接修改出问题，目前倾向于打个日志后不再继续执行就算 fix 了

Fix patch:
diff --git a/dice/platform_adapter_gocq.go b/dice/platform_adapter_gocq.go
index e8693aab..ab32790f 100644
--- a/dice/platform_adapter_gocq.go
+++ b/dice/platform_adapter_gocq.go
@@ -1342,16 +1342,28 @@ func (pa *PlatformAdapterGocq) packTempCtx(msgQQ *MessageQQ, msg *Message) *MsgC
 			ctx.Player.Name = d.Nickname
 			ctx.Player.UpdatedAtTime = time.Now().Unix()
 		}
-		SetTempVars(ctx, ctx.Player.Name)
+		SetTempVars(ctx, d.Nickname)
 	case "group":
-		d := pa.GetGroupMemberInfo(string(msgQQ.GroupID), string(msgQQ.UserID)) // 先获取个人信息，避免不存在id
+		d := pa.GetGroupMemberInfo(string(msgQQ.GroupID), string(msgQQ.UserID))
 		msg.Sender.UserID = FormatDiceIDQQ(string(msgQQ.UserID))
 		ctx.Group, ctx.Player = GetPlayerInfoBySender(ctx, msg)
+		if ctx.Group == nil {
+			gi := pa.GetGroupInfo(msg.GroupID, false)
+			ctx.Group = &GroupInfo{GroupID: msg.GroupID, GroupName: gi.GroupName}
+			ctx.Group.UpdatedAtTime = time.Now().Unix()
+		}
+		if ctx.Player == nil {
+			ctx.Player = &GroupPlayerInfo{UserID: msg.Sender.UserID}
+		}
 		if ctx.Player.Name == "" {
-			ctx.Player.Name = d.Card
+			if d.Card == "" {
+				ctx.Player.Name = d.Nickname
+			} else {
+				ctx.Player.Name = d.Card
+			}
 			ctx.Player.UpdatedAtTime = time.Now().Unix()
 		}
-		SetTempVars(ctx, ctx.Player.Name)
+		SetTempVars(ctx, d.Nickname)
 	}
 
 	return ctx


Test patch: