From 7549e4956ba4de5a9062371a12b82cc1f4a6cfae Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 20 Oct 2019 20:09:25 +0800 Subject: [PATCH] update ambush --- def.go | 12 ++++++++++++ msg.go | 11 +++++++++++ workers.go | 16 +++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/def.go b/def.go index 8789acd..395d395 100644 --- a/def.go +++ b/def.go @@ -10,6 +10,7 @@ import ( ) const maxUnixTimestamp int64 = 2147483647 +const chtwrsbotID64 int64 = 408101137 type DataBackup struct { Messages []ChatWarsMessage `json:"messages"` @@ -204,6 +205,17 @@ type ChatWarsMessageQuestResult struct { LostTorch bool `json:"lost_torch"` } +type ChatWarsMessageQuestResultAmbush struct { + Msg *ChatWarsMessage `json:"msg"` + Loot []ChatWarsItems `json:"loot"` + Level int `json:"level"` + Armored bool `json:"armored"` + Enraged bool `json:"enraged"` + SpearResists bool `json:"spear resists"` + Toughness bool `json:"toughness"` + PoisonBottles bool `json:"poison_bottles"` +} + type ChatWarsMessageDuelFight struct { ObjID64 int64 `json:"obj_id"` WinCastle string `json:"win_castle"` diff --git a/msg.go b/msg.go index 5718f72..bdc3f5a 100644 --- a/msg.go +++ b/msg.go @@ -427,6 +427,17 @@ func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa return &cwm, nil } +func parseSubTypeMessageQuestResultAmbush(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageQuestResultAmbush, error) { + cwm := ChatWarsMessageQuestResultAmbush{} + + re := regexp.MustCompile(`(([0-9] x ){0,1}[a-zA-Z ]* lvl\.[0-9]*)`) + for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Monsters}"), -1) { + log.Printf("parseSubTypeMessageQuestResultAmbush : %s\n", l[1]) + } + cwm.Msg = m + return &cwm, nil +} + func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessagePillageInc, error) { cwm := ChatWarsMessagePillageInc{} cwm.Attacker = r.ReplaceAllString(m.Text, "${Attacker}") diff --git a/workers.go b/workers.go index b0b9fc0..be1c70b 100644 --- a/workers.go +++ b/workers.go @@ -383,6 +383,20 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { cwm, err := parseSubTypeMessageReportAck(m, rule.re) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.") cwm.ObjID64 = objId + case objSubTypeMessageQuestResultAmbush: + cwm, err := parseSubTypeMessageQuestResultAmbush(m, rule.re) + logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageQuestResultAmbush.") + cwm.ObjID64 = objId + if m.Date.Add(3*time.Minute).After(time.Now()) && m.ChatID64 == chtwrsbotID64 { + s := TGCommand{ + Type: commandForwardMsg, + FromUserID64: m.TGUserID64, + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + ToChatID64: cfg.Bot.Mainchat, + } + MQTGCmdQueue <- s + } case objSubTypeMessagePillageInc: cwm, err := parseSubTypeMessagePillageInc(m, rule.re) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessagePillageInc.") @@ -390,7 +404,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { err = insertMsgPillageInc(cwm) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc") // only catch live pillages - if m.Date.Add(3 * time.Minute).After(time.Now()) { + if m.Date.Add(3*time.Minute).After(time.Now()) && m.ChatID64 == chtwrsbotID64 { s := TGCommand{ Type: commandSendMsg, Text: fmt.Sprintf("Catching pillage (%s)", m.Date.Format(time.RFC3339)),