craft stock

This commit is contained in:
shoopea 2019-08-30 15:11:49 +08:00
parent 13a0e3a9de
commit 49903fc889
5 changed files with 33 additions and 2 deletions

3
bot.go
View File

@ -107,7 +107,8 @@ func botHelp(m *tb.Message) {
/backup_export - export message database
/backup_import <URL> - import message database from URL
/get_item_id <string> - identify item_id from string
/clients - list all connected clients`,
/clients - list all connected clients
/g_deposit_all - deposit all res to vault`,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}

5
def.go
View File

@ -132,6 +132,11 @@ type ChatWarsMessageStockAck struct {
Stock []ChatWarsItems `json:"stock"`
}
type ChatWarsMessageStockAnyAck struct {
Msg *ChatWarsMessage `json:"msg"`
Stock []ChatWarsItems `json:"stock"`
}
type ChatWarsMessageOrderbookAck struct {
Msg *ChatWarsMessage `json:"msg"`
Name string `json:"name"`

22
msg.go
View File

@ -23,6 +23,28 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
}
}
func parseSubTypeMessageStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAnyAck, error) {
cwm := ChatWarsMessageStockAnyAck{}
items := []ChatWarsItems{}
re := regexp.MustCompile(`([a-zA-Z ]+) \(([0-9]+)\)\n{0,1}`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -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.Stock = items
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageGDepositReq(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositReq, error) {
cwm := ChatWarsMessageGDepositReq{}

View File

@ -200,7 +200,7 @@ func resetMsgParsingRules() {
,(5000, ` + strconv.Itoa(objSubTypeMessageEquipStockReq) + `, "Equipment Stock Req", "^🏷Equipment$")
,(5000, ` + strconv.Itoa(objSubTypeMessageCraftStockReq) + `, "Crafting Stock Req", "^⚒Crafting$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockEmpty) + `, "Stock Empty", "^\\[empty\\]$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAnyAck) + `, "Any Stock Ack", "^$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAnyAck) + `, "Any Stock Ack", "^(?P<Items>(([a-zA-Z ]+ \\([0-9]+\\)\\n{0,1})+)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGDepositReq) + `, "GDeposit Req", "^/g_deposit (?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `, "GDeposit Ack #2", "^Deposited successfully: (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `, "GDeposit Ack #1", "^Deposited (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\) successfully$")

View File

@ -468,6 +468,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageGDepositAck:
_, err := parseSubTypeMessageGDepositAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGDepositAck.")
case objSubTypeMessageStockAnyAck:
_, err := parseSubTypeMessageStockAnyAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageStockAnyAck.")
default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID, objId, m.Text)
}