From 0314f192ea5413fde97c1ae7b8783dcbd3bb0de9 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 19 Jun 2020 21:44:10 +0200 Subject: [PATCH] test get stash --- bot.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index 48c2d63..82cb0bb 100644 --- a/bot.go +++ b/bot.go @@ -1074,6 +1074,11 @@ func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) { } func botGetStash(m *ChatWarsMessage, r *regexp.Regexp) { + var ( + userID64 uint64 = 0 + userBusyUntil time.Time + ) + if hasUnfinishedJob(cacheObjSubType[`job_get_stash`]) { c := TGCommand{ Type: commandReplyMsg, @@ -1097,6 +1102,14 @@ func botGetStash(m *ChatWarsMessage, r *regexp.Regexp) { if c.Active { p.ClientCount++ p.ClientID64 = append(p.ClientID64, c.TGUserID64) + if userID64 == 0 { + userID64 = c.TGUserID64 + userBusyUntil = c.CWBusyUntil + } else if userBusyUntil.After(c.CWBusyUntil) { + userID64 = c.TGUserID64 + userBusyUntil = c.CWBusyUntil + } + if c.CWBusyUntil.After(busy) { busy = c.CWBusyUntil } @@ -1104,9 +1117,19 @@ func botGetStash(m *ChatWarsMessage, r *regexp.Regexp) { } muxClients.RUnlock() + if p.ClientCount == 0 { + c := TGCommand{ + Type: commandReplyMsg, + Text: "No clients online.", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + return + } b, _ := json.Marshal(p) t := time.Now().UTC().Add(1 * time.Second) - _, err := createJob(cacheObjSubType[`job_get_stash`], objJobPriority, userID64, 0, t, b) + _, err = createJob(cacheObjSubType[`job_get_stash`], objJobPriority, userID64, 0, t, b) if err != nil { c := TGCommand{