From ac74074f596327bba856cf69f3be0d87c69dc858 Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 6 Feb 2020 18:57:46 +0800 Subject: [PATCH] /shops skeleton --- bot.go | 55 +++++++++++++++++++++++++++++++++++++ data/code_obj_sub_type.json | 10 +++++++ rules.go | 20 ++++++++++++++ sql.go | 24 ++++++++++++---- workers.go | 2 ++ 5 files changed, 106 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index f55e8b7..85ea7de 100644 --- a/bot.go +++ b/bot.go @@ -772,6 +772,61 @@ func botGStock(m *ChatWarsMessage) { return } +func botShops(m *ChatWarsMessage) { + // fan out to all active and non idle clients + /* + clts, err := getLockedAllIdleClient() + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Busy, please retry later.", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + return + } + userID64 := clt.TGUserID64 + clt.Mux.Unlock() + + p := JobPayloadGStock{ + MsgID64: m.ID64, + ChatID64: m.ChatID64, + Status: 0, + } + b, _ := json.Marshal(p) + t := time.Now().UTC().Add(1 * time.Second) + _, err = createJob(cacheObjSubType[`job_gstock`], 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: "Stock requested", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + } + */ + + c := TGCommand{ + Type: commandReplyMsg, + Text: "Not implemented", + FromMsgID64: m.ID64, + FromChatID64: m.ChatID64, + } + TGCmdQueue <- c + return +} + func botCraftItem(m *ChatWarsMessage, r *regexp.Regexp) { clt, err := getLockedIdleClient() if err != nil { diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 12974b0..e4389d2 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -644,6 +644,11 @@ "name": "Craft check for all items", "obj_type": "msg" }, + { + "intl_id": "msg_bot_shops", + "name": "Check all shops", + "obj_type": "msg" + }, { "intl_id": "msg_bot_g_stock", "name": "Get Stock", @@ -759,6 +764,11 @@ "name": "Craft all items summary job", "obj_type": "job" }, + { + "intl_id": "job_shops", + "name": "Shops summary job", + "obj_type": "job" + }, { "intl_id": "job_check_vault_limit", "name": "Check vault resource limit", diff --git a/rules.go b/rules.go index a9786b5..a8d09cc 100644 --- a/rules.go +++ b/rules.go @@ -105,6 +105,26 @@ func resetMsgParsingRules() error { } rules2 = append(rules2, r) + r = MessageParsingRule{ + Priority: 9999, + Description: "Get Shops list", + Rule: "^/shops$", + MsgTypeID64: cacheObjSubType[`msg_bot_shops`], + ChatID64: cfg.Bot.Mainchat, + SenderUserID64: 0, + } + rules2 = append(rules2, r) + + r = MessageParsingRule{ + Priority: 9999, + Description: "Get Shops list", + Rule: "^/shops$", + MsgTypeID64: cacheObjSubType[`msg_bot_shops`], + ChatID64: cfg.Bot.Admin, + SenderUserID64: cfg.Bot.Admin, + } + rules2 = append(rules2, r) + r = MessageParsingRule{ Priority: 1, Description: "Default Main chat", diff --git a/sql.go b/sql.go index ac5541a..6322a1a 100644 --- a/sql.go +++ b/sql.go @@ -577,11 +577,25 @@ func initDBViews() { failOnError(err, "initDBViews : create view obj_msg_callback_v") log.Println("initDBViews : obj_msg_callback_v created ...") - _, err = db.Exec(`CREATE VIEW obj_shop_v AS - SELECT omsm.* - FROM obj_msg_shop_main omsm;`) - failOnError(err, "initDBViews : create view obj_shop_v") - log.Println("initDBViews : obj_shop_v created ...") + _, err = db.Exec(`CREATE VIEW obj_shop_main_v AS + SELECT omsm.obj_id + ,omsm.name COLLATE utf8mb4_unicode_ci AS name + ,omsm.link COLLATE utf8mb4_unicode_ci AS link + ,omsm.number + ,omsm.user COLLATE utf8mb4_unicode_ci AS user + ,omsm.mana + ,omsm.mana_total + ,omsm.class COLLATE utf8mb4_unicode_ci AS class + ,obn.name COLLATE utf8mb4_unicode_ci AS castle + ,omsm.fees COLLATE utf8mb4_unicode_ci AS fees + ,omsm.guru COLLATE utf8mb4_unicode_ci AS guru + ,omsm.open + FROM obj_msg_shop_main omsm + ,obj_name obn; + WHERE obn.obj_id = omsm.castle_id + AND obn.priority = 0;`) + failOnError(err, "initDBViews : create view obj_shop_main_v") + log.Println("initDBViews : obj_shop_main_v created ...") log.Println("initDBViews : Views set up") } diff --git a/workers.go b/workers.go index 32575eb..12c72b8 100644 --- a/workers.go +++ b/workers.go @@ -513,6 +513,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]") case cacheObjSubType[`msg_bot_g_stock`]: botGStock(m) + case cacheObjSubType[`msg_bot_shops`]: + botShops(m) case cacheObjSubType[`msg_bot_craft_item`]: botCraftItem(m, rule.re) case cacheObjSubType[`msg_bot_craft_all`]: