From 377742825d44493e35b9a7d91109ffbc044ad645 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 26 Jan 2020 18:30:37 +0800 Subject: [PATCH] test --- data/code_obj_sub_type.json | 10 ++++++++++ obj.go | 10 +++++----- rules.go | 26 ++++++++++++++++++++++++++ workers.go | 9 +++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index ed60dac..81d642b 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -609,6 +609,16 @@ "name": "NY 2020 Event Battle Station", "obj_type": "msg" }, + { + "intl_id": "msg_bot_craft_item", + "name": "Craft check for specific item", + "obj_type": "msg" + }, + { + "intl_id": "msg_bot_craft_all", + "name": "Craft check for all items", + "obj_type": "msg" + }, { "intl_id": "job_pillage", "name": "Pillage job", diff --git a/obj.go b/obj.go index 6db19f2..20f378e 100644 --- a/obj.go +++ b/obj.go @@ -34,11 +34,6 @@ func initCache(initDB bool) { err = loadObjSubType() logOnError(err, "initCache : caching obj_sub_type") - log.Println("Filling message parsing rules...") - resetMsgParsingRules() - msgParsingRules, err = loadMsgParsingRules() - logOnError(err, "initCache : message parsing rules") - log.Println("Caching guilds ..") err = loadObjGuild() logOnError(err, "initCache : caching guilds") @@ -51,6 +46,11 @@ func initCache(initDB bool) { err = loadObjItem() logOnError(err, "initCache : caching items") + log.Println("Filling message parsing rules...") + resetMsgParsingRules() + msgParsingRules, err = loadMsgParsingRules() + logOnError(err, "initCache : message parsing rules") + log.Println("Caching messages ..") err = loadObjMsg() logOnError(err, "initCache : caching msgs") diff --git a/rules.go b/rules.go index 2e46d9f..82c1555 100644 --- a/rules.go +++ b/rules.go @@ -39,6 +39,32 @@ func resetMsgParsingRules() error { } rules2 = append(rules2, r) + r = MessageParsingRule{ + Priority: 9999, + Description: "All item craft", + Rule: "^/craft_all$", + MsgTypeID64: cacheObjSubType[`msg_bot_craft_all`], + ChatID64: cfg.Bot.Mainchat, + SenderUserID64: 0, + } + rules2 = append(rules2, r) + + muxObjItem.RLock() + defer muxObjItem.RUnlock() + for _, o := range objItems { + if o.Craft != nil { + r = MessageParsingRule{ + Priority: 9998, + Description: fmt.Sprintf("Specific item craft %s", o.Code), + Rule: fmt.Sprintf("^%s$", o.Craft.Command), + MsgTypeID64: cacheObjSubType[`msg_bot_craft_item`], + ChatID64: cfg.Bot.Mainchat, + SenderUserID64: 0, + } + rules2 = append(rules2, r) + } + } + r = MessageParsingRule{ Priority: 1, Description: "Default Main chat", diff --git a/workers.go b/workers.go index 8b2f023..7d2c1f4 100644 --- a/workers.go +++ b/workers.go @@ -508,6 +508,15 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { case cacheObjSubType[`msg_job_gwithdraw_ack`]: _, err := parseSubTypeMessageJobGWithdrawAck(m, rule.re) logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]") + case cacheObjSubType[`msg_bot_craft_item`]: + c := TGCommand{ + Type: commandReplyMsg, + Text: `test`, + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + ParseMode: cmdParseModeHTML, + } + TGCmdQueue <- c 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) }