From 7995fa3e016db5b01503d6ac86f537fa67fc880d Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 6 Feb 2020 10:23:50 +0800 Subject: [PATCH] update for shops --- bot.go | 26 ++++++++++++++++++++++---- data/code_obj_sub_type.json | 10 ++++++++++ data/config.json | 4 ++-- data/msg_rules.json | 16 ++++++++++++++++ def.go | 11 +++++++---- msg.go | 13 +++++++++++++ workers.go | 4 ++++ 7 files changed, 74 insertions(+), 10 deletions(-) diff --git a/bot.go b/bot.go index 30ae67e..2db8043 100644 --- a/bot.go +++ b/bot.go @@ -420,11 +420,29 @@ func botMsgRescanAll(m *tb.Message) { TGCmdQueue <- c return } - p := JobPayloadRescanMsg{ - Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;", cacheObjType[`msg`], cacheObjSubType[`msg`]), - MsgID64: int64(m.ID), - ChatID64: m.Chat.ID, + + var p JobPayloadRescanMsg + if len(m.Payload) > 0 { + r := regexp.MustCompile("^\"(?P(.*))\"$") + if r.MatchString(m.Payload) { + p.Query = fmt.Sprintf("SELECT o.id FROM obj o, obj_msg om WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d AND om.obj_id = o.id AND om.text like '%s' ORDER BY o.id ASC;", cacheObjType[`msg`], cacheObjSubType[`msg`], r.ReplaceAllString(m.Text, "${Filter}")) + } else { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Wrong format", + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + return + } + } else { + p.Query = fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY o.id ASC;", cacheObjType[`msg`], cacheObjSubType[`msg`]) } + + p.MsgID64 = int64(m.ID) + p.ChatID64 = m.Chat.ID + b, _ := json.Marshal(p) _, err := createJob(cacheObjSubType[`job_rescan_msg`], objJobPriorityRescanAllMsg, int64(m.Sender.ID), 0, time.Now().UTC(), b) logOnError(err, "botMsgRescan : createJob(cacheObjSubType[`job_rescan_msg`])") diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 9d68851..12974b0 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -24,6 +24,16 @@ "name": "Guild deposit chat", "obj_type": "msg" }, + { + "intl_id": "msg_shop_main_req", + "name": "Shop main request", + "obj_type": "msg" + }, + { + "intl_id": "msg_shop_main_ack", + "name": "Shop main ack", + "obj_type": "msg" + }, { "intl_id": "msg_job_gwithdraw_req", "name": "Guild withdraw conf req", diff --git a/data/config.json b/data/config.json index 28ce300..25bb61c 100644 --- a/data/config.json +++ b/data/config.json @@ -31,7 +31,7 @@ "max_qty": 10000 } ], - "shops": [ {"type": "armor", "link": "/ws_abcd"}, - {"type": "off_hand", "link": "/ws_0123"} ] + "shops": [ "/ws_abcd", + "/ws_0123" ] } } \ No newline at end of file diff --git a/data/msg_rules.json b/data/msg_rules.json index d5dc6d9..c63aba3 100644 --- a/data/msg_rules.json +++ b/data/msg_rules.json @@ -1878,5 +1878,21 @@ "msg_type": "msg_tributes_stats_ack", "chat_id": 0, "user_id": 0 + }, + { + "prio": 5000, + "descn": "Shop main req", + "rule": "^/ws_(?P[a-zA-Z0-9]+)$", + "msg_type": "msg_shop_main_req", + "chat_id": 0, + "user_id": 0 + }, + { + "prio": 5000, + "descn": "Shop main ack", + "rule": "^Welcome, to the (?P[a-zA-Z0-9 ]+) #(?P[0-9]+)\\.\\n(?s:.*)$", + "msg_type": "msg_shop_main_ack", + "chat_id": 0, + "user_id": 0 } ] \ No newline at end of file diff --git a/def.go b/def.go index 23a78e9..181652b 100644 --- a/def.go +++ b/def.go @@ -45,10 +45,7 @@ type Config struct { Min int64 `json:"min_qty"` Max int64 `json:"max_qty"` } `json:"vault_limit"` - Shops []struct { - Type string `json:"type"` - Link string `json:"link"` - } `json:"shops"` + Shops []string `json:"shops"` } `json:"bot"` } @@ -370,6 +367,12 @@ type ChatWarsMessageTributesStatsAck struct { Tributes []ChatWarsTribute `json:"tributes"` } +type ChatWarsMessageShopMainAck struct { + Msg *ChatWarsMessage `json:"msg"` + Name string `json:"name"` + Number string `json:"number"` +} + type MessageParsingRule struct { ID int32 Priority int32 `json:"prio"` diff --git a/msg.go b/msg.go index 7d809a5..0b2dbf9 100644 --- a/msg.go +++ b/msg.go @@ -298,6 +298,19 @@ func parseSubTypeMessageTributesStatsAck(m *ChatWarsMessage, r *regexp.Regexp) ( return &cwm, nil } +func parseSubTypeMessageShopMainAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageShopMainAck, error) { + cwm := ChatWarsMessageShopMainAck{} + cwm.Msg = m + + cwm.Name = r.ReplaceAllString(m.Text, "${Name}") + cwm.Number = r.ReplaceAllString(m.Text, "${Number}") + + log.Printf("parseSubTypeMessageShopMainAck : Name : %s\n", cwm.Name) + log.Printf("parseSubTypeMessageShopMainAck : Number : %s\n", cwm.Number) + + return &cwm, nil +} + func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) { var i int64 diff --git a/workers.go b/workers.go index d3c6656..a03e788 100644 --- a/workers.go +++ b/workers.go @@ -523,6 +523,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_tributes_stats_ack`]") err = insertMsgTributesStats(cwm) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgTributesStats") + case cacheObjSubType[`msg_shop_main_req`]: + case cacheObjSubType[`msg_shop_main_ack`]: + _, err := parseSubTypeMessageShopMainAck(m, rule.re) + logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_shop_main_ack`]") 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) }