2019-05-06 04:54:24 +02:00
|
|
|
package main
|
|
|
|
|
2019-05-08 12:33:52 +02:00
|
|
|
import (
|
2019-05-08 17:20:52 +02:00
|
|
|
"errors"
|
2019-05-08 17:19:52 +02:00
|
|
|
"log"
|
2019-05-08 12:33:52 +02:00
|
|
|
"regexp"
|
2019-05-09 05:08:50 +02:00
|
|
|
"strconv"
|
2019-05-08 17:19:52 +02:00
|
|
|
"time"
|
2019-05-08 12:33:52 +02:00
|
|
|
)
|
|
|
|
|
2019-05-06 04:54:24 +02:00
|
|
|
type ChatWarsMessage struct {
|
2019-05-06 05:59:19 +02:00
|
|
|
UserID64 int64 `json:"user_id"`
|
2019-05-06 04:54:24 +02:00
|
|
|
SenderUserID64 int64 `json:"sender_user_id"`
|
|
|
|
Date int32 `json:"date"`
|
|
|
|
ID64 int64 `json:"id"`
|
|
|
|
ChatID64 int64 `json:"chat_id"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
}
|
2019-05-06 05:59:19 +02:00
|
|
|
|
2019-05-07 13:15:25 +02:00
|
|
|
type MessageParsingRule struct {
|
|
|
|
ID int32
|
|
|
|
Priority int32
|
|
|
|
Description string
|
|
|
|
Rule string
|
|
|
|
MsgTypeID int32
|
2019-05-08 12:33:52 +02:00
|
|
|
re *regexp.Regexp
|
2019-05-07 13:15:25 +02:00
|
|
|
}
|
|
|
|
|
2019-05-06 05:59:19 +02:00
|
|
|
const (
|
2019-05-07 05:12:03 +02:00
|
|
|
objTypeUser = 1
|
|
|
|
objTypeGuild = 2
|
|
|
|
objTypeMessage = 3
|
|
|
|
objTypeWar = 4
|
|
|
|
objTypeWarReport = 5
|
2019-05-07 13:15:25 +02:00
|
|
|
objTypeJob = 6
|
2019-05-06 05:59:19 +02:00
|
|
|
|
2019-05-08 16:34:47 +02:00
|
|
|
objSubTypeMessageUnknown = 301
|
|
|
|
objSubTypeMessageWar = 302
|
|
|
|
objSubTypeMessageMiniWar = 303
|
|
|
|
objSubTypeMessageGuildWar = 304
|
|
|
|
objSubTypeMessageReport = 305
|
|
|
|
objSubTypeMessageGReport = 306
|
|
|
|
objSubTypeMessageQuest = 307
|
|
|
|
objSubTypeMessageFight = 308
|
|
|
|
objSubTypeMessageHero = 309
|
|
|
|
objSubTypeMessageMe = 310
|
|
|
|
objSubTypeMessageInventory = 311
|
|
|
|
objSubTypeMessagePillageInc = 312
|
|
|
|
objSubTypeMessageTributeInc = 313
|
|
|
|
objSubTypeMessagePillageAck = 314
|
|
|
|
objSubTypeMessageTributeAck = 315
|
|
|
|
objSubTypeMessageAuctionAnnounce = 316
|
2019-05-09 04:43:47 +02:00
|
|
|
objSubTypeMessageTime = 317
|
2019-05-08 16:34:47 +02:00
|
|
|
objSubTypeJobPillage = 601
|
|
|
|
objSubTypeJobTribute = 602
|
|
|
|
objSubTypeJobStatus = 603
|
|
|
|
objSubTypeJobWithdrawal = 604
|
|
|
|
objSubTypeJobGStock = 605
|
2019-05-06 09:25:57 +02:00
|
|
|
|
|
|
|
MQGetMsgWorkers = 3
|
|
|
|
SQLCWMsgWorkers = 6
|
|
|
|
SQLIdentifyMsgWorkers = 6
|
2019-05-07 13:15:25 +02:00
|
|
|
SQLJobWorkers = 3
|
2019-05-06 05:59:19 +02:00
|
|
|
)
|
2019-05-08 17:18:17 +02:00
|
|
|
|
2019-05-09 04:27:21 +02:00
|
|
|
var (
|
|
|
|
chatWarsMonth = map[string]int{
|
|
|
|
"Wintar": 1,
|
|
|
|
"Hornung": 2,
|
|
|
|
"Lenzin": 3,
|
|
|
|
"Ōstar": 4,
|
|
|
|
"Winni": 5,
|
|
|
|
"Brāh": 6,
|
|
|
|
"Hewi": 7,
|
|
|
|
"Aran": 8,
|
|
|
|
"Witu": 9,
|
|
|
|
"Wīndume": 10,
|
|
|
|
"Herbist": 11,
|
|
|
|
"Hailag": 12}
|
2019-05-09 04:28:06 +02:00
|
|
|
|
|
|
|
chatWarsDaysSpecial = map[int]map[int]int{
|
|
|
|
2: {1060: 29},
|
|
|
|
4: {1060: 29}}
|
|
|
|
|
2019-05-09 04:27:21 +02:00
|
|
|
chatWarsDays = map[int]int{
|
|
|
|
1: 31,
|
|
|
|
2: 28,
|
|
|
|
3: 31,
|
|
|
|
4: 30,
|
|
|
|
5: 31,
|
|
|
|
6: 30,
|
|
|
|
7: 31,
|
|
|
|
8: 31,
|
|
|
|
9: 30,
|
|
|
|
10: 31,
|
|
|
|
11: 30,
|
|
|
|
12: 31}
|
|
|
|
)
|
|
|
|
|
2019-05-08 17:18:17 +02:00
|
|
|
func fromChatWarsDate(d string) (t time.Time, err error) {
|
|
|
|
r := regexp.MustCompile(`(?P<Day>[0-9]{2}) (?P<Month>(Wintar|Hornung|Lenzin|Ōstar|Winni|Brāh|Hewi|Aran|Witu|Wīndume|Herbist|Hailag)) (?P<Year>[0-9]{4})( (?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})){0,1}`)
|
|
|
|
if r.FindStringSubmatch(d) != nil {
|
2019-05-08 17:20:38 +02:00
|
|
|
log.Printf("fromChatWarsDate : Day : %s\n", r.ReplaceAllString(d, "${Day}"))
|
|
|
|
log.Printf("fromChatWarsDate : Month : %s\n", r.ReplaceAllString(d, "${Month}"))
|
|
|
|
log.Printf("fromChatWarsDate : Year : %s\n", r.ReplaceAllString(d, "${Year}"))
|
|
|
|
log.Printf("fromChatWarsDate : Hour : %s\n", r.ReplaceAllString(d, "${Hour}"))
|
|
|
|
log.Printf("fromChatWarsDate : Minute : %s\n", r.ReplaceAllString(d, "${Minute}"))
|
2019-05-09 05:04:22 +02:00
|
|
|
days := int(0)
|
|
|
|
for i := 1059; i < strconv.Atoi(r.ReplaceAllString(d, "${Year}")); i++ {
|
|
|
|
days = days + 365
|
|
|
|
}
|
|
|
|
for i := 1; i < chatWarsMonth[r.ReplaceAllString(d, "${Month}")]; i++ {
|
|
|
|
if _, special := chatWarsDaysSpecial[strconv.Atoi(r.ReplaceAllString(d, "${Year}"))][i]; special {
|
|
|
|
days = days + chatWarsDaysSpecial[strconv.Atoi(r.ReplaceAllString(d, "${Year}"))][i]
|
|
|
|
} else {
|
|
|
|
days = days + chatWarsDays[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := 1; i < strconv.Atoi(r.ReplaceAllString(d, "${Day}")); i++ {
|
|
|
|
days++
|
|
|
|
}
|
|
|
|
t, _ := time.Parse(time.RFC3339, "2018-01-31T00:00:00+00:00")
|
2019-05-09 05:06:36 +02:00
|
|
|
t = t.AddDate(0, 0, (days / 3))
|
2019-05-09 05:08:50 +02:00
|
|
|
t = t.Add(time.Hour * ((days % 3) * 8))
|
|
|
|
t = t.Add(time.Minute * (strconv.Atoi(r.ReplaceAllString(d, "${Hour}")) * 20))
|
|
|
|
t = t.Add(time.Second * (strconv.Atoi(r.ReplaceAllString(d, "${Minute}")) * 20))
|
2019-05-09 05:04:22 +02:00
|
|
|
return t, nil
|
2019-05-08 17:18:17 +02:00
|
|
|
} else {
|
2019-05-08 17:20:17 +02:00
|
|
|
return time.Now(), errors.New("Wrong format")
|
2019-05-08 17:18:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toChatWarsDate(t time.Time) (s string, err error) {
|
|
|
|
return "test", nil
|
|
|
|
}
|