diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 10ba80a..9d68851 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -124,6 +124,11 @@ "name": "Pillage incoming", "obj_type": "msg" }, + { + "intl_id": "msg_pillage_inc2", + "name": "Pillage incoming v2", + "obj_type": "msg" + }, { "intl_id": "msg_pillage_go", "name": "Pillage go", diff --git a/data/msg_rules.json b/data/msg_rules.json index 911a630..d5dc6d9 100644 --- a/data/msg_rules.json +++ b/data/msg_rules.json @@ -25,12 +25,20 @@ }, { "prio": 5000, - "descn": "Pillage Inc", + "descn": "Pillage Inc #1", "rule": "^You were strolling around on your horse when you noticed (\\[(?P[A-Z0-9]{1,3})\\]){0,1}(?P.*) of .{1}(?P(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$", "msg_type": "msg_pillage_inc", "chat_id": 0, "user_id": 0 }, + { + "prio": 5000, + "descn": "Pillage Inc #2", + "rule": "^You were strolling around on your horse when you noticed (\\[(?P[A-Z0-9]{1,3})\\]){0,1}(?P.*) of .{1}(?P(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village\\.$", + "msg_type": "msg_pillage_inc2", + "chat_id": 0, + "user_id": 0 + }, { "prio": 5000, "descn": "Go", diff --git a/job.go b/job.go index 2953208..a29afcf 100644 --- a/job.go +++ b/job.go @@ -464,7 +464,7 @@ func jobPillage(j Job) { err = json.Unmarshal(j.Payload, &r) logOnError(err, "jobPillage : Unmarshal payload") - // check if we have a acknoledgment of go or a timeout within 3m30 of the PillageInc from the Job + // check if we have a acknowledgment of go or a timeout within 3m30 of the PillageInc from the Job ids := getSQLListID64(`SELECT ox.id FROM obj ox ,obj_msg omx @@ -581,7 +581,7 @@ func jobPillage(j Job) { if len(ids) > 0 { // we did, so we reschedule the job to check the outcome and wait m, err := getObjMsg(ids[0]) - logOnError(err, "jobPillage : getMsg(cacheObjSubType[`msg_go`], 10)") + logOnError(err, "jobPillage : getMsg") if err == nil { s := TGCommand{ Type: commandSendMsg, @@ -593,7 +593,34 @@ func jobPillage(j Job) { err = rescheduleJob(j.ID64, j.Trigger, time.Now().Add(30*time.Second).UTC()) logOnError(err, "jobPillage : rescheduleJob(cacheObjSubType[`msg_go`], 10)") } else { //no /go in the last 30 sec so we go ahead, send one and reschedule to check again in 25sec - clientSendCWMsg(j.UserID64, "/go") + t, err := getObjSubTypeId(r.ObjID64) + logOnError(err, "jobPillage : getObjSubTypeId") + if t == cacheObjSubType[`msg_pillage_inc`] { + clientSendCWMsg(j.UserID64, "/go") + } else if t == cacheObjSubType[`msg_pillage_inc2`] { + m, err := getObjMsg(r.ObjID64) + if len(m.Callbacks) != 1 { + s := TGCommand{ + Type: commandSendMsg, + Text: fmt.Sprintf("More than one button (%s)", m.Date.Format(time.RFC3339)), + ToUserID64: j.UserID64, + } + TGCmdQueue <- s + } else { + for _, c := range m.Callbacks { + if c.Name == `🧹Intervene` { + clientCallback(j.UserID64, m.ID64, m.ChatID64, c.Name, c.Data) + } + } + } + } else { + s := TGCommand{ + Type: commandSendMsg, + Text: fmt.Sprintf("Unknown pillage version (%s)", m.Date.Format(time.RFC3339)), + ToUserID64: j.UserID64, + } + TGCmdQueue <- s + } err = rescheduleJob(j.ID64, j.Trigger, time.Now().Add(30*time.Second).UTC()) logOnError(err, "jobPillage : rescheduleJob") diff --git a/workers.go b/workers.go index 5af3e41..42d7ea4 100644 --- a/workers.go +++ b/workers.go @@ -406,6 +406,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { } } case cacheObjSubType[`msg_pillage_inc`]: + fallthrough + case cacheObjSubType[`msg_pillage_inc2`]: cwm, err := parseSubTypeMessagePillageInc(m, rule.re) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_pillage_inc`]") cwm.ObjID64 = objId