From 894ad95d73ebd8997c80e7a110b8a5bc28d27c79 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Wed, 16 Oct 2024 19:23:49 +0200 Subject: [PATCH] Move logic into alreadyHandled function --- main.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 693b70b..63b45e0 100644 --- a/main.go +++ b/main.go @@ -49,10 +49,10 @@ func tickGameStart(c *sn.Client) { continue } - if exists, err := db.ItemHasReply(n.Item.Id, meId); err != nil { + if handled, err := alreadyHandled(n.Item.Id); err != nil { log.Printf("failed to check for existing reply to game start in item %d: %v\n", n.Item.Id, err) continue - } else if exists { + } else if handled { // TODO: check if move changed log.Printf("reply to game start in item %d already exists\n", n.Item.Id) continue @@ -98,10 +98,10 @@ func tickGameProgress(c *sn.Client) { continue } - if exists, err := db.ItemHasReply(n.Item.Id, meId); err != nil { + if handled, err := alreadyHandled(n.Item.Id); err != nil { log.Printf("failed to check for existing reply to game update in item %d: %v\n", n.Item.Id, err) continue - } else if exists { + } else if handled { // TODO: check if move changed log.Printf("reply to game update in item %d already exists\n", n.Item.Id) continue @@ -296,3 +296,7 @@ func isRecent(t time.Time) bool { x := time.Now().Add(-30 * time.Second) return t.After(x) } + +func alreadyHandled(id int) (bool, error) { + return db.ItemHasReply(id, meId) +}