127 lines
7.6 KiB
Go
127 lines
7.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"regexp"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
|
|
cwm := ChatWarsMessageReportAck{}
|
|
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}"))
|
|
|
|
return &cwm, nil
|
|
}
|
|
|
|
func parseSubTypeMessageUnionWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageUnionWar, error) {
|
|
//re := regexp.MustCompile('^(🏠Trade union news:\\n)(?P<Union>(?s:[^(🎪State of exclusive rights)]*))(🎪State of exclusive rights:)(?P<Fair>(?s:.*))$')
|
|
|
|
/*
|
|
"^(🏠Trade union news:\\n){0,1}` +
|
|
`(((?P<Union>[A-Z][a-z]+ [A-Z][a-z]+) was (?P<Status>(easily defended|defended successfully|breached.|easily breached.|closely breached.))(Attackers have pillage union for (?<Loot>[0-9]+) stock):\\n` +
|
|
`(🎖Attack leaders: (?P<AtkCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser1>[^,]+)(,(?P<AtkCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser2>[^,]+)){0,1}(,(?P<AtkCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser3>[^,]+)){0,1}(,(?P<AtkCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser4>[^,]+)){0,1}){0,1}(\\n){0,1}` +
|
|
`(🎖Defense leaders: (?P<DefCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUser1>[^,]+)(,(?P<DefCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser2>[^,]+)){0,1}(,(?P<DefCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUser3>[^,]+)){0,1}(,(?P<DefCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser4>[^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
|
|
`(🎪State of exclusive rights:\\n){0,1}` +
|
|
`(((?P<Fair>[A-Z][a-z]+ [A-Z][a-z]+) (?P<Status>(was protected|belongs to)( (?P<Attacker>[A-Z][a-z]+ [A-Z][a-z]+):)\\n` +
|
|
`(🎖Attack leaders: (?P<AtkCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser1>[^,]+)(,(?P<AtkCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser2>[^,]+)){0,1}(,(?P<AtkCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser3>[^,]+)){0,1}(,(?P<AtkCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser4>[^,]+)){0,1}){0,1}(\\n){0,1}` +
|
|
`(🎖Defense leaders: (?P<DefCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUser1>[^,]+)(,(?P<DefCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser2>[^,]+)){0,1}(,(?P<DefCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUser3>[^,]+)){0,1}(,(?P<DefCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUser4>[^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
|
|
`$)"
|
|
*/
|
|
cwm := ChatWarsMessageUnionWar{}
|
|
/*
|
|
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}"))
|
|
*/
|
|
return &cwm, nil
|
|
}
|
|
|
|
func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageDuelFight, error) {
|
|
cwm := ChatWarsMessageDuelFight{}
|
|
if r.ReplaceAllString(m.Text, "${Duelist1}") == r.ReplaceAllString(m.Text, "${WinDuelist}") {
|
|
cwm.WinCastle = r.ReplaceAllString(m.Text, "${Castle1}")
|
|
cwm.WinGuild = r.ReplaceAllString(m.Text, "${Guild1}")
|
|
cwm.WinUser = r.ReplaceAllString(m.Text, "${Duelist1}")
|
|
cwm.WinLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life1}"), 10, 64)
|
|
cwm.LossCastle = r.ReplaceAllString(m.Text, "${Castle2}")
|
|
cwm.LossGuild = r.ReplaceAllString(m.Text, "${Guild2}")
|
|
cwm.LossUser = r.ReplaceAllString(m.Text, "${Duelist2}")
|
|
cwm.LossLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life2}"), 10, 64)
|
|
} else {
|
|
cwm.LossCastle = r.ReplaceAllString(m.Text, "${Castle1}")
|
|
cwm.LossGuild = r.ReplaceAllString(m.Text, "${Guild1}")
|
|
cwm.LossUser = r.ReplaceAllString(m.Text, "${Duelist1}")
|
|
cwm.LossLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life1}"), 10, 64)
|
|
cwm.WinCastle = r.ReplaceAllString(m.Text, "${Castle2}")
|
|
cwm.WinGuild = r.ReplaceAllString(m.Text, "${Guild2}")
|
|
cwm.WinUser = r.ReplaceAllString(m.Text, "${Duelist2}")
|
|
cwm.WinLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life2}"), 10, 64)
|
|
}
|
|
cwm.Weapon = r.ReplaceAllString(m.Text, "${Weapon}")
|
|
|
|
return &cwm, nil
|
|
}
|
|
|
|
func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMiniWar, error) {
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|