update ambush

This commit is contained in:
shoopea 2019-10-20 20:09:25 +08:00
parent 41a80e2e3e
commit 7549e4956b
3 changed files with 38 additions and 1 deletions

12
def.go
View File

@ -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"`

11
msg.go
View File

@ -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}")

View File

@ -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)),