From 3a637bc684c0f0c2daab66f0c522497da36cd65d Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 7 Feb 2020 11:53:55 +0800 Subject: [PATCH] update job shops --- job.go | 22 +++++++++++++++++++++- obj.go | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/job.go b/job.go index 7aaab59..b9a22e0 100644 --- a/job.go +++ b/job.go @@ -2206,9 +2206,29 @@ func jobShops(j Job) { err = json.Unmarshal(j.Payload, &p) logOnError(err, "jobShops : Unmarshal payload") + out := fmt.Sprintf("Shop summary:\n") + for _, m := range p.Msgs { + rule, err := getMsgParsingRule(m) + logOnError(err, "jobShopsSlave : getMsgParsingRule") + if rule.MsgTypeID64 == cacheObjSubType[`msg_shop_main_ack`] { + cwm, err := parseSubTypeMessageShopMainAck(m, rule.re) + logOnError(err, "jobShops : parseSubTypeMessageShopMainAck") + if cwm.Open { + out = fmt.Sprintf("%s ✔️", out) + } else { + out = fmt.Sprintf("%s ❌", out) + } + c := getObjCastle(cwm.CastleID64) + out = fmt.Sprintf("%s%s", out, c.Logo) + out = fmt.Sprintf("%s%s", out, cwm.Link, cwm.User) + out = fmt.Sprintf("%s [%d/%d]\n", out, cwm.Mana, cwm.ManaTotal) + } + clientDelTGMsg(m.TGUserID64, m.ID64, m.ChatID64) + } + c := TGCommand{ Type: commandReplyMsg, - Text: "Done", + Text: out, FromMsgID64: p.MsgID64, FromChatID64: p.ChatID64, ParseMode: cmdParseModeHTML, diff --git a/obj.go b/obj.go index 61d2c81..32779a8 100644 --- a/obj.go +++ b/obj.go @@ -486,8 +486,19 @@ func addObjCastle(logo string, name string) (int64, error) { return objId, nil } -func getObjCastleID(s string) int64 { - if v, ok := cacheObjCastle.Load(s); ok { +func getObjCastle(i interface{}) ChatWarsCastle { + if v, ok := cacheObjCastle.Load(i); ok { + c := v.(ChatWarsCastle) + return c + } else { + v, _ := cacheObjCastle.Load(`⛔`) + c := v.(ChatWarsCastle) + return c + } +} + +func getObjCastleID(i interface{}) int64 { + if v, ok := cacheObjCastle.Load(i); ok { c := v.(ChatWarsCastle) return c.ObjID64 } else { @@ -495,7 +506,6 @@ func getObjCastleID(s string) int64 { c := v.(ChatWarsCastle) return c.ObjID64 } - } func loadObjCastle() error {