This commit is contained in:
shoopea 2020-06-27 11:54:13 +02:00
parent 99bda82986
commit 8f451118cb
4 changed files with 36 additions and 2 deletions

1
def.go
View File

@ -375,6 +375,7 @@ type ChatWarsMessageUnionWar struct {
}
type ChatWarsMessageTimeAck struct {
ObjID64 int64 `json:"obj_id"`
RealTime time.Time `json:"real_time"`
TimeOfDay string `json:"time_of_day"`
Hour int64 `json:"hour"`

2
msg.go
View File

@ -619,6 +619,7 @@ func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
func parseSubTypeMessageTimeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageTimeAck, error) {
cwm := ChatWarsMessageTimeAck{}
cwm.ObjID64 = m.ObjID64
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}"))
logOnError(err, "parseSubTypeMessageTimeAck : fromChatWarsDate")
cwm.RealTime = t
@ -630,7 +631,6 @@ func parseSubTypeMessageTimeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWars
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}")
log.Printf("parseSubTypeMessageTimeAck : drift %v", m.Date.Sub(cwm.RealTime))
return &cwm, nil
}

32
sql.go
View File

@ -383,6 +383,14 @@ func initDB() {
failOnError(err, "initDB : create table obj_msg_shop_main")
log.Println("initDB : obj_msg_shop_main created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_time (
obj_id BIGINT UNSIGNED NOT NULL
,date DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_time")
log.Println("initDB : obj_msg_time created ...")
_, err = db.Exec(`CREATE TABLE obj_tribute (
tg_user_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
@ -879,6 +887,30 @@ func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
return nil
}
func insertMsgTimeAck(m *ChatWarsMessageTimeAck) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_time_ack`] {
return errors.New("Message type mismatch")
}
stmt, err := db.Prepare(`INSERT INTO obj_msg_time (obj_id, date)
VALUES (?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
_, err = stmt.Exec(m.ObjID64, m.RealTime)
if err != nil {
return err
}
return nil
}
func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {

View File

@ -497,8 +497,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
*/
}
case cacheObjSubType[`msg_time_ack`]:
_, err := parseSubTypeMessageTimeAck(m, rule.re)
cwm, err := parseSubTypeMessageTimeAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_time_ack`]")
err = insertMsgTimeAck(cwm)
case cacheObjSubType[`msg_orderbook_acl`]:
_, err := parseSubTypeMessageOrderbookAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_orderbook_acl`]")