From e8d0fd3b447d383636064072bc39adf6f46f2c1f Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 3 Feb 2020 12:06:41 +0800 Subject: [PATCH] test tributes --- data/code_obj_sub_type.json | 10 ++++++++++ data/msg_rules.json | 16 ++++++++++++++++ def.go | 12 ++++++++++++ msg.go | 16 ++++++++++++++++ workers.go | 4 ++++ 5 files changed, 58 insertions(+) diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index a341410..5d3d67c 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -154,6 +154,16 @@ "name": "Tribute acknowledged", "obj_type": "msg" }, + { + "intl_id": "msg_tributes_stats_req", + "name": "Tribute Stats req", + "obj_type": "msg" + }, + { + "intl_id": "msg_tributes_stats_ack", + "name": "Tribute Stats ack", + "obj_type": "msg" + }, { "intl_id": "msg_auction_announce", "name": "Auction announce", diff --git a/data/msg_rules.json b/data/msg_rules.json index 9d72b51..427e20d 100644 --- a/data/msg_rules.json +++ b/data/msg_rules.json @@ -1854,5 +1854,21 @@ "msg_type": "msg_inspect_ack", "chat_id": 0, "user_id": 0 + }, + { + "prio": 5000, + "descn": "Tributes stats req", + "rule": "^/tributes$", + "msg_type": "msg_tributes_stats_req", + "chat_id": 0, + "user_id": 0 + }, + { + "prio": 5000, + "descn": "Tributes stats ack", + "rule": "^([1-9]{2} [a-zA-Z]+ [0-9]{4} [0-9]{2}:[0-9]{2} - [a-zA-Z]+ x [0-9]+, [0-9]+🔥(\n){0,1})+$", + "msg_type": "msg_tributes_stats_req", + "chat_id": 0, + "user_id": 0 } ] \ No newline at end of file diff --git a/def.go b/def.go index bd6f75a..06f7e70 100644 --- a/def.go +++ b/def.go @@ -345,6 +345,18 @@ type ChatWarsMessageJobGWithdrawAck struct { Ref string `json:"ref"` } +type ChatWarsTribute struct { + Date Time.time `json:"time"` + ItemID64 int64 `json:"item_id"` + Quantity int64 `json:"quantity"` + Exp int64 `json:"exp"` +} + +type ChatWarsMessageTributesStatsAck struct { + Msg *ChatWarsMessage `json:"msg"` + Tributes []ChatWarsTribute `json:"tributes"` +} + type MessageParsingRule struct { ID int32 Priority int32 `json:"prio"` diff --git a/msg.go b/msg.go index 547aef3..ddaf945 100644 --- a/msg.go +++ b/msg.go @@ -275,6 +275,22 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha return &cwm, nil } +func parseSubTypeMessageTributesStatsAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTributesStatsAck, error) { + cwm := ChatWarsMessageTributesStatsAck{} + tribute := []ChatWarsTribute{} + re := regexp.MustCompile(`((?P[1-9]{2} [a-zA-Z]+ [0-9]{4} [0-9]{2}:[0-9]{2}) - (?P[a-zA-Z]+) x (?P[0-9]+), (?P[0-9]+)🔥(\n){0,1})`) + for _, l := range re.FindAllStringSubmatch(m.Text, -1) { + log.Printf("parseSubTypeMessageTributesStatsAck : Date : %s\n", r.ReplaceAllString(l[0], "${Date}")) + log.Printf("parseSubTypeMessageTributesStatsAck : Item : %s\n", r.ReplaceAllString(l[0], "${Item}")) + log.Printf("parseSubTypeMessageTributesStatsAck : Quantity : %s\n", r.ReplaceAllString(l[0], "${Quantity}")) + log.Printf("parseSubTypeMessageTributesStatsAck : Exp : %s\n", r.ReplaceAllString(l[0], "${Exp}")) + cwm.Tributes = append(cwm.Tributes, tribute) + } + + cwm.Msg = m + return &cwm, nil +} + func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) { var i int64 diff --git a/workers.go b/workers.go index 501f765..4ccbbee 100644 --- a/workers.go +++ b/workers.go @@ -514,6 +514,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { botCraftItem(m, rule.re) case cacheObjSubType[`msg_bot_craft_all`]: botCraftAll(m, rule.re) + case cacheObjSubType[`msg_tributes_stats_req`]: + case cacheObjSubType[`msg_tributes_stats_ack`]: + _, err := parseSubTypeMessageTributesStatsAck(m, rule.re) + logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_tributes_stats_ack`]") default: //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text) }