test time parsing

This commit is contained in:
shoopea 2019-12-19 11:31:28 +08:00
parent ea5b8a8397
commit a9a0d5f43e
6 changed files with 72 additions and 4 deletions

View File

@ -57,10 +57,14 @@ func cronSetDef() {
func cronGetHammerTime() { func cronGetHammerTime() {
clt, err := getLockedRandomClient() clt, err := getLockedRandomClient()
logOnError(err, "cronGetHammerTime") logOnError(err, "cronGetHammerTime : getLockedRandomClient")
if err != nil { if err != nil {
return return
} }
clt.Mux.Unlock() clt.Mux.Unlock()
p := JobPayloadGetHammertime{}
b, _ := json.Marshal(&p)
err = createJobCallback(objSubTypeJobGetHammerTime, clt.TGUserID64, objSubTypeMessageTimeAck, b, 1*time.Minute)
logOnError(err, "cronGetHammerTime : createJobCallback")
clientSendCWMsgDelay(clt.TGUserID64, `/time`, 0) clientSendCWMsgDelay(clt.TGUserID64, `/time`, 0)
} }

16
def.go
View File

@ -266,6 +266,18 @@ type ChatWarsMessagePillageInc struct {
type ChatWarsMessageUnionWar struct { type ChatWarsMessageUnionWar struct {
} }
type ChatWarsMessageTimeAck struct {
RealTime time.Time `json:"real_time"`
TimeOfDay string `json:"time_of_day"`
Hour int64 `json:"hour"`
Minute int64 `json:"minute"`
Day int64 `json:"day"`
Month int64 `json:"month"`
Year int64 `json:"year"`
Weather string `json:"weather"`
WeatherNext string `json:"weather_next"`
}
type MessageParsingRule struct { type MessageParsingRule struct {
ID int32 ID int32
Priority int32 Priority int32
@ -291,6 +303,9 @@ type Job struct {
Payload []byte Payload []byte
} }
type JobPayloadGetHammerTime struct {
}
type JobPayloadSetDef struct { type JobPayloadSetDef struct {
} }
@ -548,6 +563,7 @@ const (
objSubTypeJobFwdMsg = 617 // rename to objSubTypeJobMsgFwd objSubTypeJobFwdMsg = 617 // rename to objSubTypeJobMsgFwd
objSubTypeJobSetDef = 618 objSubTypeJobSetDef = 618
objSubTypeJobMsgDel = 619 objSubTypeJobMsgDel = 619
objSubTypeJobGetHammerTime = 620
objSubTypeItemResource = 701 objSubTypeItemResource = 701
objSubTypeItemAlch = 702 objSubTypeItemAlch = 702
objSubTypeItemMisc = 703 objSubTypeItemMisc = 703

24
job.go
View File

@ -1335,3 +1335,27 @@ func jobSetDef(j Job) {
return return
} }
func jobGetHammerTime(j Job) {
var p JobPayloadSetDef
err := setJobStart(j.ID64)
logOnError(err, "jobGetHammerTime : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobGetHammerTime : Unmarshal payload")
msg, err := getObjMsg(j.Trigger)
logOnError(err, "jobGetHammerTime : getObjMsg msg")
rule, err := getMsgParsingRule(msg)
logOnError(err, "jobGetHammerTime : getMsgParsingRule")
cwm, err := parseSubTypeMessageTimeAck(msg, rule.re)
if cwm.State == `🛌Rest` {
clientSendCWMsg(j.UserID64, `🛡Defend`)
}
err = setJobDone(j.ID64)
logOnError(err, "jobSetDef : setJobDone")
return
}

16
msg.go
View File

@ -427,6 +427,22 @@ func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
return &cwm, nil return &cwm, nil
} }
func parseSubTypeMessageTimeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTimeAck, error) {
cwm := ChatWarsMessageTimeAck{}
t, err = fromChatWarsDate(r.ReplaceAllString(m.Text, "${Day}") + " " + r.ReplaceAllString(m.Text, "${Month}") + " " + r.ReplaceAllString(m.Text, "${Year}") + " " + r.ReplaceAllString(m.Text, "${Hour}") + ":" + r.ReplaceAllString(m.Text, "${Minute}"))
logOnError(err, "parseSubTypeMessageTimeAck : fromChatWarsDate")
cwm.RealTime = t
cwm.TimeOfDay = r.ReplaceAllString(m.Text, "${Time}")
cwm.Hour, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Hour}"), 10, 64)
cwm.Minute, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Minute}"), 10, 64)
cwm.Day, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Day}"), 10, 64)
cwm.Month = chatWarsMonth[r.ReplaceAllString(d, "${Month}")]
cwm.Year, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Year}"), 10, 64)
cwm.Weather = r.ReplaceAllString(m.Text, "${Weather}")
cwm.WeatherNext = r.ReplaceAllString(m.Text, "${WeatherNext}")
return cwm, nil
}
func parseSubTypeMessageQuestResultAmbush(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageQuestResultAmbush, error) { func parseSubTypeMessageQuestResultAmbush(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageQuestResultAmbush, error) {
var lvlSum, qtySum int64 var lvlSum, qtySum int64

View File

@ -25,7 +25,13 @@ func resetMsgParsingRules() {
`End At: (?P<End>.*)\\n` + `End At: (?P<End>.*)\\n` +
`Status: (?P<Status>.*)(\\n)` + `Status: (?P<Status>.*)(\\n)` +
`*(?s:.*)") `*(?s:.*)")
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>.+) (?P<Year>[0-9]{4})\\n(?s:.*)$") ,(5000, ` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "Time", "^In Chat Wars world now\\n` +
`(?P<Time>.*)\\n` +
`(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n` +
`(?P<Day>[0-9]{2}) (?P<Month>.+) (?P<Year>[0-9]{4})\\n\\n` +
`Weather forecast\\n` +
`(?P<Weather>.*)→(?P<WeatherNext>.*)\\n` +
`*Data provided by CWNN$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "Pillage Inc", "^You were strolling around on your horse when you noticed (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) of .{1}(?P<Castle>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$") ,(5000, ` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "Pillage Inc", "^You were strolling around on your horse when you noticed (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) of .{1}(?P<Castle>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGo) + `, "Go", "^/go$") ,(5000, ` + strconv.Itoa(objSubTypeMessageGo) + `, "Go", "^/go$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageGo) + `,"Pillage Go", "^You lift up your sword and charge at the violator.$") ,(5000, ` + strconv.Itoa(objSubTypeMessagePillageGo) + `,"Pillage Go", "^You lift up your sword and charge at the violator.$")

View File

@ -473,8 +473,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
*/ */
} }
case objSubTypeMessageTimeAck: case objSubTypeMessageTimeAck:
_, err := fromChatWarsDate(rule.re.ReplaceAllString(m.Text, "${Day}") + " " + rule.re.ReplaceAllString(m.Text, "${Month}") + " " + rule.re.ReplaceAllString(m.Text, "${Year}") + " " + rule.re.ReplaceAllString(m.Text, "${Hour}") + ":" + rule.re.ReplaceAllString(m.Text, "${Minute}")) _, err := parseSubTypeMessageTimeAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : fromChatWarsDate") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageTimeAck.")
case objSubTypeMessageOrderbookAck: case objSubTypeMessageOrderbookAck:
_, err := parseSubTypeMessageOrderbookAck(m, rule.re) _, err := parseSubTypeMessageOrderbookAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageOrderbookAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageOrderbookAck.")
@ -579,6 +579,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobFwdMsg(j) jobFwdMsg(j)
case objSubTypeJobSetDef: case objSubTypeJobSetDef:
jobSetDef(j) jobSetDef(j)
case objSubTypeJobGetHammerTime:
jobGetHammerTime(j)
default: default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
} }