test tributes

This commit is contained in:
shoopea 2020-02-03 12:06:41 +08:00
parent 053b6cacb2
commit e8d0fd3b44
5 changed files with 58 additions and 0 deletions

View File

@ -154,6 +154,16 @@
"name": "Tribute acknowledged", "name": "Tribute acknowledged",
"obj_type": "msg" "obj_type": "msg"
}, },
{
"intl_id": "msg_tributes_stats_req",
"name": "Tribute Stats req",
"obj_type": "msg"
},
{
"intl_id": "msg_tributes_stats_ack",
"name": "Tribute Stats ack",
"obj_type": "msg"
},
{ {
"intl_id": "msg_auction_announce", "intl_id": "msg_auction_announce",
"name": "Auction announce", "name": "Auction announce",

View File

@ -1854,5 +1854,21 @@
"msg_type": "msg_inspect_ack", "msg_type": "msg_inspect_ack",
"chat_id": 0, "chat_id": 0,
"user_id": 0 "user_id": 0
},
{
"prio": 5000,
"descn": "Tributes stats req",
"rule": "^/tributes$",
"msg_type": "msg_tributes_stats_req",
"chat_id": 0,
"user_id": 0
},
{
"prio": 5000,
"descn": "Tributes stats ack",
"rule": "^([1-9]{2} [a-zA-Z]+ [0-9]{4} [0-9]{2}:[0-9]{2} - [a-zA-Z]+ x [0-9]+, [0-9]+🔥(\n){0,1})+$",
"msg_type": "msg_tributes_stats_req",
"chat_id": 0,
"user_id": 0
} }
] ]

12
def.go
View File

@ -345,6 +345,18 @@ type ChatWarsMessageJobGWithdrawAck struct {
Ref string `json:"ref"` Ref string `json:"ref"`
} }
type ChatWarsTribute struct {
Date Time.time `json:"time"`
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
Exp int64 `json:"exp"`
}
type ChatWarsMessageTributesStatsAck struct {
Msg *ChatWarsMessage `json:"msg"`
Tributes []ChatWarsTribute `json:"tributes"`
}
type MessageParsingRule struct { type MessageParsingRule struct {
ID int32 ID int32
Priority int32 `json:"prio"` Priority int32 `json:"prio"`

16
msg.go
View File

@ -275,6 +275,22 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha
return &cwm, nil return &cwm, nil
} }
func parseSubTypeMessageTributesStatsAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTributesStatsAck, error) {
cwm := ChatWarsMessageTributesStatsAck{}
tribute := []ChatWarsTribute{}
re := regexp.MustCompile(`((?P<Date>[1-9]{2} [a-zA-Z]+ [0-9]{4} [0-9]{2}:[0-9]{2}) - (?P<Item>[a-zA-Z]+) x (?P<Quantity>[0-9]+), (?P<Exp>[0-9]+)🔥(\n){0,1})`)
for _, l := range re.FindAllStringSubmatch(m.Text, -1) {
log.Printf("parseSubTypeMessageTributesStatsAck : Date : %s\n", r.ReplaceAllString(l[0], "${Date}"))
log.Printf("parseSubTypeMessageTributesStatsAck : Item : %s\n", r.ReplaceAllString(l[0], "${Item}"))
log.Printf("parseSubTypeMessageTributesStatsAck : Quantity : %s\n", r.ReplaceAllString(l[0], "${Quantity}"))
log.Printf("parseSubTypeMessageTributesStatsAck : Exp : %s\n", r.ReplaceAllString(l[0], "${Exp}"))
cwm.Tributes = append(cwm.Tributes, tribute)
}
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) { func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
var i int64 var i int64

View File

@ -514,6 +514,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
botCraftItem(m, rule.re) botCraftItem(m, rule.re)
case cacheObjSubType[`msg_bot_craft_all`]: case cacheObjSubType[`msg_bot_craft_all`]:
botCraftAll(m, rule.re) botCraftAll(m, rule.re)
case cacheObjSubType[`msg_tributes_stats_req`]:
case cacheObjSubType[`msg_tributes_stats_ack`]:
_, err := parseSubTypeMessageTributesStatsAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_tributes_stats_ack`]")
default: default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text) //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text)
} }