test
This commit is contained in:
parent
ea5812e98c
commit
419f917b3b
62
def.go
62
def.go
@ -1,12 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
UserID64 int64 `json:"user_id"`
|
||||
SenderUserID64 int64 `json:"sender_user_id"`
|
||||
@ -16,6 +9,19 @@ type ChatWarsMessage struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageAuctionAnnounce struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
LotID int32 `json:"lot_id"`
|
||||
Item string `json:"item"`
|
||||
Cond string `json:"cond"`
|
||||
Quality string `json:"quality"`
|
||||
Seller string `json:"seller"`
|
||||
Buyer string `json:"buyer"`
|
||||
Price int32 `json:"price"`
|
||||
Status string `json:"status"`
|
||||
End int64 `json:"end"`
|
||||
}
|
||||
|
||||
type MessageParsingRule struct {
|
||||
ID int32
|
||||
Priority int32
|
||||
@ -102,45 +108,3 @@ var (
|
||||
11: 30,
|
||||
12: 31}
|
||||
)
|
||||
|
||||
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}"))
|
||||
year, _ := strconv.Atoi(r.ReplaceAllString(d, "${Year}"))
|
||||
day, _ := strconv.Atoi(r.ReplaceAllString(d, "${Day}"))
|
||||
hour, _ := strconv.Atoi(r.ReplaceAllString(d, "${Hour}"))
|
||||
minute, _ := strconv.Atoi(r.ReplaceAllString(d, "${Minute}"))
|
||||
days := int(0)
|
||||
for i := 1059; i < year; i++ {
|
||||
days = days + 365
|
||||
}
|
||||
for i := 1; i < chatWarsMonth[r.ReplaceAllString(d, "${Month}")]; i++ {
|
||||
if _, special := chatWarsDaysSpecial[year][i]; special {
|
||||
days = days + chatWarsDaysSpecial[year][i]
|
||||
} else {
|
||||
days = days + chatWarsDays[i]
|
||||
}
|
||||
}
|
||||
for i := 1; i < day; i++ {
|
||||
days++
|
||||
}
|
||||
|
||||
t, _ := time.Parse(time.RFC3339, "2017-11-18T21:00:00+00:00")
|
||||
t = t.AddDate(0, 0, (days / 3))
|
||||
t = t.Add(time.Hour * time.Duration(days%3) * 8)
|
||||
t = t.Add(time.Minute * time.Duration(hour) * 20)
|
||||
t = t.Add(time.Second * time.Duration(minute) * 20)
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Now(), errors.New("Wrong format")
|
||||
}
|
||||
}
|
||||
|
||||
func toChatWarsDate(t time.Time) (s string, err error) {
|
||||
return "test", nil
|
||||
}
|
||||
|
42
sql.go
42
sql.go
@ -139,7 +139,7 @@ func initDB() {
|
||||
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
||||
failOnError(err, "initDB : create table obj_msg_report")
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE obj_auction_announce (
|
||||
_, err = db.Exec(`CREATE TABLE obj_msg_auction_announce (
|
||||
obj_id BIGINT UNSIGNED NOT NULL
|
||||
,lot_id BIGINT UNSIGNED NOT NULL
|
||||
,item VARCHAR(80)
|
||||
@ -152,7 +152,7 @@ func initDB() {
|
||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||
,UNIQUE KEY (lot_id)
|
||||
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
|
||||
failOnError(err, "initDB : create table obj_auction_announce")
|
||||
failOnError(err, "initDB : create table obj_msg_auction_announce")
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE msg_rules (
|
||||
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
|
||||
@ -1270,38 +1270,26 @@ func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int3
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertAuctionAnnounce(objId int64, war_date int32, atk int32, def int32, exp int32, gold int32, stock int32, crit bool, stamina bool) error {
|
||||
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
|
||||
objSubTypeId, err := getObjSubTypeId(objId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if objSubTypeId != objSubTypeMessageUnknown {
|
||||
return errors.New("Message is not of type Unknown")
|
||||
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageAuctionAnnounce {
|
||||
return errors.New("Message type mismatch")
|
||||
}
|
||||
/*
|
||||
|
||||
obj_id BIGINT UNSIGNED NOT NULL
|
||||
,lot_id BIGINT UNSIGNED NOT NULL
|
||||
,item VARCHAR(80)
|
||||
,cond VARCHAR(32)
|
||||
,quality VARCHAR(32)
|
||||
,seller VARCHAR(32)
|
||||
,buyer VARCHAR(32)
|
||||
,status VARCHAR(32)
|
||||
,end TIMESTAMP NOT NULL
|
||||
stmt, err := db.Prepare(`INSERT INTO obj_msg_auction_announce (obj_id, lot_id, item, cond, quality, seller, buyer, status, end)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, FROM_UNIXTIME(?));`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
stmt, err := db.Prepare(`INSERT INTO obj_msg_report (obj_id, war_date, attack, defense, gold, stock, exp, stamina, crit)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?FROM_UNIXTIME(?), ?);`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(objId, m.ID64, m.ChatID64, m.UserID64, m.SenderUserID64, m.Date, m.Text)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*/
|
||||
_, err = stmt.Exec(m.MsgID64, m.LotID, m.Item, m.Cond, m.Quality, m.Seller, m.Buyer, m.Status, m.End)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
42
utils.go
42
utils.go
@ -15,3 +15,45 @@ func logOnError(err error, msg string) {
|
||||
log.Printf("%s: %s", msg, err)
|
||||
}
|
||||
}
|
||||
|
||||
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}"))
|
||||
year, _ := strconv.Atoi(r.ReplaceAllString(d, "${Year}"))
|
||||
day, _ := strconv.Atoi(r.ReplaceAllString(d, "${Day}"))
|
||||
hour, _ := strconv.Atoi(r.ReplaceAllString(d, "${Hour}"))
|
||||
minute, _ := strconv.Atoi(r.ReplaceAllString(d, "${Minute}"))
|
||||
days := int(0)
|
||||
for i := 1059; i < year; i++ {
|
||||
days = days + 365
|
||||
}
|
||||
for i := 1; i < chatWarsMonth[r.ReplaceAllString(d, "${Month}")]; i++ {
|
||||
if _, special := chatWarsDaysSpecial[year][i]; special {
|
||||
days = days + chatWarsDaysSpecial[year][i]
|
||||
} else {
|
||||
days = days + chatWarsDays[i]
|
||||
}
|
||||
}
|
||||
for i := 1; i < day; i++ {
|
||||
days++
|
||||
}
|
||||
|
||||
t, _ := time.Parse(time.RFC3339, "2017-11-18T21:00:00+00:00")
|
||||
t = t.AddDate(0, 0, (days / 3))
|
||||
t = t.Add(time.Hour * time.Duration(days%3) * 8)
|
||||
t = t.Add(time.Minute * time.Duration(hour) * 20)
|
||||
t = t.Add(time.Second * time.Duration(minute) * 20)
|
||||
return t, nil
|
||||
} else {
|
||||
return time.Now(), errors.New("Wrong format")
|
||||
}
|
||||
}
|
||||
|
||||
func toChatWarsDate(t time.Time) (s string, err error) {
|
||||
return "test", nil
|
||||
}
|
||||
|
24
workers.go
24
workers.go
@ -100,17 +100,19 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stamina : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stamina}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Crit : %s (%d)\n", r.ReplaceAllString(m.Text, "${Crit}"), objId)
|
||||
case objSubTypeMessageAuctionAnnounce:
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Auction announce (%d)\n", objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Lot : %s (%d)\n", r.ReplaceAllString(m.Text, "${Lot}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Item : %s (%d)\n", r.ReplaceAllString(m.Text, "${Item}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Seller : %s (%d)\n", r.ReplaceAllString(m.Text, "${Seller}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Buyer : %s (%d)\n", r.ReplaceAllString(m.Text, "${Buyer}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Price : %s (%d)\n", r.ReplaceAllString(m.Text, "${Price}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Status : %s (%d)\n", r.ReplaceAllString(m.Text, "${Status}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : End : %s (%d)\n", r.ReplaceAllString(m.Text, "${End}"), objId)
|
||||
t, err := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AuctionAnnounce : end")
|
||||
log.Println(t)
|
||||
m := ChatWarsMessageAuctionAnnounce{
|
||||
ID64: objId,
|
||||
}
|
||||
m.Lot, _ = strconv.Atoi(r.ReplaceAllString(m.Text, "${Lot}"))
|
||||
m.Cond = r.ReplaceAllString(m.Text, "${Cond}")
|
||||
m.Quality = r.ReplaceAllString(m.Text, "${Quality}")
|
||||
m.Seller = r.ReplaceAllString(m.Text, "${Seller}")
|
||||
m.Buyer = r.ReplaceAllString(m.Text, "${Buyer}")
|
||||
m.Price, _ = strconv.Atoi(r.ReplaceAllString(m.Text, "${Price}"))
|
||||
m.Status = r.ReplaceAllString(m.Text, "${Status}")
|
||||
t, _ := fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
|
||||
m.End = t.Unix()
|
||||
insertMsgAuctionAnnounce(&m)
|
||||
case objSubTypeMessageTime:
|
||||
/*
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Time (%d)\n", objId)
|
||||
|
Loading…
Reference in New Issue
Block a user