test rules

This commit is contained in:
shoopea 2019-12-29 19:45:26 +08:00
parent cce71562f1
commit 7d43e6281d
3 changed files with 73 additions and 6 deletions

View File

@ -131,7 +131,7 @@ func main() {
_, _ = addObjGuild(``, `No Guild`)
}
resetMsgParsingRules()
resetMsgParsingRules2()
msgParsingRules, err = loadMsgParsingRules()
logOnError(err, "Message parsing rules")

36
obj.go
View File

@ -22,6 +22,42 @@ var (
muxObjItemId sync.Mutex
)
func codeObjTypeId(intlId string) (int64, error) {
var objTypeId int64
stmt, err := db.Prepare(`SELECT c.id FROM code_obj_type c WHERE o.intl_id = ?`)
if err != nil {
return 0, err
}
defer stmt.Close()
err = stmt.QueryRow(intlId).Scan(&objTypeId)
if err != nil {
return 0, err
}
return objTypeId, nil
}
func codeObjSubTypeId(intlId string) (int64, error) {
var objSubTypeId int64
stmt, err := db.Prepare(`SELECT c.id FROM code_obj_sub_type c WHERE o.intl_id = ?`)
if err != nil {
return 0, err
}
defer stmt.Close()
err = stmt.QueryRow(intlId).Scan(&objSubTypeId)
if err != nil {
return 0, err
}
return objSubTypeId, nil
}
func getObjTypeId(objId int64) (int64, error) {
var objTypeId int64

View File

@ -7,11 +7,6 @@ import (
func resetMsgParsingRules2() error {
var rules []MessageParsingRule
_, err := db.Exec(`TRUNCATE TABLE msg_rules;`)
logOnError(err, "resetMsgParsingRules2 : truncate table msg_rules")
if err != nil {
return err
}
b, err := Asset("data/msg_rules.json")
logOnError(err, "resetMsgParsingRules2 : load data/msg_rules.json")
@ -21,6 +16,42 @@ func resetMsgParsingRules2() error {
err = json.Unmarshal(b, &rules)
for r := range rules {
r.MsgTypeID64, err = codeObjSubTypeId(r.MsgType)
logOnError(err, "resetMsgParsingRules2 : codeObjSubTypeId("+r.MsgType+")")
if err != nil {
return err
}
i.re, err = regexp.Compile(rule)
logOnError(err, "resetMsgParsingRules2 : Compile("+r.rule+")")
if err != nil {
return err
}
}
_, err := db.Exec(`TRUNCATE TABLE msg_rules;`)
logOnError(err, "resetMsgParsingRules2 : truncate table msg_rules")
if err != nil {
return err
}
stmt, err := db.Prepare(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (?, ?, ?, ?);`)
logOnError(errm "resetMsgParsingRules2 : prepare statement")
if err != nil {
return err
}
defer stmt.Close()
for r := range rules {
_, err = stmt.Exec(r.Priority, r.MsgTypeID64, r.Description, r.Rule)
logOnError(err, "resetMsgParsingRules2 : insert statement " + r.Description)
if err != nil {
return err
}
}
return nil
}