parse withdraw rcv

This commit is contained in:
shoopea 2019-10-10 18:14:29 +08:00
parent 338d7660c3
commit cd38dc3933
5 changed files with 60 additions and 2 deletions

12
bot.go
View File

@ -45,6 +45,15 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/get_item_id", botGetItemId)
b.Handle("/clients", botGetClients)
b.Handle("/vault", botVaultHelp)
b.Handle("/vault_all", botVault)
b.Handle("/vault_res", botVault)
b.Handle("/vault_alch", botVault)
b.Handle("/vault_misc", botVault)
b.Handle("/vault_rec", botVault)
b.Handle("/vault_part", botVault)
b.Handle("/vault_other", botVault)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery)
@ -112,7 +121,8 @@ func botHelp(m *tb.Message) {
/get_item_id <string> - identify item_id from string
/clients - list all connected clients
/g_deposit_all - deposit all res to vault
/g_withdraw <item> <qty> .. - withdraw items`,
/g_withdraw <item> <qty> .. - withdraw items
/vault - Deposit and withdrawal stats`,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}

5
def.go
View File

@ -124,6 +124,11 @@ type ChatWarsMessageGStock struct {
ItemList []ChatWarsItems `json:"item_list"`
}
type ChatWarsMessageWithdrawRcv struct {
Msg *ChatWarsMessage `json:"msg"`
ItemList []ChatWarsItems `json:"item_list"`
}
type ChatWarsMessageGDepositReq struct {
Msg *ChatWarsMessage `json:"msg"`
ItemID64 int64 `json:"item_id"`

19
msg.go
View File

@ -219,6 +219,25 @@ func parseSubTypeMessageAuctionAnnounce(m *ChatWarsMessage, r *regexp.Regexp) (*
return &cwm, nil
}
func parseSubTypeMessageWithdrawRcv(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageWithdrawRcv, error) {
cwm := ChatWarsMessageWithdrawRcv{}
items := []ChatWarsItems{}
re := regexp.MustCompile(`(.*) x (.*)`)
for _, l := range re.FindAllStringSubmatch(m.Text), -1) {
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items = append(items, item)
}
}
cwm.ItemList = items
return &cwm, nil
}
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGStock, error) {
cwm := ChatWarsMessageGStock{}
items := []ChatWarsItems{}

20
sql.go
View File

@ -546,6 +546,10 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeMessageOrderbookSearch) + `, "orderbook_search", "Orderbook search", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageQuestReq) + `, "quest_req", "Quest Req", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageQuestAck) + `, "quest_ack", "Quest Ack", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageBattle) + `, "battle", "Battle", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageOrderCancelReq) + `, "order_cancel_req", "Order Cancel Req", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageOrderCancelAck) + `, "order_cancel_ack", "Order Cancel Ack", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageStaminaRestored) + `, "stamina_restored", "Stamina Restored", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeJobPillage) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGWithdraw) + `, "job_gwithdraw", "GWithdrawal job", ` + strconv.Itoa(objTypeJob) + `)
@ -580,6 +584,22 @@ func initDB() {
log.Println("initDB : Database set up")
}
func insertMsgItem(objId int64, itemId int64, quantity int64) error {
stmt, err := db.Prepare(`INSERT INTO obj_msg_item (obj_id, item_id, quantity)
VALUES (?, ?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.Exec(objId, itemId, quantity)
if err != nil {
return err
}
return nil
}
func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int32, gold int32, stock int32, crit bool, stamina bool) error {
objSubTypeId, err := getObjSubTypeId(objId)
if err != nil {

View File

@ -362,6 +362,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageWithdrawReq:
case objSubTypeMessageWithdrawCode:
case objSubTypeMessageWithdrawRcv:
_, err := parseSubTypeMessageWithdrawRcv(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageWithdrawRcv.")
case objSubTypeMessageStockReq:
case objSubTypeMessageMiscReq:
case objSubTypeMessageGStockResReq:
@ -461,8 +463,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
_, err := parseSubTypeMessageGDepositReq(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGDepositReq.")
case objSubTypeMessageGDepositAck:
_, err := parseSubTypeMessageGDepositAck(m, rule.re)
cwm, err := parseSubTypeMessageGDepositAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGDepositAck.")
err = insertMsgItem(cwm.Msg.ObjID64, cwm.ItemID64, cwm.Quantity)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Inserting objSubTypeMessageGDepositAck.")
case objSubTypeMessageStockAnyAck:
_, err := parseSubTypeMessageStockAnyAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageStockAnyAck.")