chirpnest/msg.go

90 lines
4.7 KiB
Go
Raw Normal View History

2019-05-13 08:15:53 +02:00
package main
import (
"fmt"
2019-05-18 09:46:34 +02:00
"log"
2019-05-13 08:15:53 +02:00
"regexp"
"strconv"
"time"
)
2019-05-19 06:19:24 +02:00
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
cwm := ChatWarsMessageReportAck{}
2019-05-18 09:46:34 +02:00
log.Printf("parseSubTypeMessageReport : War report identified\n")
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
log.Printf("parseSubTypeMessageReport : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
log.Printf("parseSubTypeMessageReport : User : %s\n", r.ReplaceAllString(m.Text, "${User}"))
log.Printf("parseSubTypeMessageReport : Attack : %s\n", r.ReplaceAllString(m.Text, "${Attack}"))
log.Printf("parseSubTypeMessageReport : AttackMod : %s\n", r.ReplaceAllString(m.Text, "${AttackMod}"))
log.Printf("parseSubTypeMessageReport : Defense : %s\n", r.ReplaceAllString(m.Text, "${Defense}"))
log.Printf("parseSubTypeMessageReport : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
log.Printf("parseSubTypeMessageReport : Exp : %s\n", r.ReplaceAllString(m.Text, "${Exp}"))
log.Printf("parseSubTypeMessageReport : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
log.Printf("parseSubTypeMessageReport : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
log.Printf("parseSubTypeMessageReport : Stamina : %s\n", r.ReplaceAllString(m.Text, "${Stamina}"))
log.Printf("parseSubTypeMessageReport : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
2019-05-18 09:44:25 +02:00
2019-05-18 10:09:33 +02:00
return &cwm, nil
2019-05-18 09:44:25 +02:00
}
2019-05-18 16:16:26 +02:00
func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageDuelFight, error) {
2019-05-18 16:15:24 +02:00
cwm := ChatWarsMessageDuelFight{}
2019-05-18 16:16:26 +02:00
log.Printf("parseSubTypeMessageDuelFight : Duel fight identified\n")
log.Printf("parseSubTypeMessageDuelFight : Castle1 : %s\n", r.ReplaceAllString(m.Text, "${Castle1}"))
log.Printf("parseSubTypeMessageDuelFight : Guild1 : %s\n", r.ReplaceAllString(m.Text, "${Guild1}"))
log.Printf("parseSubTypeMessageDuelFight : Duelist1 : %s\n", r.ReplaceAllString(m.Text, "${Duelist1}"))
log.Printf("parseSubTypeMessageDuelFight : Life1 : %s\n", r.ReplaceAllString(m.Text, "${Life1}"))
log.Printf("parseSubTypeMessageDuelFight : Castle2 : %s\n", r.ReplaceAllString(m.Text, "${Castle2}"))
log.Printf("parseSubTypeMessageDuelFight : Guild2 : %s\n", r.ReplaceAllString(m.Text, "${Guild2}"))
log.Printf("parseSubTypeMessageDuelFight : Duelist2 : %s\n", r.ReplaceAllString(m.Text, "${Duelist2}"))
log.Printf("parseSubTypeMessageDuelFight : Life2 : %s\n", r.ReplaceAllString(m.Text, "${Life2}"))
log.Printf("parseSubTypeMessageDuelFight : WinCastle : %s\n", r.ReplaceAllString(m.Text, "${WinCastle}"))
log.Printf("parseSubTypeMessageDuelFight : WinGuild : %s\n", r.ReplaceAllString(m.Text, "${WinGuild}"))
log.Printf("parseSubTypeMessageDuelFight : WinDuelist : %s\n", r.ReplaceAllString(m.Text, "${WinDuelist}"))
log.Printf("parseSubTypeMessageDuelFight : LossCastle : %s\n", r.ReplaceAllString(m.Text, "${LossCastle}"))
log.Printf("parseSubTypeMessageDuelFight : LossGuild : %s\n", r.ReplaceAllString(m.Text, "${LossGuild}"))
log.Printf("parseSubTypeMessageDuelFight : LossDuelist : %s\n", r.ReplaceAllString(m.Text, "${LossDuelist}"))
2019-05-18 16:40:58 +02:00
log.Printf("parseSubTypeMessageDuelFight : Weapon : %s\n", r.ReplaceAllString(m.Text, "${Weapon}"))
2019-05-18 16:15:24 +02:00
return &cwm, nil
}
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
}