From b265890b68662530d13d4bf8ef226a7d202e273d Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 29 Feb 2020 16:43:04 +0800 Subject: [PATCH] test alch stuff --- bot.go | 35 ++++++++++++++++ data/code_obj_sub_type.json | 25 ++++++++++++ data/msg_rules.json | 34 +++++++++++++++- def.go | 10 +++++ job.go | 81 +++++++++++++++++++++++++++++++++++++ msg.go | 45 ++++++++++++--------- rules.go | 10 +++++ workers.go | 4 ++ 8 files changed, 224 insertions(+), 20 deletions(-) diff --git a/bot.go b/bot.go index c0f4b66..750866a 100644 --- a/bot.go +++ b/bot.go @@ -934,6 +934,41 @@ func botUserConfig(m *ChatWarsMessage) { return } +func botAlchAll(m *ChatWarsMessage) { + + p := JobPayloadAlchAll{ + MsgID64: m.ID64, + ChatID64: m.ChatID64, + Status: 0, + Mana: 0, + MaxMana: 0, + } + + b, _ := json.Marshal(p) + t := time.Now().UTC().Add(1 * time.Second) + _, err = createJob(cacheObjSubType[`job_alch_all`], objJobPriority, userID64, 0, t, b) + + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: fmt.Sprintf("%s", err), + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } else { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Alch all coming", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } + + return +} + func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) { if hasUnfinishedJob(cacheObjSubType[`job_craft_all`]) { c := TGCommand{ diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 942c4f7..4d74efd 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -689,6 +689,26 @@ "name": "Peace Up Withdraw", "obj_type": "msg" }, + { + "intl_id": "msg_bot_alch_all", + "name": "Alch all", + "obj_type": "msg" + }, + { + "intl_id": "msg_alch_stock_req", + "name": "Alch stock req", + "obj_type": "msg" + }, + { + "intl_id": "msg_alch_stock_ack", + "name": "Alch stock ack", + "obj_type": "msg" + }, + { + "intl_id": "msg_skill_too_low", + "name": "Skill too low", + "obj_type": "msg" + }, { "intl_id": "job_pillage", "name": "Pillage job", @@ -799,6 +819,11 @@ "name": "Craft all items summary job", "obj_type": "job" }, + { + "intl_id": "job_alch_all", + "name": "Craft all items in stock job", + "obj_type": "job" + }, { "intl_id": "job_shops", "name": "Shops summary job", diff --git a/data/msg_rules.json b/data/msg_rules.json index 0c23620..b065f04 100644 --- a/data/msg_rules.json +++ b/data/msg_rules.json @@ -129,7 +129,15 @@ }, { "prio": 5000, - "descn": "Me request", + "descn": "Me request #1", + "rule": "^/me$", + "msg_type": "msg_me_req", + "chat_id": 0, + "user_id": 0 + }, + { + "prio": 5000, + "descn": "Me request #2", "rule": "^🏅Me$", "msg_type": "msg_me_req", "chat_id": 0, @@ -471,6 +479,30 @@ "chat_id": 0, "user_id": 0 }, + { + "prio": 5000, + "descn": "Alch stock Req", + "rule": "^/alch$", + "msg_type": "msg_alch_stock_req", + "chat_id": 0, + "user_id": 0 + }, + { + "prio": 5000, + "descn": "Alch stock Ack", + "rule": "^📦Your stock:(?P(\\n/aa_[0-9]{2} [a-zA-Z ]+ x [0-9]+)+)$", + "msg_type": "msg_alch_stock_ack", + "chat_id": 0, + "user_id": 0 + }, + { + "prio": 5000, + "descn": "Skill too low", + "rule": "^[Skill level too low]$", + "msg_type": "msg_skill_too_low", + "chat_id": 0, + "user_id": 0 + }, { "prio": 5000, "descn": "Guild stock Req", diff --git a/def.go b/def.go index 925c340..802b20c 100644 --- a/def.go +++ b/def.go @@ -292,6 +292,8 @@ type ChatWarsMessageMeAck struct { Level int64 `json:"level"` ExpNow int64 `json:"exp_now"` ExpLvl int64 `json:"exp_lvl"` + ManaNow int64 `json:"mana_now"` + ManaMax int64 `json:"mana_max"` } type ChatWarsMessageGRolesAck struct { @@ -584,6 +586,14 @@ type JobPayloadCraftAll struct { VaultJobID64 int64 `json:"vault_job_id"` } +type JobPayloadAlchAll struct { + MsgID64 int64 `json:"msg_id"` + ChatID64 int64 `json:"chat_id"` + Status int64 `json:"status"` + Mana int64 `json:"mana"` + MaxMana int64 `json:"max_mana"` +} + type JobPayloadCheckVaultLimit struct { Status int64 `json:"status"` VaultJobID64 int64 `json:"vault_job_id"` diff --git a/job.go b/job.go index 022b7eb..7316954 100644 --- a/job.go +++ b/job.go @@ -2029,6 +2029,87 @@ func jobCraftItem(j Job) { } +func jobAlchAll(j Job) { + var p JobPayloadAlchAll + + err := setJobStart(j.ID64) + logOnError(err, "jobAlchAll : setJobStart") + + err = json.Unmarshal(j.Payload, &p) + logOnError(err, "jobAlchAll : Unmarshal payload") + + if p.Status == 0 { + + p.Status = 1 + + err = setJobPayloadJSON(j.ID64, p) + logOnError(err, "jobAlchAll : setJobPayloadJSON(p)") + + setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_me_ack`]) + rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) + clientSendCWMsgDelay(j.UserID64, "/me", 0*time.Second) + return + } else if p.Status == 1 && j.Trigger != 0 { + m, err := getObjMsg(j.Trigger) + logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") + if err == nil { + rule, err := getMsgParsingRule(&m) + logOnError(err, "jobAlchAll : getMsgParsingRule") + if rule.MsgTypeID64 == cacheObjSubType[`msg_me_ack`] { + + cwm, err := parseSubTypeMessageMeAck(m, rule.re) + p.Status = 2 + p.Mana = cwm.ManaNow + p.ManaMax = cwm.ManaMax + + err = setJobPayloadJSON(j.ID64, p) + logOnError(err, "jobAlchAll : setJobPayloadJSON(p)") + + setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_skill_too_low`]) + setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_alch_stock_ack`]) + rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) + clientSendCWMsgDelay(j.UserID64, "/alch", 2*time.Second) + return + } + } + } else if p.Status == 2 && j.Trigger != 0 { + m, err := getObjMsg(j.Trigger) + logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")") + if err == nil { + rule, err := getMsgParsingRule(&m) + logOnError(err, "jobAlchAll : getMsgParsingRule") + if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Success.", + FromMsgID64: p.MsgID64, + FromChatID64: p.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- c + err = setJobDone(j.ID64) + logOnError(err, "jobAlchAll : setJobDone") + + return + } + } + } + + c := TGCommand{ + Type: commandReplyMsg, + Text: "Failed.", + FromMsgID64: p.MsgID64, + FromChatID64: p.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- c + + err = setJobDone(j.ID64) + logOnError(err, "jobAlchAll : setJobDone") + + return +} + func jobCraftAll(j Job) { var ( p JobPayloadCraftAll diff --git a/msg.go b/msg.go index 43bd6dc..520354c 100644 --- a/msg.go +++ b/msg.go @@ -409,25 +409,32 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Level}"), 10, 64) cwm.Level = i - /* - log.Printf("parseSubTypeMessageMeAck : Me report identified\n") - log.Printf("parseSubTypeMessageMeAck : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}")) - log.Printf("parseSubTypeMessageMeAck : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}")) - log.Printf("parseSubTypeMessageMeAck : Class : %s\n", cwm.Class) - log.Printf("parseSubTypeMessageMeAck : Atk : %s\n", r.ReplaceAllString(m.Text, "${Atk}")) - log.Printf("parseSubTypeMessageMeAck : Def : %s\n", r.ReplaceAllString(m.Text, "${Def}")) - log.Printf("parseSubTypeMessageMeAck : ExpNow : %s\n", r.ReplaceAllString(m.Text, "${ExpNow}")) - log.Printf("parseSubTypeMessageMeAck : ExpLvl : %s\n", r.ReplaceAllString(m.Text, "${ExpLvl}")) - log.Printf("parseSubTypeMessageMeAck : StaminaNow : %s\n", r.ReplaceAllString(m.Text, "${StaminaNow}")) - log.Printf("parseSubTypeMessageMeAck : StaminaMax : %s\n", r.ReplaceAllString(m.Text, "${StaminaMax}")) - log.Printf("parseSubTypeMessageMeAck : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}")) - log.Printf("parseSubTypeMessageMeAck : Pogs : %s\n", r.ReplaceAllString(m.Text, "${Pogs}")) - log.Printf("parseSubTypeMessageMeAck : Gems : %s\n", r.ReplaceAllString(m.Text, "${Gems}")) - log.Printf("parseSubTypeMessageMeAck : AtkGear : %s\n", r.ReplaceAllString(m.Text, "${AtkGear}")) - log.Printf("parseSubTypeMessageMeAck : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}")) - log.Printf("parseSubTypeMessageMeAck : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}")) - log.Printf("parseSubTypeMessageMeAck : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}")) - */ + i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaNow}"), 10, 64) + cwm.ManaNow = i + + i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaMax}"), 10, 64) + cwm.ManaMax = i + + log.Printf("parseSubTypeMessageMeAck : Me report identified\n") + log.Printf("parseSubTypeMessageMeAck : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}")) + log.Printf("parseSubTypeMessageMeAck : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}")) + log.Printf("parseSubTypeMessageMeAck : Class : %s\n", cwm.Class) + log.Printf("parseSubTypeMessageMeAck : Atk : %s\n", r.ReplaceAllString(m.Text, "${Atk}")) + log.Printf("parseSubTypeMessageMeAck : Def : %s\n", r.ReplaceAllString(m.Text, "${Def}")) + log.Printf("parseSubTypeMessageMeAck : ExpNow : %s\n", r.ReplaceAllString(m.Text, "${ExpNow}")) + log.Printf("parseSubTypeMessageMeAck : ExpLvl : %s\n", r.ReplaceAllString(m.Text, "${ExpLvl}")) + log.Printf("parseSubTypeMessageMeAck : StaminaNow : %s\n", r.ReplaceAllString(m.Text, "${StaminaNow}")) + log.Printf("parseSubTypeMessageMeAck : StaminaMax : %s\n", r.ReplaceAllString(m.Text, "${StaminaMax}")) + log.Printf("parseSubTypeMessageMeAck : ManaNow : %s\n", r.ReplaceAllString(m.Text, "${ManaNow}")) + log.Printf("parseSubTypeMessageMeAck : ManaMax : %s\n", r.ReplaceAllString(m.Text, "${ManaMax}")) + log.Printf("parseSubTypeMessageMeAck : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}")) + log.Printf("parseSubTypeMessageMeAck : Pogs : %s\n", r.ReplaceAllString(m.Text, "${Pogs}")) + log.Printf("parseSubTypeMessageMeAck : Gems : %s\n", r.ReplaceAllString(m.Text, "${Gems}")) + log.Printf("parseSubTypeMessageMeAck : AtkGear : %s\n", r.ReplaceAllString(m.Text, "${AtkGear}")) + log.Printf("parseSubTypeMessageMeAck : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}")) + log.Printf("parseSubTypeMessageMeAck : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}")) + log.Printf("parseSubTypeMessageMeAck : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}")) + cwm.Msg = m return &cwm, nil } diff --git a/rules.go b/rules.go index 05f5f88..40c1da2 100644 --- a/rules.go +++ b/rules.go @@ -80,6 +80,16 @@ func resetMsgParsingRules() error { SenderUserID64: id, } rules2 = append(rules2, r) + + r = MessageParsingRule{ + Priority: 9999, + Description: "Alch your supply", + Rule: "^/alch_all$", + MsgTypeID64: cacheObjSubType[`msg_bot_alch_all`], + ChatID64: chats[id], + SenderUserID64: users[id], + } + rules2 = append(rules2, r) } } muxClients.RUnlock() diff --git a/workers.go b/workers.go index 84a2287..ea98162 100644 --- a/workers.go +++ b/workers.go @@ -552,6 +552,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { botShutdown() case cacheObjSubType[`msg_bot_rage_up`]: case cacheObjSubType[`msg_bot_peace_up`]: + case cacheObjSubType[`msg_bot_alch_all`]: + botAlchAll(m) 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) } @@ -658,6 +660,8 @@ func JobWorker(id int, jobs <-chan Job) { jobShops(j) case cacheObjSubType[`job_shops_slave`]: jobShopsSlave(j) + case cacheObjSubType[`job_alch_all`]: + jobAlchAll(j) default: log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64) }