diff --git a/def.go b/def.go index dd2f77a..114b220 100644 --- a/def.go +++ b/def.go @@ -107,6 +107,7 @@ type ChatWarsExchangeDeal struct { ItemID64 int64 `json:"item_id"` Quantity int64 `json:"quantity"` Price int64 `json:"price"` + Status string `json:"status"` Link string `json:"link"` } diff --git a/msg.go b/msg.go index 498ab3b..5ff2eb2 100644 --- a/msg.go +++ b/msg.go @@ -29,20 +29,27 @@ func parseSubTypeMessageExchangeAck(m *ChatWarsMessage, r *regexp.Regexp) (*Chat log.Printf("parseSubTypeMessageExchangeAck : ActiveDeals : %s\n", r.ReplaceAllString(m.Text, "${ActiveDeals}")) log.Printf("parseSubTypeMessageExchangeAck : MaxDeals : %s\n", r.ReplaceAllString(m.Text, "${MaxDeals}")) - /* - re := regexp.MustCompile(`([a-zA-Z ]+)\n([0-9]+) x ([0-9]+)💰 [Cancelling] (.*)\n`) - for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) { + cwm.ActiveDeals, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ActiveDeals}"), 10, 64) + cwm.MaxDeals, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${MaxDeals}"), 10, 64) + + if cwm.ActiveDeals > 0 { + re := regexp.MustCompile(`([a-zA-Z ]+)\n([0-9]+) x ([0-9]+)💰 \[(.*)\] (.*)\n`) + for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Deals}"), -1) { i := getObjItemID(``, l[1]) q, _ := strconv.ParseInt(l[2], 10, 64) + p, _ := strconv.ParseInt(l[3], 10, 64) + l := l[4] if i != 0 { - item := ChatWarsItems{ + deal := ChatWarsExchangeDeal{ ItemID64: i, Quantity: q, + Price: p, + Link: l, } - items = append(items, item) + deals = append(items, deal) } } - */ + } cwm.DealList = deals cwm.Msg = m return &cwm, nil diff --git a/rules.go b/rules.go index 70892d5..d151b06 100644 --- a/rules.go +++ b/rules.go @@ -225,9 +225,6 @@ func resetMsgParsingRules() { `Your deals \\((?P[0-9]+)/(?P[0-9]+)\\):\\n` + `(?P(?s:.*))\\n` + `Your last 10 comitted trades: /trades$") - ,(4000, ` + strconv.Itoa(objSubTypeMessageExchangeAck) + `, "Exchange Ack", "^Here you can buy and sell some items.\\n` + - `To find a tradable item just type:\\n` + - `(?s:.*)$") ;`) failOnError(err, "resetMsgParsingRules : populate table msg_rules") }