chirpnest/def.go
2019-05-08 23:20:38 +08:00

80 lines
2.4 KiB
Go

package main
import (
"log"
"regexp"
"time"
)
type ChatWarsMessage struct {
UserID64 int64 `json:"user_id"`
SenderUserID64 int64 `json:"sender_user_id"`
Date int32 `json:"date"`
ID64 int64 `json:"id"`
ChatID64 int64 `json:"chat_id"`
Text string `json:"text"`
}
type MessageParsingRule struct {
ID int32
Priority int32
Description string
Rule string
MsgTypeID int32
re *regexp.Regexp
}
const (
objTypeUser = 1
objTypeGuild = 2
objTypeMessage = 3
objTypeWar = 4
objTypeWarReport = 5
objTypeJob = 6
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
objSubTypeJobPillage = 601
objSubTypeJobTribute = 602
objSubTypeJobStatus = 603
objSubTypeJobWithdrawal = 604
objSubTypeJobGStock = 605
MQGetMsgWorkers = 3
SQLCWMsgWorkers = 6
SQLIdentifyMsgWorkers = 6
SQLJobWorkers = 3
)
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 {
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}"))
return time.Now(), nil
} else {
return time.Now(), errors.New("Wrong format")
}
}
func toChatWarsDate(t time.Time) (s string, err error) {
return "test", nil
}