update stock ack

This commit is contained in:
shoopea 2019-08-22 17:31:16 +08:00
parent e465d3fb54
commit 5854f4f58d
4 changed files with 41 additions and 3 deletions

9
def.go
View File

@ -100,7 +100,7 @@ type ChatWarsMessage struct {
Text string `json:"text"`
}
type ChatWarsMessageStock struct {
type ChatWarsMessageGStock struct {
Msg *ChatWarsMessage `json:"msg"`
OwnerID64 int64 `json:"owner_id"`
ItemList []ChatWarsItems `json:"item_list"`
@ -110,6 +110,13 @@ type ChatWarsMessageReportAck struct {
ObjID64 int64 `json:"obj_id"`
}
type ChatWarsMessageStockAck struct {
Msg *ChatWarsMessage `json:"msg"`
Used int64 `json:"used"`
Available int64 `json:"available"`
Stock []ChatWarsItems `json:"stock"`
}
type ChatWarsMessageOrderbookAck struct {
Msg *ChatWarsMessage `json:"msg"`
Name string `json:"name"`

29
msg.go
View File

@ -23,6 +23,33 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
}
}
func parseSubTypeMessageStockAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAck, error) {
cwm := ChatWarsMessageStockAck{}
items := []ChatWarsItems{}
log.Printf("parseSubTypeMessageReport : Stock Ack identified\n")
log.Printf("parseSubTypeMessageReport : Used : %s\n", r.ReplaceAllString(m.Text, "${Used}"))
log.Printf("parseSubTypeMessageReport : Available : %s\n", r.ReplaceAllString(m.Text, "${Available}"))
re := regexp.MustCompile(`\n[a-zA-Z ]+ \([0-9]+\)`)
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.Used, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Used}"), 10, 64)
cwm.Available, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Available}"), 10, 64)
cwm.Stock = items
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
cwm := ChatWarsMessageReportAck{}
/*
@ -81,7 +108,7 @@ func parseSubTypeMessageAuctionAnnounce(m *ChatWarsMessage, r *regexp.Regexp) (*
return &cwm, nil
}
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) {
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGStock, error) {
cwm := ChatWarsMessageStock{}
items := []ChatWarsItems{}
re := regexp.MustCompile(`\n([0-9a-z]+) (.*) x ([0-9]+)`)

View File

@ -121,6 +121,8 @@ func resetMsgParsingRules() {
,(5000, ` + strconv.Itoa(objSubTypeMessageDepositAck) + `, "Deposit Ack #2", "^Deposited successfully: (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDepositAck) + `, "Deposit Ack #1", "^Deposited (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\) successfully$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockReq) + `, "Stock Req", "^/stock$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAck) + `, "Stock Ack", "^📦Storage ((?P<Userd>[0-9]+)/(?P<Available>[0-9]+)):` +
`(?P<Items>(\\n[a-zA-Z ]+ \\([0-9]+\\))*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageMiscReq) + `, "Misc Req", "^/misc$")` + /*
,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war report", "^(🏠Trade union news:\\n){0,1}` +
`(((?P<Union>[A-Z][a-z]+ [A-Z][a-z]+) was (?P<StatusUnion>(easily defended|defended successfully|breached.|easily breached.|closely breached.))( Attackers have pillaged union for (?P<Loot>[0-9]+) stock){0,1}:\\n` +

View File

@ -462,7 +462,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageOrderbookAck:
_, err := parseSubTypeMessageOrderbookAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageOrderbookAck.")
case objSubTypeMessageStockAck:
_, err := parseSubTypeMessageStockAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageStockAck.")
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)
}