This commit is contained in:
shoopea 2019-05-11 13:56:51 +08:00
parent 673d2e29ab
commit 89615155e2
3 changed files with 13 additions and 7 deletions

View File

@ -81,6 +81,7 @@ func main() {
if *initdb {
initDB()
}
resetMsgParsingRules()
msgParsingRules, err = loadMsgParsingRules()
logOnError(err, "Message parsing rules")

17
sql.go
View File

@ -254,12 +254,6 @@ func initDB() {
;`)
failOnError(err, "initDB : populate table code_obj_sub_type")
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReport) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(?P<Guild>(\\[[A-Z]{3}\\]){0,1})(?P<User>([A-Za-z0-9 ]*)) ⚔:(?P<Attack>[0-9]+)(?P<AttackMod>\\((-|\\+)[0-9]+\\)){0,1} 🛡:(?P<Defense>[0-9]+) Lvl: (?P<Level>[0-9]+)\\nYour result on the battlefield:\\n🔥Exp: (?P<Exp>[0-9]+)\\n💰Gold: (?P<Gold>-{0,1}[0-9]+)\\n📦Stock: (?P<Stock>-{0,1}[0-9]+)(\\n)*(?P<Stamina>(🔋Stamina restored)){0,1}(\\n)*(?P<Crit>(⚡Critical strike)){0,1}(\\n)*(?s:.*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "Auction annouce", "^Lot #(?P<Lot>[0-9]+) : (?P<Item>.*)\\nSeller: (?P<Seller>.*)\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (?P<Buyer>.*)\\nEnd At: (?P<End>.*)\\nStatus: (?P<Status>.*)(\\n)*(?s:.*)")
,(5000, ` + strconv.Itoa(objSubTypeMessageTime) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>[a-zA-Z]+) (?P<Year>[0-9]{4})\\n(?s:.*)");`)
failOnError(err, "initDB : populate table msg_rules")
_, err = db.Exec(`
INSERT INTO obj (id, obj_type_id, obj_sub_type_id) VALUES
(1, 7, 701),
@ -1217,6 +1211,17 @@ INSERT INTO obj_item (obj_id, intl_id, name, weight) VALUES
log.Println("Database set up")
}
func resetMsgParsingRules() {
_, err := db.Exec(`TRUNCATE TABLE msg_rules;`)
failOnError(err, "resetMsgParsingRules : truncate table msg_rules")
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReport) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(?P<Guild>(\\[[A-Z]{3}\\]){0,1})(?P<User>([A-Za-z0-9 ]*)) ⚔:(?P<Attack>[0-9]+)(?P<AttackMod>\\((-|\\+)[0-9]+\\)){0,1} 🛡:(?P<Defense>[0-9]+) Lvl: (?P<Level>[0-9]+)\\nYour result on the battlefield:\\n🔥Exp: (?P<Exp>[0-9]+)\\n💰Gold: (?P<Gold>-{0,1}[0-9]+)\\n📦Stock: (?P<Stock>-{0,1}[0-9]+)(\\n)*(?P<Stamina>(🔋Stamina restored)){0,1}(\\n)*(?P<Crit>(⚡Critical strike)){0,1}(\\n)*(?s:.*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "Auction annouce", "^Lot #(?P<Lot>[0-9]+) : (?P<Item>.*)\\nSeller: (?P<Seller>.*)\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (?P<Buyer>.*)\\nEnd At: (?P<End>.*)\\nStatus: (?P<Status>.*)(\\n)*(?s:.*)")
,(5000, ` + strconv.Itoa(objSubTypeMessageTime) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>[a-zA-Z]+) (?P<Year>[0-9]{4})\\n(?s:.*)");`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
}
func putUnprocessedMsg(m ChatWarsMessage) (int64, error) {
res, err := db.Exec(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
VALUES (` + strconv.Itoa(objTypeMessage) + `,` + strconv.Itoa(objSubTypeMessageUnknown) + `);`)

View File

@ -80,7 +80,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
}
if i == len(msgParsingRules) {
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Can't find message type in rules(%d)\n", objId)
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Can't find message type in rules(%d)\n%s\n", objId, m.Text)
} else {
r := msgParsingRules[i].re
switch msgParsingRules[i].MsgTypeID {