chirpnest/msg.go

567 lines
26 KiB
Go
Raw Normal View History

2019-09-01 10:30:21 +02:00
package main
2019-05-13 08:15:53 +02:00
import (
2019-08-21 08:37:53 +02:00
"errors"
2019-07-09 07:04:57 +02:00
"log"
2019-05-13 08:15:53 +02:00
"regexp"
"strconv"
2019-05-30 10:56:37 +02:00
"strings"
2019-05-13 08:15:53 +02:00
"time"
)
2019-08-21 08:37:53 +02:00
func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
var i int
2020-01-06 04:58:46 +01:00
for i = 0; i < len(msgParsingRules); i++ {
if msgParsingRules[i].re.FindStringSubmatch(m.Text) != nil {
if (msgParsingRules[i].ChatID64 == 0 || msgParsingRules[i].ChatID64 == m.ChatID64) && (msgParsingRules[i].SenderUserID64 == 0 || msgParsingRules[i].SenderUserID64 == m.TGSenderUserID64) {
break
}
}
2019-08-21 08:37:53 +02:00
}
if i == len(msgParsingRules) {
return nil, errors.New("Can't find message type in rules.")
} else {
2019-08-21 08:53:36 +02:00
r := msgParsingRules[i]
2019-08-21 08:54:06 +02:00
return &r, nil
2019-08-21 08:37:53 +02:00
}
}
2020-01-22 10:07:14 +01:00
func parseSubTypeMessageInspectAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageInspectAck, error) {
cwm := ChatWarsMessageInspectAck{}
cwm.Name = r.ReplaceAllString(m.Text, "${Item}")
log.Printf("parseSubTypeMessageInspectAck : Name : %s\n", cwm.Name)
return &cwm, nil
}
2019-09-14 10:27:38 +02:00
func parseSubTypeMessageExchangeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageExchangeAck, error) {
cwm := ChatWarsMessageExchangeAck{}
deals := []ChatWarsExchangeDeal{}
log.Printf("parseSubTypeMessageExchangeAck : ActiveDeals : %s\n", r.ReplaceAllString(m.Text, "${ActiveDeals}"))
log.Printf("parseSubTypeMessageExchangeAck : MaxDeals : %s\n", r.ReplaceAllString(m.Text, "${MaxDeals}"))
2019-09-14 10:43:18 +02:00
cwm.ActiveDeals, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ActiveDeals}"), 10, 64)
cwm.MaxDeals, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${MaxDeals}"), 10, 64)
if cwm.ActiveDeals > 0 {
re := regexp.MustCompile(`([a-zA-Z ]+)\n([0-9]+) x ([0-9]+)💰 \[(.*)\] (.*)\n`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Deals}"), -1) {
2019-09-14 10:27:38 +02:00
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
2019-09-14 10:43:18 +02:00
p, _ := strconv.ParseInt(l[3], 10, 64)
l := l[4]
2019-09-14 10:27:38 +02:00
if i != 0 {
2019-09-14 10:43:18 +02:00
deal := ChatWarsExchangeDeal{
2019-09-14 10:27:38 +02:00
ItemID64: i,
Quantity: q,
2019-09-14 10:43:18 +02:00
Price: p,
Link: l,
2019-09-14 10:27:38 +02:00
}
2019-09-14 10:43:44 +02:00
deals = append(deals, deal)
2019-09-14 10:27:38 +02:00
}
}
2019-09-14 10:43:18 +02:00
}
2019-09-14 10:30:43 +02:00
cwm.DealList = deals
2019-09-14 10:27:38 +02:00
cwm.Msg = m
return &cwm, nil
}
2019-10-03 05:35:24 +02:00
func parseSubTypeMessageQuestResult(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageQuestResult, error) {
cwm := ChatWarsMessageQuestResult{}
2019-10-03 12:11:24 +02:00
/* look for 351 go_quest_ack, etc .. */
2019-10-03 05:35:24 +02:00
cwm.Msg = m
return &cwm, nil
}
2019-08-30 09:11:49 +02:00
func parseSubTypeMessageStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAnyAck, error) {
cwm := ChatWarsMessageStockAnyAck{}
items := []ChatWarsItems{}
2019-11-05 03:59:12 +01:00
re := regexp.MustCompile(`(📃){0,1}(['a-zA-Z ]+) \(([0-9]+)\)( /view_[a-z0-9]+){0,1}\n{0,1}`)
2019-08-30 09:11:49 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
2019-09-23 03:33:45 +02:00
// fmt.Printf("parseSubTypeMessageStockAnyAck : %+q\n", l)
i := getObjItemID(``, l[2])
q, _ := strconv.ParseInt(l[3], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
2019-08-30 09:11:49 +02:00
}
2019-09-23 03:33:45 +02:00
items = append(items, item)
}
2019-08-30 09:11:49 +02:00
}
cwm.Stock = items
cwm.Msg = m
return &cwm, nil
}
2019-08-30 04:14:30 +02:00
func parseSubTypeMessageGDepositReq(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositReq, error) {
cwm := ChatWarsMessageGDepositReq{}
cwm.ItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Item}"), ``) // FIXME, handle uXXX items ?
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
cwm.Msg = m
return &cwm, nil
}
2019-08-27 17:10:57 +02:00
func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) {
cwm := ChatWarsMessageGDepositAck{}
2019-08-29 13:52:09 +02:00
cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}"))
2019-08-27 17:10:57 +02:00
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
2019-08-30 04:14:30 +02:00
gDepositForwardMux.Lock()
for i := range gDepositForwardMsg {
msg, err := getObjMsg(gDepositForwardMsg[i])
logOnError(err, "parseSubTypeMessageGDepositAck : gDepositForwardMsg")
if err == nil && m.TGUserID64 == msg.TGUserID64 {
rule, err := getMsgParsingRule(msg)
logOnError(err, "parseSubTypeMessageGDepositAck : getMsgParsingRule")
cwmreq, err := parseSubTypeMessageGDepositReq(msg, rule.re)
logOnError(err, "parseSubTypeMessageGDepositAck : parseSubTypeMessageGDepositReq")
if err == nil && cwmreq.ItemID64 == cwm.ItemID64 && cwmreq.Quantity == cwm.Quantity {
2019-08-30 05:07:37 +02:00
if m.Date.UTC().Before(msg.Date.UTC().Add(1 * time.Minute)) {
clientFwdCWMsg(msg.TGUserID64, m.ID64, m.ChatID64, cfg.Bot.Depositchat)
}
2019-08-30 04:14:30 +02:00
gDepositForwardMsg[i] = gDepositForwardMsg[len(gDepositForwardMsg)-1]
gDepositForwardMsg = gDepositForwardMsg[:len(gDepositForwardMsg)-1]
break
}
}
}
gDepositForwardMux.Unlock()
2019-08-27 17:10:57 +02:00
cwm.Msg = m
return &cwm, nil
}
2019-08-22 11:31:16 +02:00
func parseSubTypeMessageStockAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAck, error) {
cwm := ChatWarsMessageStockAck{}
items := []ChatWarsItems{}
2020-01-02 17:20:56 +01:00
re := regexp.MustCompile(`\n([a-zA-Z ❄️]+) \(([0-9]+)\)`)
2019-08-22 11:31:16 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items = append(items, item)
}
}
2020-01-02 12:56:43 +01:00
re = regexp.MustCompile(`\n\/sg_[0-9]+ ([^\(]+) \(([0-9]+)\)`)
2019-08-27 05:58:23 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items = append(items, item)
}
}
2019-08-22 11:31:16 +02:00
cwm.Used, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Used}"), 10, 64)
cwm.Available, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Available}"), 10, 64)
cwm.Stock = items
cwm.Msg = m
return &cwm, nil
}
2019-05-19 06:19:24 +02:00
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
cwm := ChatWarsMessageReportAck{}
2019-05-30 07:49:11 +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 10:09:33 +02:00
return &cwm, nil
2019-05-18 09:44:25 +02:00
}
2019-08-21 08:37:53 +02:00
func parseSubTypeMessageOrderbookAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageOrderbookAck, error) {
cwm := ChatWarsMessageOrderbookAck{}
2019-10-11 03:56:02 +02:00
/*
log.Printf("parseSubTypeMessageOrderbookAck : Orderbook identified\n")
log.Printf("parseSubTypeMessageOrderbookAck : Name : %s\n", r.ReplaceAllString(m.Text, "${Name}"))
log.Printf("parseSubTypeMessageOrderbookAck : Code : %s\n", r.ReplaceAllString(m.Text, "${Code}"))
log.Printf("parseSubTypeMessageOrderbookAck : Qty : %s\n", r.ReplaceAllString(m.Text, "${Qty}"))
log.Printf("parseSubTypeMessageOrderbookAck : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
log.Printf("parseSubTypeMessageOrderbookAck : Qty1 : %s\n", r.ReplaceAllString(m.Text, "${Qty1}"))
log.Printf("parseSubTypeMessageOrderbookAck : Price1 : %s\n", r.ReplaceAllString(m.Text, "${Price1}"))
log.Printf("parseSubTypeMessageOrderbookAck : Qty2 : %s\n", r.ReplaceAllString(m.Text, "${Qty2}"))
log.Printf("parseSubTypeMessageOrderbookAck : Price2 : %s\n", r.ReplaceAllString(m.Text, "${Price2}"))
log.Printf("parseSubTypeMessageOrderbookAck : Qty3 : %s\n", r.ReplaceAllString(m.Text, "${Qty3}"))
log.Printf("parseSubTypeMessageOrderbookAck : Price3 : %s\n", r.ReplaceAllString(m.Text, "${Price3}"))
*/
2019-08-21 08:37:53 +02:00
return &cwm, nil
}
2019-06-06 07:52:22 +02:00
func parseSubTypeMessageAuctionAnnounce(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageAuctionAnnounce, error) {
cwm := ChatWarsMessageAuctionAnnounce{}
l, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Lot}"), 10, 32)
cwm.LotID = int32(l)
2019-06-06 07:54:10 +02:00
cwm.ItemID64 = getObjItemID(``, r.ReplaceAllString(m.Text, "${Item}"))
2019-06-06 07:52:22 +02:00
cwm.Cond = r.ReplaceAllString(m.Text, "${Cond}")
cwm.Quality = r.ReplaceAllString(m.Text, "${Quality}")
cwm.SellerUserID64 = getObjUserID(r.ReplaceAllString(m.Text, "${SellerUser}"))
2019-06-11 04:06:04 +02:00
cwm.SellerGuildID64 = getObjGuildID(r.ReplaceAllString(m.Text, "${SellerGuild}"))
cwm.SellerCastleID64 = getObjCastleID(r.ReplaceAllString(m.Text, "${SellerCastle}"))
2019-06-06 07:52:22 +02:00
cwm.BuyerUserID64 = getObjUserID(r.ReplaceAllString(m.Text, "${BuyerUser}"))
2019-06-11 04:06:04 +02:00
cwm.BuyerGuildID64 = getObjGuildID(r.ReplaceAllString(m.Text, "${BuyerGuild}"))
cwm.BuyerCastleID64 = getObjCastleID(r.ReplaceAllString(m.Text, "${BuyerCastle}"))
2019-06-06 07:52:22 +02:00
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
cwm.Price = int32(p)
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
2019-06-06 08:25:05 +02:00
2019-06-06 07:56:28 +02:00
return &cwm, nil
2019-06-06 07:52:22 +02:00
}
2019-10-10 12:14:29 +02:00
func parseSubTypeMessageWithdrawRcv(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageWithdrawRcv, error) {
cwm := ChatWarsMessageWithdrawRcv{}
items := []ChatWarsItems{}
2019-10-11 03:21:09 +02:00
re := regexp.MustCompile(`(.*) x (.*)`)
2019-10-11 03:56:02 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
2019-10-11 03:21:09 +02:00
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
2019-10-10 12:14:29 +02:00
}
2019-10-11 03:21:09 +02:00
items = append(items, item)
2019-10-10 12:14:29 +02:00
}
2019-10-11 03:21:09 +02:00
}
2019-10-10 12:14:29 +02:00
cwm.ItemList = items
2019-10-11 03:51:03 +02:00
cwm.Msg = m
2019-10-10 12:14:29 +02:00
return &cwm, nil
}
2019-08-22 11:31:16 +02:00
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGStock, error) {
2019-08-22 11:32:36 +02:00
cwm := ChatWarsMessageGStock{}
2019-12-13 12:19:52 +01:00
stock := []ChatWarsItems{}
2019-06-02 11:52:10 +02:00
re := regexp.MustCompile(`\n([0-9a-z]+) (.*) x ([0-9]+)`)
2019-06-02 11:50:29 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Stock}"), -1) {
2019-06-02 15:27:53 +02:00
i := getObjItemID(l[1], l[2])
2019-06-02 12:33:55 +02:00
q, _ := strconv.ParseInt(l[3], 10, 64)
if i != 0 {
item := ChatWarsItems{
2020-01-14 04:34:29 +01:00
Code: l[1],
Name: l[2],
2019-06-02 12:33:55 +02:00
ItemID64: i,
Quantity: q,
}
2019-12-13 12:19:52 +01:00
stock = append(stock, item)
2019-06-02 12:33:55 +02:00
}
2019-06-02 11:30:04 +02:00
}
2019-12-13 12:19:52 +01:00
cwm.Stock = stock
2019-10-11 03:51:03 +02:00
cwm.Msg = m
2019-06-02 11:30:04 +02:00
return &cwm, nil
}
2020-02-03 05:06:41 +01:00
func parseSubTypeMessageTributesStatsAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTributesStatsAck, error) {
cwm := ChatWarsMessageTributesStatsAck{}
2020-02-03 07:28:11 +01:00
cwm.Msg = m
2020-02-03 07:34:21 +01:00
tributes := []ChatWarsTribute{}
2020-02-03 07:28:11 +01:00
2020-02-03 05:14:02 +01:00
re := regexp.MustCompile(`(\n(?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]+)🔥)`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Tributes}"), -1) {
2020-02-03 07:26:16 +01:00
tribute := ChatWarsTribute{}
2020-02-03 07:20:57 +01:00
d, err := fromChatWarsDate(re.ReplaceAllString(l[0], "${Date}"))
2020-02-03 07:18:17 +01:00
logOnError(err, "parseSubTypeMessageTributesStatsAck : fromChatWarsDate")
2020-02-03 07:32:21 +01:00
tribute.Date = d
2020-02-03 07:18:17 +01:00
tribute.ItemID64 = getSilentObjItemID(``, re.ReplaceAllString(l[0], "${Item}"))
2020-02-03 07:38:01 +01:00
tribute.Quantity, err = strconv.ParseInt(re.ReplaceAllString(l[0], "${Quantity}"), 10, 64)
2020-02-03 07:37:04 +01:00
logOnError(err, "parseSubTypeMessageTributesStatsAck : ParseInt")
2020-02-03 07:38:01 +01:00
tribute.Exp, err = strconv.ParseInt(re.ReplaceAllString(l[0], "${Exp}"), 10, 64)
2020-02-03 07:37:04 +01:00
logOnError(err, "parseSubTypeMessageTributesStatsAck : ParseInt")
2020-02-03 07:52:21 +01:00
tributes = append(tributes, tribute)
2020-02-03 05:06:41 +01:00
}
2020-02-03 07:34:21 +01:00
cwm.Tributes = tributes
2020-02-03 05:06:41 +01:00
return &cwm, nil
}
2020-02-06 03:23:50 +01:00
func parseSubTypeMessageShopMainAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageShopMainAck, error) {
cwm := ChatWarsMessageShopMainAck{}
cwm.Msg = m
cwm.Name = r.ReplaceAllString(m.Text, "${Name}")
2020-02-06 09:48:06 +01:00
cwm.ShopNumber, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Number}"), 10, 64)
2020-02-06 03:44:10 +01:00
cwm.User = r.ReplaceAllString(m.Text, "${User}")
2020-02-06 09:48:06 +01:00
cwm.Mana, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Mana}"), 10, 64)
cwm.ManaTotal, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaTotal}"), 10, 64)
2020-02-06 03:44:10 +01:00
cwm.Class = r.ReplaceAllString(m.Text, "${Class}")
2020-02-06 09:48:06 +01:00
cwm.CastleID64 = getObjCastleID(r.ReplaceAllString(m.Text, "${Castle}"))
2020-02-06 09:12:03 +01:00
cwm.Fees = r.ReplaceAllString(m.Text, "${Fees}")
cwm.Guru = r.ReplaceAllString(m.Text, "${Guru}")
2020-02-06 09:48:06 +01:00
if r.ReplaceAllString(m.Text, "${Open}") == `open` {
cwm.Open = true
} else {
cwm.Open = false
}
2020-02-06 03:23:50 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Name : %s\n", cwm.Name)
2020-02-06 09:48:06 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Number : %d\n", cwm.ShopNumber)
2020-02-06 03:45:40 +01:00
log.Printf("parseSubTypeMessageShopMainAck : User : %s\n", cwm.User)
2020-02-06 09:48:06 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Mana : %d\n", cwm.Mana)
log.Printf("parseSubTypeMessageShopMainAck : ManaTotal : %d\n", cwm.ManaTotal)
2020-02-06 03:45:40 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Class : %s\n", cwm.Class)
2020-02-06 09:48:06 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Castle : %d\n", cwm.CastleID64)
2020-02-06 09:12:03 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Fees : %s\n", cwm.Fees)
log.Printf("parseSubTypeMessageShopMainAck : Guru : %s\n", cwm.Guru)
2020-02-06 09:48:06 +01:00
log.Printf("parseSubTypeMessageShopMainAck : Status : %v\n", cwm.Open)
2020-02-06 03:23:50 +01:00
return &cwm, nil
}
2019-05-28 06:14:46 +02:00
func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
2019-05-31 04:02:21 +02:00
var i int64
2019-05-30 07:49:11 +02:00
cwm := ChatWarsMessageMeAck{
2019-07-31 10:57:45 +02:00
CWUserID64: getObjUserID(r.ReplaceAllString(m.Text, "${Player}")),
CWGuildID64: getObjGuildID(r.ReplaceAllString(m.Text, "${Guild}")),
State: r.ReplaceAllString(m.Text, "${State}"),
2020-01-06 07:55:13 +01:00
Class: r.ReplaceAllString(m.Text, "${Class}"),
2019-05-30 07:49:11 +02:00
}
2019-05-31 04:04:37 +02:00
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ExpNow}"), 10, 64)
2019-05-31 04:02:21 +02:00
cwm.ExpNow = i
2019-05-31 04:04:37 +02:00
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ExpLvl}"), 10, 64)
2019-05-31 04:02:21 +02:00
cwm.ExpLvl = i
2019-05-31 04:04:37 +02:00
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Level}"), 10, 64)
2019-05-31 04:02:21 +02:00
cwm.Level = i
2019-05-28 09:00:37 +02:00
/*
2020-01-12 10:56:08 +01:00
log.Printf("parseSubTypeMessageMeAck : Me report identified\n")
log.Printf("parseSubTypeMessageMeAck : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
log.Printf("parseSubTypeMessageMeAck : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
log.Printf("parseSubTypeMessageMeAck : Class : %s\n", cwm.Class)
log.Printf("parseSubTypeMessageMeAck : Atk : %s\n", r.ReplaceAllString(m.Text, "${Atk}"))
log.Printf("parseSubTypeMessageMeAck : Def : %s\n", r.ReplaceAllString(m.Text, "${Def}"))
log.Printf("parseSubTypeMessageMeAck : ExpNow : %s\n", r.ReplaceAllString(m.Text, "${ExpNow}"))
log.Printf("parseSubTypeMessageMeAck : ExpLvl : %s\n", r.ReplaceAllString(m.Text, "${ExpLvl}"))
log.Printf("parseSubTypeMessageMeAck : StaminaNow : %s\n", r.ReplaceAllString(m.Text, "${StaminaNow}"))
log.Printf("parseSubTypeMessageMeAck : StaminaMax : %s\n", r.ReplaceAllString(m.Text, "${StaminaMax}"))
log.Printf("parseSubTypeMessageMeAck : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
log.Printf("parseSubTypeMessageMeAck : Pogs : %s\n", r.ReplaceAllString(m.Text, "${Pogs}"))
log.Printf("parseSubTypeMessageMeAck : Gems : %s\n", r.ReplaceAllString(m.Text, "${Gems}"))
log.Printf("parseSubTypeMessageMeAck : AtkGear : %s\n", r.ReplaceAllString(m.Text, "${AtkGear}"))
log.Printf("parseSubTypeMessageMeAck : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}"))
log.Printf("parseSubTypeMessageMeAck : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}"))
log.Printf("parseSubTypeMessageMeAck : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}"))
2019-05-28 09:00:37 +02:00
*/
2019-08-21 08:37:53 +02:00
cwm.Msg = m
2019-05-28 09:00:37 +02:00
return &cwm, nil
}
2019-05-28 06:14:46 +02:00
2019-05-30 10:36:40 +02:00
func parseSubTypeMessageGRolesAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGRolesAck, error) {
cwm := ChatWarsMessageGRolesAck{
Msg: m,
}
/*
BartenderID64: getObjUserID(r.ReplaceAllString(m.Text, "${Bartender}")),
CommanderID64: getObjUserID(r.ReplaceAllString(m.Text, "${Commander}")),
SquireID64: getObjUserID(r.ReplaceAllString(m.Text, "${Squire}")),
TreasurerID64: getObjUserID(r.ReplaceAllString(m.Text, "${Treasurer}")),
*/
2019-08-12 10:42:18 +02:00
if len(r.ReplaceAllString(m.Text, "${Bartender}")) > 0 {
2019-08-12 10:30:06 +02:00
cwm.BartenderID64 = getObjUserID(r.ReplaceAllString(m.Text, "${Bartender}"))
2019-05-30 10:55:38 +02:00
} else {
cwm.BartenderID64 = 0
2019-05-30 10:53:57 +02:00
}
2019-08-12 10:42:18 +02:00
if len(r.ReplaceAllString(m.Text, "${Commander}")) > 0 {
2019-08-12 10:30:06 +02:00
cwm.CommanderID64 = getObjUserID(r.ReplaceAllString(m.Text, "${Commander}"))
2019-05-30 10:55:38 +02:00
} else {
cwm.CommanderID64 = 0
2019-05-30 10:53:57 +02:00
}
2019-08-12 10:42:18 +02:00
if len(r.ReplaceAllString(m.Text, "${Squire}")) > 0 {
2019-08-12 10:30:06 +02:00
cwm.SquireID64 = getObjUserID(r.ReplaceAllString(m.Text, "${Squire}"))
2019-05-30 10:55:38 +02:00
} else {
cwm.SquireID64 = 0
2019-05-30 10:53:57 +02:00
}
2019-08-12 10:42:18 +02:00
if len(r.ReplaceAllString(m.Text, "${Treasurer}")) > 0 {
2019-08-12 10:30:06 +02:00
cwm.TreasurerID64 = getObjUserID(r.ReplaceAllString(m.Text, "${Treasurer}"))
2019-05-30 10:55:38 +02:00
} else {
cwm.TreasurerID64 = 0
2019-05-30 10:53:57 +02:00
}
2019-08-13 05:09:44 +02:00
/*
log.Printf("parseSubTypeMessageGRolesAck : Guild roles Ack identified\n")
log.Printf("parseSubTypeMessageGRolesAck : Bartender : %s\n", r.ReplaceAllString(m.Text, "${Bartender}"))
log.Printf("parseSubTypeMessageGRolesAck : Commander : %s\n", r.ReplaceAllString(m.Text, "${Commander}"))
log.Printf("parseSubTypeMessageGRolesAck : Squire : %s\n", r.ReplaceAllString(m.Text, "${Squire}"))
log.Printf("parseSubTypeMessageGRolesAck : Treasurer : %s\n", r.ReplaceAllString(m.Text, "${Treasurer}"))
log.Printf("cwm.BartenderID64 : %d\n", cwm.BartenderID64)
log.Printf("cwm.CommanderID64 : %d\n", cwm.CommanderID64)
log.Printf("cwm.SquireID64 : %d\n", cwm.SquireID64)
log.Printf("cwm.TreasurerID64 : %d\n", cwm.TreasurerID64)
*/
2019-08-21 08:37:53 +02:00
cwm.Msg = m
2019-05-30 10:36:40 +02:00
return &cwm, nil
}
2019-05-28 09:00:37 +02:00
func parseSubTypeMessageGoQuestAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGoQuestAck, error) {
cwm := ChatWarsMessageGoQuestAck{}
2020-01-16 08:37:15 +01:00
/*
log.Printf("parseSubTypeMessageGoQuestAck : Go Quest Ack report identified\n")
log.Printf("parseSubTypeMessageGoQuestAck : Place : %s\n", r.ReplaceAllString(m.Text, "${Place}"))
log.Printf("parseSubTypeMessageGoQuestAck : Time : %s\n", r.ReplaceAllString(m.Text, "${Time}"))
*/
2019-07-09 07:04:23 +02:00
switch quest := strings.ToLower(r.ReplaceAllString(m.Text, "${Place}")); quest {
case "forest":
2020-01-02 16:36:28 +01:00
cwm.QuestTypeID64 = cacheObjSubType[`quest_forest`]
2020-01-12 14:43:15 +01:00
case "mountains":
cwm.QuestTypeID64 = cacheObjSubType[`quest_mountains`]
2019-07-09 07:04:23 +02:00
default:
log.Printf("parseSubTypeMessageGoQuestAck : no reference for quest `%s`\n", quest)
2020-01-02 16:36:28 +01:00
cwm.QuestTypeID64 = cacheObjSubType[`quest_forest`]
2019-07-09 07:04:23 +02:00
}
2019-07-08 12:31:22 +02:00
i, err := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Time}"), 10, 64)
2020-01-16 08:37:15 +01:00
if err == nil {
2019-07-08 12:33:24 +02:00
cwm.Duration = time.Duration(i) * time.Minute
2019-07-08 12:31:22 +02:00
} else {
cwm.Duration = 0 * time.Minute
}
2019-08-21 08:37:53 +02:00
cwm.Msg = m
2019-05-28 06:14:46 +02:00
return &cwm, nil
}
2019-05-25 13:12:31 +02:00
func parseSubTypeMessageUnionWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageUnionWar, error) {
2019-05-26 13:30:21 +02:00
//re := regexp.MustCompile('^(🏠Trade union news:\\n)(?P<Union>(?s:[^(🎪State of exclusive rights)]*))(🎪State of exclusive rights:)(?P<Fair>(?s:.*))$')
2019-05-25 13:12:31 +02:00
/*
"^(🏠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{}
/*
2020-01-12 10:56:08 +01:00
log.Printf("parseSubTypeMessageUnionWar : War report identified\n")
log.Printf("parseSubTypeMessageUnionWar : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
log.Printf("parseSubTypeMessageUnionWar : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
log.Printf("parseSubTypeMessageUnionWar : User : %s\n", r.ReplaceAllString(m.Text, "${User}"))
log.Printf("parseSubTypeMessageUnionWar : Attack : %s\n", r.ReplaceAllString(m.Text, "${Attack}"))
log.Printf("parseSubTypeMessageUnionWar : AttackMod : %s\n", r.ReplaceAllString(m.Text, "${AttackMod}"))
log.Printf("parseSubTypeMessageUnionWar : Defense : %s\n", r.ReplaceAllString(m.Text, "${Defense}"))
log.Printf("parseSubTypeMessageUnionWar : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
log.Printf("parseSubTypeMessageUnionWar : Exp : %s\n", r.ReplaceAllString(m.Text, "${Exp}"))
log.Printf("parseSubTypeMessageUnionWar : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
log.Printf("parseSubTypeMessageUnionWar : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
log.Printf("parseSubTypeMessageUnionWar : Stamina : %s\n", r.ReplaceAllString(m.Text, "${Stamina}"))
log.Printf("parseSubTypeMessageUnionWar : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
2019-05-25 13:12:31 +02:00
*/
return &cwm, nil
}
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-19 14:00:18 +02:00
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}")
2019-05-18 16:15:24 +02:00
return &cwm, nil
}
2019-12-19 04:31:28 +01:00
func parseSubTypeMessageTimeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTimeAck, error) {
cwm := ChatWarsMessageTimeAck{}
2019-12-19 04:32:10 +01:00
t, err := fromChatWarsDate(r.ReplaceAllString(m.Text, "${Day}") + " " + r.ReplaceAllString(m.Text, "${Month}") + " " + r.ReplaceAllString(m.Text, "${Year}") + " " + r.ReplaceAllString(m.Text, "${Hour}") + ":" + r.ReplaceAllString(m.Text, "${Minute}"))
2019-12-19 04:31:28 +01:00
logOnError(err, "parseSubTypeMessageTimeAck : fromChatWarsDate")
cwm.RealTime = t
cwm.TimeOfDay = r.ReplaceAllString(m.Text, "${Time}")
cwm.Hour, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Hour}"), 10, 64)
cwm.Minute, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Minute}"), 10, 64)
cwm.Day, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Day}"), 10, 64)
2019-12-19 04:34:11 +01:00
cwm.Month = int64(chatWarsMonth[r.ReplaceAllString(m.Text, "${Month}")])
2019-12-19 04:31:28 +01:00
cwm.Year, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Year}"), 10, 64)
cwm.Weather = r.ReplaceAllString(m.Text, "${Weather}")
cwm.WeatherNext = r.ReplaceAllString(m.Text, "${WeatherNext}")
2019-12-19 04:32:33 +01:00
return &cwm, nil
2019-12-19 04:31:28 +01:00
}
2019-10-20 14:09:25 +02:00
func parseSubTypeMessageQuestResultAmbush(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageQuestResultAmbush, error) {
2019-10-20 14:28:16 +02:00
var lvlSum, qtySum int64
2019-10-20 14:21:18 +02:00
2019-10-20 14:09:25 +02:00
cwm := ChatWarsMessageQuestResultAmbush{}
2019-10-20 14:24:52 +02:00
re := regexp.MustCompile(`([0-9]){0,1}( x ){0,1}([a-zA-Z ]*) lvl\.([0-9]*)`)
2019-10-20 14:09:25 +02:00
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Monsters}"), -1) {
2019-10-20 14:13:51 +02:00
log.Printf("parseSubTypeMessageQuestResultAmbush : %s\n", l[1])
log.Printf("parseSubTypeMessageQuestResultAmbush : %s\n", l[2])
log.Printf("parseSubTypeMessageQuestResultAmbush : %s\n", l[3])
2019-10-20 14:24:52 +02:00
log.Printf("parseSubTypeMessageQuestResultAmbush : %s\n", l[4])
2019-10-20 14:21:39 +02:00
qty, _ := strconv.ParseInt(l[1], 10, 64)
2019-10-20 14:21:58 +02:00
log.Printf("parseSubTypeMessageQuestResultAmbush : qty : %d\n", qty)
2019-10-20 14:24:52 +02:00
if qty == 0 {
qty = 1
}
lvl, _ := strconv.ParseInt(l[4], 10, 64)
log.Printf("parseSubTypeMessageQuestResultAmbush : lvl : %d\n", lvl)
2019-10-20 14:28:16 +02:00
lvlSum = lvlSum + lvl
qtySum = qtySum + qty
2019-10-20 14:09:25 +02:00
}
2019-10-20 14:28:16 +02:00
cwm.Level = lvlSum / qtySum
2019-10-20 14:09:25 +02:00
cwm.Msg = m
2019-10-20 14:28:16 +02:00
log.Printf("parseSubTypeMessageQuestResultAmbush : Level : %d\n", cwm.Level)
2019-10-20 14:09:25 +02:00
return &cwm, nil
}
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
}
2020-01-17 03:47:03 +01:00
func parseSubTypeMessageJobGWithdrawAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageJobGWithdrawAck, error) {
cwm := ChatWarsMessageJobGWithdrawAck{}
cwm.Ref = r.ReplaceAllString(m.Text, "${Ref}")
cwm.Msg = m
return &cwm, nil
}