/shops skeleton

This commit is contained in:
shoopea 2020-02-06 18:57:46 +08:00
parent 4878e6205e
commit ac74074f59
5 changed files with 106 additions and 5 deletions

55
bot.go
View File

@ -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 {

View File

@ -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",

View File

@ -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",

24
sql.go
View File

@ -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")
}

View File

@ -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`]: