testtest
This commit is contained in:
parent
a43848d7df
commit
9e0b05caf7
27
def.go
27
def.go
@ -58,6 +58,14 @@ type ChatWarsUser struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type ChatWarsItem struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
ItemTypeID int64 `json:"item_type_id"`
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
UserID64 int64 `json:"user_id"`
|
||||
@ -289,15 +297,15 @@ const (
|
||||
objSubTypeMessageGoQuestAck = 353 // confirm quest destination/busyness (done)
|
||||
objSubTypeMessageGRolesReq = 354 // /g_roles (done)
|
||||
objSubTypeMessageGRolesAck = 355 // result from /g_roles (done)
|
||||
objSubTypeMessageGStockResReq = 356 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockAlchReq = 357 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockMiscReq = 358 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockRecReq = 359 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockPartReq = 360 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockOthReq = 361 // /g_stock_res (not done)
|
||||
objSubTypeMessageGStockAnyAck = 362 // result from any /g_stock_xxx (not done)
|
||||
objSubTypeMessageGStockReq = 363 // /g_stock (not done)
|
||||
objSubTypeMessageGStockAck = 364 // result from /g_stock (not done)
|
||||
objSubTypeMessageGStockResReq = 356 // /g_stock_res (done)
|
||||
objSubTypeMessageGStockAlchReq = 357 // /g_stock_alch (done)
|
||||
objSubTypeMessageGStockMiscReq = 358 // /g_stock_misc (done)
|
||||
objSubTypeMessageGStockRecReq = 359 // /g_stock_rec (done)
|
||||
objSubTypeMessageGStockPartReq = 360 // /g_stock_parts (done)
|
||||
objSubTypeMessageGStockOthReq = 361 // /g_stock_other (done)
|
||||
objSubTypeMessageGStockAnyAck = 362 // result from any /g_stock_xxx (done)
|
||||
objSubTypeMessageGStockReq = 363 // /g_stock (done)
|
||||
objSubTypeMessageGStockAck = 364 // result from /g_stock (done)
|
||||
objSubTypeJobPillage = 601
|
||||
objSubTypeJobTribute = 602
|
||||
objSubTypeJobStatus = 603
|
||||
@ -312,6 +320,7 @@ const (
|
||||
objSubTypeItemRecipe = 704
|
||||
objSubTypeItemPart = 705
|
||||
objSubTypeItemOther = 706
|
||||
objSubTypeItemUnique = 707
|
||||
objSubTypeCastle = 801
|
||||
objSubTypeFair = 901
|
||||
objSubTypeUnion = 1001
|
||||
|
94
obj.go
94
obj.go
@ -10,6 +10,7 @@ var (
|
||||
cacheObjCastle *sync.Map
|
||||
cacheObjGuild *sync.Map
|
||||
cacheObjUser *sync.Map
|
||||
cacheObjItem *sync.Map
|
||||
)
|
||||
|
||||
func getObjTypeId(objId int64) (int64, error) {
|
||||
@ -438,3 +439,96 @@ func addObjXP(userID64 int64, expNow int64, expLvl int64, level int64, date time
|
||||
}
|
||||
return objId, nil
|
||||
}
|
||||
|
||||
func addObjItem(name string, code string, itemTypeID64 int64, weight int) (int64, error) {
|
||||
tx, err := db.Begin()
|
||||
logOnError(err, "addObjItem : start transaction")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
res, err := tx.Exec(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
|
||||
VALUES (` + strconv.Itoa(objTypeItem) + `,` + strconv.Itoa(itemTypeID64) + `);`)
|
||||
logOnError(err, "addObjItem : exec insert obj")
|
||||
if err != nil {
|
||||
err2 := tx.Rollback()
|
||||
logOnError(err2, "addObjItem : rollback insert obj")
|
||||
return 0, err
|
||||
}
|
||||
|
||||
objId, err := res.LastInsertId()
|
||||
if err != nil {
|
||||
err2 := tx.Rollback()
|
||||
logOnError(err2, "addObjItem : rollback get lastInsertId")
|
||||
return 0, err
|
||||
}
|
||||
|
||||
stmt, err := tx.Prepare(`INSERT INTO obj_item (obj_id, intl_id, name, weight)
|
||||
VALUES (?, ?, ?, ?);`)
|
||||
logOnError(err, "addObjItem : prepare insert obj_item")
|
||||
if err != nil {
|
||||
err2 := tx.Rollback()
|
||||
logOnError(err2, "addObjItem : rollback prepare insert obj_item")
|
||||
return 0, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(objId, code, name, weight)
|
||||
logOnError(err, "addObjItem : exec insert obj_item")
|
||||
if err != nil {
|
||||
err2 := tx.Rollback()
|
||||
logOnError(err2, "addObjItem : rollback exec insert obj_item")
|
||||
return 0, err
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
logOnError(err, "addObjItem : commit")
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return objId, nil
|
||||
}
|
||||
|
||||
func getObjItemID(s string) int64 {
|
||||
if v, ok := cacheObjItem.Load(s); ok {
|
||||
i := v.(ChatWarsUser)
|
||||
return i.ObjID64
|
||||
} else {
|
||||
s := fmt.Sprintf("Object unknown : %s\n", s)
|
||||
clientSendCWMsg(cfg.Bot.Admin, s)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func loadObjItem() error {
|
||||
var (
|
||||
id int64
|
||||
intl_id string
|
||||
name string
|
||||
weight int
|
||||
)
|
||||
|
||||
cacheObjItem = new(sync.Map)
|
||||
|
||||
items, err := db.Query(`SELECT oi.obj_id, oi.intl_id, oi.name, oi.weight FROM obj_item oi;`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer items.Close()
|
||||
|
||||
for items.Next() {
|
||||
err = items.Scan(&id, &intl_id, &name, &weight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c := new(ChatWarsItem)
|
||||
c.ObjID64 = id
|
||||
c.Code = intl_id
|
||||
c.Name = name
|
||||
c.Weight = weight
|
||||
cacheObjItem.Store(intl_id, *c)
|
||||
cacheObjItem.Store(name, *c)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
15
rules.go
15
rules.go
@ -139,6 +139,21 @@ func resetMsgParsingRules() {
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGoQuestAck) + `, "Go Quest Ack Devil's Valley", "^You went to the (?P<Place>[a-zA-Z ']+). Don't lose your soul. Back in (?P<Time>[0-9]+) minutes$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesReq) + `, "Guild roles Req", "^/g_roles$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGRolesAck) + `, "Guild roles Req", "^Roles:\\nBartender:\\n(?P<Bartender>.*)\\n\\n\\nCommander:\\n(?P<Commander>.*)\\n\\n\\nSquire:\\n(?P<Squire>.*)\\n\\n\\nTreasurer:\\n(?P<Treasurer>.*)$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockReq) + `, "Guild stock Req", "^/g_stock$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAck) + `, "Guild stock Ack", "^Grouped by:\\n` +
|
||||
`/g_stock_res - resources\\n` +
|
||||
`/g_stock_alch - alchemist herbs\\n` +
|
||||
`/g_stock_misc - miscellaneous stuff\\n` +
|
||||
`/g_stock_rec - items recipes\\n` +
|
||||
`/g_stock_parts - items parts\\n` +
|
||||
`/g_stock_other - everything else$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockResReq) + `, "Guild stock resources Req", "^/g_stock_res$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAlchReq) + `, "Guild stock alchemy Req", "^/g_stock_alch$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockMiscReq) + `, "Guild stock misc Req", "^/g_stock_misc$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockRecReq) + `, "Guild stock recipes Req", "^/g_stock_rec$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockPartReq) + `, "Guild stock parts Req", "^/g_stock_parts$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockOthReq) + `, "Guild stock other Req", "^/g_stock_other$")
|
||||
,(5000, ` + strconv.Itoa(objSubTypeMessageGStockAnyAck) + `, "Guild stock any Ack", "^Guild Warehouse:(?P<Stock>(\\n[0-9a-z]+ (.*) x ([0-9]+))+)$")
|
||||
;`)
|
||||
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
|
||||
}
|
||||
|
11
workers.go
11
workers.go
@ -87,29 +87,26 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
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
|
||||
err = setObjSubTypeId(objId, msgParsingRules[i].MsgTypeID)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId")
|
||||
switch msgParsingRules[i].MsgTypeID {
|
||||
case objSubTypeMessageReportAck:
|
||||
cwm, err := parseSubTypeMessageReportAck(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.")
|
||||
cwm.ObjID64 = objId
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageReportAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportAck)")
|
||||
|
||||
case objSubTypeMessageMiniWar:
|
||||
cwm, err := parseSubTypeMessageMiniWar(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
|
||||
cwm.ObjID64 = objId
|
||||
err = insertMsgMiniWar(cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMiniWar)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MiniWar)")
|
||||
case objSubTypeMessagePillageInc:
|
||||
cwm, err := parseSubTypeMessagePillageInc(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessagePillageInc.")
|
||||
cwm.ObjID64 = objId
|
||||
err = insertMsgPillageInc(cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageInc)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)")
|
||||
// only catch live pillages
|
||||
if m.Date.Add(3 * time.Minute).After(time.Now()) {
|
||||
s := TGCommand{
|
||||
@ -126,8 +123,6 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
||||
}
|
||||
case objSubTypeMessageGo:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGo)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Go)")
|
||||
case objSubTypeMessageReportReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageReportReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportReq)")
|
||||
|
Loading…
Reference in New Issue
Block a user