chirpnest/msg.go

48 lines
1.6 KiB
Go
Raw Normal View History

2019-05-13 08:15:53 +02:00
package main
import (
"fmt"
"regexp"
"strconv"
"time"
)
2019-05-13 08:16:44 +02:00
func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMiniWar, error) {
2019-05-13 08:15:53 +02:00
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)
}
2019-05-13 08:17:15 +02:00
return &cwm, err
2019-05-13 08:15:53 +02:00
}
2019-05-15 12:02:17 +02:00
func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessagePillageInc, error) {
cwm := ChatWarsMessagePillageInc{}
cwm.Attacker = r.ReplaceAllString(m.Text, "${Attacker}")
cwm.Castle = r.ReplaceAllString(m.Text, "${Castle}")
cwm.Guild = r.ReplaceAllString(m.Text, "${Guild}")
return &cwm, nil
}