0

Fix Fwdcnt zero value handling in message parsing

- Change Fwdcnt type from int64 to *int64 in rMsg struct
- Use pointer to properly distinguish between 'not provided' (nil) and explicit 0
- Update all Fwdcnt usages to dereference pointer
This commit is contained in:
eleksir
2026-03-30 01:51:35 +03:00
parent 97b337db31
commit b661d42074
2 changed files with 8 additions and 7 deletions

View File

@@ -69,9 +69,10 @@ func MsgParser(ctx context.Context, msg string) {
j.Misc.Csign = Config.Csign
}
// j.Misc.Fwdcnt если нам его не передали, то будет 0.
if exist := j.Misc.Fwdcnt; exist == 0 {
j.Misc.Fwdcnt = 1
// j.Misc.Fwdcnt если нам его не передали, то будет nil.
if j.Misc.Fwdcnt == nil {
j.Misc.Fwdcnt = new(int64)
*j.Misc.Fwdcnt = 1
}
// j.Misc.GoodMorning может быть 1 или 0, по-умолчанию 0.
@@ -81,13 +82,13 @@ func MsgParser(ctx context.Context, msg string) {
// Отвалидировались, теперь вернёмся к нашим баранам.
// Если у нас циклическая пересылка сообщения, попробуем её тут разорвать, отбросив сообщение.
if j.Misc.Fwdcnt > Config.ForwardsMax {
if *j.Misc.Fwdcnt > Config.ForwardsMax {
log.Warnf("Discarding msg with fwd_cnt exceeding max value: %s", msg)
return
}
j.Misc.Fwdcnt++
*j.Misc.Fwdcnt++
// Классифицирем входящие сообщения. Первым делом, попробуем определить команды.
if len(j.Message) >= len(j.Misc.Csign) && j.Message[0:len(j.Misc.Csign)] == j.Misc.Csign {
@@ -211,7 +212,7 @@ func MsgParser(ctx context.Context, msg string) {
message.Message = j.Message
message.Plugin = j.Plugin
message.Mode = j.Mode
message.Misc.Fwdcnt = j.Misc.Fwdcnt
message.Misc.Fwdcnt = *j.Misc.Fwdcnt
message.Misc.Csign = j.Misc.Csign
message.Misc.Username = j.Misc.Username
message.Misc.Answer = j.Misc.Answer

View File

@@ -52,7 +52,7 @@ type rMsg struct {
Answer int64 `json:"answer,omitempty"`
Botnick string `json:"bot_nick,omitempty"`
Csign string `json:"csign,omitempty"`
Fwdcnt int64 `json:"fwd_cnt,omitempty"`
Fwdcnt *int64 `json:"fwd_cnt,omitempty"`
GoodMorning int64 `json:"good_morning,omitempty"`
Msgformat int64 `json:"msg_format,omitempty"`
Username string `json:"username,omitempty"`