This commit is contained in:
shoopea 2019-05-13 14:15:53 +08:00
parent f7ef018ae8
commit 0f8fddf555

38
msg.go Normal file
View File

@ -0,0 +1,38 @@
package main
import (
"fmt"
"regexp"
"strconv"
"time"
)
func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMiniWar, err) {
t, err := time.Parse("02/01/06 15:04", r.ReplaceAllString(m.Text, "${Time}"))
logOnError(err, "parseSubTypeMessageMiniWar : parsing time : "+r.ReplaceAllString(m.Text, "${Time}"))
cwm := ChatWarsMessageMiniWar{
Time: t,
Report: make(map[string]*ChatWarsMessageMiniWarCastle),
}
for i := 1; i <= 7; i++ {
loot := fmt.Sprintf("${Loot%d}", i)
gardian := fmt.Sprintf("${Gardian%d}", i)
result := fmt.Sprintf("${Result%d}", i)
gold := fmt.Sprintf("${Gold%d}", i)
stock := fmt.Sprintf("${Stock%d}", i)
rep := ChatWarsMessageMiniWarCastle{
Gardian: r.ReplaceAllString(m.Text, gardian),
Result: r.ReplaceAllString(m.Text, result),
}
rep.Gold, err = strconv.ParseInt(r.ReplaceAllString(m.Text, gold), 10, 64)
rep.Stock, err = strconv.ParseInt(r.ReplaceAllString(m.Text, stock), 10, 64)
cwm.Report[r.ReplaceAllString(m.Text, loot)] = &rep
}
for i := 1; i <= 7; i++ {
score := fmt.Sprintf("${Score%d}", i)
points := fmt.Sprintf("${Points%d}", i)
cwm.Report[r.ReplaceAllString(m.Text, score)].Points, err = strconv.ParseInt(r.ReplaceAllString(m.Text, points), 10, 64)
}
return cwm, err
}