update shop main

This commit is contained in:
shoopea 2020-02-06 16:48:06 +08:00
parent bd23ca0cf3
commit e0ccfc39c2
5 changed files with 81 additions and 22 deletions

View File

@ -1890,7 +1890,7 @@
{
"prio": 5000,
"descn": "Shop main ack",
"rule": "^Welcome, to the (?P<Name>[a-zA-Z0-9 -]+) #(?P<Number>[0-9]+)\\.\\n(?P<User>.+) (?P<Mana>[0-9]+)\\/(?P<ManaTotal>[0-9]+)💧the (?P<Class>.+) from (?P<Castle>.+)\\n\\n(?P<Fees>.*)\\n\\n(the (?P<Guru>.*) Guru\\n\\n){0,1}.* is (?P<Status>(open|closed))\\.\\n(?s:.*)$",
"rule": "^Welcome, to the (?P<Name>[a-zA-Z0-9 -]+) #(?P<Number>[0-9]+)\\.\\n(?P<User>.+) (?P<Mana>[0-9]+)\\/(?P<ManaTotal>[0-9]+)💧the (?P<Class>.+) from (?P<Castle>.+)\\n\\n(?P<Fees>.*)\\n\\n(the (?P<Guru>.*) Guru\\n\\n){0,1}.* is (?P<Open>(open|closed))\\.\\n(?s:.*)$",
"msg_type": "msg_shop_main_ack",
"chat_id": 0,
"user_id": 0

22
def.go
View File

@ -368,17 +368,17 @@ type ChatWarsMessageTributesStatsAck struct {
}
type ChatWarsMessageShopMainAck struct {
Msg *ChatWarsMessage `json:"msg"`
Name string `json:"name"`
Number string `json:"number"`
User string `json:"userr"`
Mana string `json:"mana"`
ManaTotal string `json:"mana_total"`
Class string `json:"class"`
Castle string `json:"castle"`
Fees string `json:"fees"`
Guru string `json:"guru"`
Status string `json:"status"`
Msg *ChatWarsMessage `json:"msg"`
Name string `json:"name"`
ShopNumber int64 `json:"shop_number"`
User string `json:"user"`
Mana int64 `json:"mana"`
ManaTotal int64 `json:"mana_total"`
Class string `json:"class"`
CastleID64 int64 `json:"castle"`
Fees string `json:"fees"`
Guru string `json:"guru"`
Open bool `json:"open"`
}
type MessageParsingRule struct {

24
msg.go
View File

@ -303,26 +303,30 @@ func parseSubTypeMessageShopMainAck(m *ChatWarsMessage, r *regexp.Regexp) (*Chat
cwm.Msg = m
cwm.Name = r.ReplaceAllString(m.Text, "${Name}")
cwm.Number = r.ReplaceAllString(m.Text, "${Number}")
cwm.ShopNumber, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Number}"), 10, 64)
cwm.User = r.ReplaceAllString(m.Text, "${User}")
cwm.Mana = r.ReplaceAllString(m.Text, "${Mana}")
cwm.ManaTotal = r.ReplaceAllString(m.Text, "${ManaTotal}")
cwm.Mana, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Mana}"), 10, 64)
cwm.ManaTotal, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaTotal}"), 10, 64)
cwm.Class = r.ReplaceAllString(m.Text, "${Class}")
cwm.Castle = r.ReplaceAllString(m.Text, "${Castle}")
cwm.CastleID64 = getObjCastleID(r.ReplaceAllString(m.Text, "${Castle}"))
cwm.Fees = r.ReplaceAllString(m.Text, "${Fees}")
cwm.Guru = r.ReplaceAllString(m.Text, "${Guru}")
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
if r.ReplaceAllString(m.Text, "${Open}") == `open` {
cwm.Open = true
} else {
cwm.Open = false
}
log.Printf("parseSubTypeMessageShopMainAck : Name : %s\n", cwm.Name)
log.Printf("parseSubTypeMessageShopMainAck : Number : %s\n", cwm.Number)
log.Printf("parseSubTypeMessageShopMainAck : Number : %d\n", cwm.ShopNumber)
log.Printf("parseSubTypeMessageShopMainAck : User : %s\n", cwm.User)
log.Printf("parseSubTypeMessageShopMainAck : Mana : %s\n", cwm.Mana)
log.Printf("parseSubTypeMessageShopMainAck : ManaTotal : %s\n", cwm.ManaTotal)
log.Printf("parseSubTypeMessageShopMainAck : Mana : %d\n", cwm.Mana)
log.Printf("parseSubTypeMessageShopMainAck : ManaTotal : %d\n", cwm.ManaTotal)
log.Printf("parseSubTypeMessageShopMainAck : Class : %s\n", cwm.Class)
log.Printf("parseSubTypeMessageShopMainAck : Castle : %s\n", cwm.Castle)
log.Printf("parseSubTypeMessageShopMainAck : Castle : %d\n", cwm.CastleID64)
log.Printf("parseSubTypeMessageShopMainAck : Fees : %s\n", cwm.Fees)
log.Printf("parseSubTypeMessageShopMainAck : Guru : %s\n", cwm.Guru)
log.Printf("parseSubTypeMessageShopMainAck : Status : %s\n", cwm.Status)
log.Printf("parseSubTypeMessageShopMainAck : Status : %v\n", cwm.Open)
return &cwm, nil
}

53
sql.go
View File

@ -327,6 +327,24 @@ func initDB() {
failOnError(err, "initDB : create table obj_msg_tribute")
log.Println("initDB : obj_msg_tribute created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_shop_main (
obj_id BIGINT UNSIGNED NOT NULL
,name VARCHAR(80)
,number INT UNSIGNED NOT NULL
,user VARCHAR(80)
,mana INT UNSIGNED NOT NULL
,mana_total INT UNSIGNED NOT NULL
,class VARCHAR(80)
,castle_id BIGINT UNSIGNED NOT NULL
,fees VARCHAR(80)
,guru VARCHAR(80)
,open TINYINT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (castle_id) REFERENCES obj_castle(obj_id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_shop_main")
log.Println("initDB : obj_msg_shop_main created ...")
_, err = db.Exec(`CREATE TABLE obj_tribute (
tg_user_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
@ -699,6 +717,41 @@ func insertMsgTributesStats(m *ChatWarsMessageTributesStatsAck) error {
return nil
}
func insertMsgShopMainAck(m *ChatWarsMessageShopMainAck) error {
objSubTypeId, err := getObjSubTypeId(m.Msg.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_shop_main_ack`] {
return errors.New("Message type mismatch")
}
return nil
/*
stmt, err := db.Prepare(`INSERT INTO obj_msg_shop_main (obj_id, name, quantity, user, mana, mana_total, class, castle_id, fees, open)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
logOnError(err, "insertMsgShopMainAck : Prepare")
if err != nil {
return err
}
defer stmt.Close()
var open int
if cwm.Open {
open = 1
} else {
open = 0
}
_, err = stmt.Exec(m.Msg.ID64, t.ItemID64, t.Quantity, t.Exp, t.Date)
logOnError(err, "insertMsgShopMainAck Exec")
return nil
*/
}
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {

View File

@ -527,6 +527,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case cacheObjSubType[`msg_shop_main_ack`]:
_, err := parseSubTypeMessageShopMainAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_shop_main_ack`]")
err = insertMsgShopMainAck(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgShopMainAck")
default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text)
}