update g_stock trigger

This commit is contained in:
shoopea 2019-12-14 14:58:28 +08:00
parent 07796e06a3
commit cb66651b84
3 changed files with 35 additions and 15 deletions

8
bot.go
View File

@ -639,7 +639,13 @@ func botListParsingRule(m *tb.Message) {
}
func botGStock(m *tb.Message) {
if !m.Private() {
if m.Private() {
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
return
}
clt.Mux.Unlock()
} else if m.Chat.ID != cfg.Bot.Mainchat {
return
}

35
job.go
View File

@ -717,23 +717,38 @@ func jobGStock(j Job) {
case 0: // send /g_stock_res
p.Progress = 1
b, _ := json.Marshal(&p)
err = createJobCallback(objSubTypeJobGStock, j.UserID64, objSubTypeMessageGStockAnyAck, b, 1*time.Minute)
logOnError(err, "jobGStock : createJobCallback")
jobID64, err := createJob(objSubTypeJobGStock, objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGStock : createJob")
setJobCallback(jobID64, j.UserID64, objSubTypeMessageGStockAnyAck)
setJobCallback(jobID64, j.UserID64, objSubTypeMessageBusy)
err = setJobTimeout(jobID64, 1*time.Minute)
logOnError(err, "jobGStock : setJobTimeout")
clientSendCWMsg(cfg.Bot.Admin, "/g_stock_res")
case 1: // send /g_stock_alch
msg, err := getObjMsg(j.Trigger)
logOnError(err, "jobGStock : getObjMsg msg")
rule, err := getMsgParsingRule(msg)
logOnError(err, "jobGStock : getMsgParsingRule")
cwm, err := parseSubTypeMessageGStockAnyAck(msg, rule.re)
for _, v := range cwm.Stock {
p.Stock = append(p.Stock, v)
if rule.MsgTypeID == objSubTypeMessageGStockAnyAck {
cwm, err := parseSubTypeMessageGStockAnyAck(msg, rule.re)
for _, v := range cwm.Stock {
p.Stock = append(p.Stock, v)
}
p.Progress = 2
b, _ := json.Marshal(&p)
err = createJobCallback(objSubTypeJobGStock, j.UserID64, objSubTypeMessageGStockAnyAck, b, 1*time.Minute)
logOnError(err, "jobGStock : createJobCallback")
clientSendCWMsg(cfg.Bot.Admin, "/g_stock_alch")
} else if rule.MsgTypeID == objSubTypeMessageBusy {
m := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- m
}
p.Progress = 2
b, _ := json.Marshal(&p)
err = createJobCallback(objSubTypeJobGStock, j.UserID64, objSubTypeMessageGStockAnyAck, b, 1*time.Minute)
logOnError(err, "jobGStock : createJobCallback")
clientSendCWMsg(cfg.Bot.Admin, "/g_stock_alch")
case 2: // send /g_stock_misc
msg, err := getObjMsg(j.Trigger)
logOnError(err, "jobGStock : getObjMsg msg")

7
obj.go
View File

@ -724,10 +724,9 @@ func getSilentObjItemID(code string, name string) int64 {
//log.Printf("Matching item code %s with %s.\n", code, obj.Code)
return obj.ObjID64
}
if ok, _ := regexp.MatchString(`^a[0-9]+[a-e]$`, code); ok {
code2 := code[:len(code)-1]
log.Printf("Matching quality item code %s with %s.\n", code, code2)
if obj, ok := cacheObjItem[code2]; ok {
if ok, _ := regexp.MatchString(`^(a|w)[0-9]+[a-e]$`, code); ok {
// log.Printf("Matching quality item code %s with %s.\n", code, code[:len(code)-1])
if obj, ok := cacheObjItem[code[:len(code)-1]]; ok {
return obj.ObjID64
}
}