update g stock with get vault
This commit is contained in:
parent
e055e7f752
commit
cdfdc21c13
30
bot.go
30
bot.go
@ -32,7 +32,6 @@ func BotHandlers(b *tb.Bot) {
|
|||||||
|
|
||||||
b.Handle("/timer", botTimer)
|
b.Handle("/timer", botTimer)
|
||||||
|
|
||||||
b.Handle("/g_stock", botGStock)
|
|
||||||
b.Handle("/g_deposit_all", botGDepositAll)
|
b.Handle("/g_deposit_all", botGDepositAll)
|
||||||
b.Handle("/g_withdraw", botGWithdraw)
|
b.Handle("/g_withdraw", botGWithdraw)
|
||||||
b.Handle("/save_res", botSaveRes)
|
b.Handle("/save_res", botSaveRes)
|
||||||
@ -661,24 +660,14 @@ func botListParsingRule(m *tb.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func botGStock(m *tb.Message) {
|
func botGStock(m ChatWarsMessage) {
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
clt, err := getLockedIdleClient()
|
clt, err := getLockedIdleClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Busy, please retry later.",
|
Text: "Busy, please retry later.",
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: m.ID64,
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.ChatID64,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
return
|
return
|
||||||
@ -687,9 +676,8 @@ func botGStock(m *tb.Message) {
|
|||||||
clt.Mux.Unlock()
|
clt.Mux.Unlock()
|
||||||
|
|
||||||
p := JobPayloadGStock{
|
p := JobPayloadGStock{
|
||||||
MsgID64: int64(m.ID),
|
MsgID64: m.ID64,
|
||||||
ChatID64: m.Chat.ID,
|
ChatID64: m.ChatID64,
|
||||||
Progress: 0,
|
|
||||||
}
|
}
|
||||||
b, _ := json.Marshal(p)
|
b, _ := json.Marshal(p)
|
||||||
t := time.Now().UTC().Add(1 * time.Second)
|
t := time.Now().UTC().Add(1 * time.Second)
|
||||||
@ -699,16 +687,16 @@ func botGStock(m *tb.Message) {
|
|||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: fmt.Sprintf("%s", err),
|
Text: fmt.Sprintf("%s", err),
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: m.ID64,
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.ChatID64,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
} else {
|
} else {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: "Stock requested",
|
Text: "Stock requested",
|
||||||
FromMsgID64: int64(m.ID),
|
FromMsgID64: m.ID64,
|
||||||
FromChatID64: m.Chat.ID,
|
FromChatID64: m.ChatID64,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
}
|
}
|
||||||
|
@ -619,6 +619,11 @@
|
|||||||
"name": "Craft check for all items",
|
"name": "Craft check for all items",
|
||||||
"obj_type": "msg"
|
"obj_type": "msg"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"intl_id": "msg_bot_g_stock",
|
||||||
|
"name": "Get Stock",
|
||||||
|
"obj_type": "msg"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"intl_id": "job_pillage",
|
"intl_id": "job_pillage",
|
||||||
"name": "Pillage job",
|
"name": "Pillage job",
|
||||||
@ -709,6 +714,11 @@
|
|||||||
"name": "Msg Del Job",
|
"name": "Msg Del Job",
|
||||||
"obj_type": "job"
|
"obj_type": "job"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"intl_id": "job_get_vault",
|
||||||
|
"name": "Generic Get Vault",
|
||||||
|
"obj_type": "job"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"intl_id": "job_get_hammer_time",
|
"intl_id": "job_get_hammer_time",
|
||||||
"name": "Get Hammer Time job",
|
"name": "Get Hammer Time job",
|
||||||
|
20
def.go
20
def.go
@ -403,8 +403,7 @@ type JobPayloadStatus struct {
|
|||||||
type JobPayloadGStock struct {
|
type JobPayloadGStock struct {
|
||||||
MsgID64 int64 `json:"msg_id"`
|
MsgID64 int64 `json:"msg_id"`
|
||||||
ChatID64 int64 `json:"chat_id"`
|
ChatID64 int64 `json:"chat_id"`
|
||||||
Progress int64 `json:"progress"`
|
VaultJobID64 int64 `json:"vault_job_id"`
|
||||||
Stock []ChatWarsItems `json:"stock"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobPayloadGWithdrawItem struct {
|
type JobPayloadGWithdrawItem struct {
|
||||||
@ -488,6 +487,23 @@ type JobPayloadVaultItemStatus struct {
|
|||||||
UserID64 int64 `json:"user_id"`
|
UserID64 int64 `json:"user_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JobPayloadCraftItem struct {
|
||||||
|
MsgID64 int64 `json:"msg_id"`
|
||||||
|
ChatID64 int64 `json:"chat_id"`
|
||||||
|
UserID64 int64 `json:"user_id"`
|
||||||
|
ObjItemID64 int64 `json:"item_id"`
|
||||||
|
Status int64 `json:"status"`
|
||||||
|
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
|
||||||
|
VaultJobId int64 `json:"vault_job_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type JobPayloadGetVault struct {
|
||||||
|
JobCallbackID64 int64 `json:"job_callback_id"`
|
||||||
|
ItemTypeList []int64 `json:"item_type"`
|
||||||
|
Vault []ChatWarsItems `json:"vault"`
|
||||||
|
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
userID64ChtWrsBot = 408101137
|
userID64ChtWrsBot = 408101137
|
||||||
|
|
||||||
|
12
item.go
12
item.go
@ -15,6 +15,7 @@ var (
|
|||||||
objItems []ChatWarsItem
|
objItems []ChatWarsItem
|
||||||
cacheObjItem map[string]int64
|
cacheObjItem map[string]int64
|
||||||
cacheObjItemId map[int64]int64
|
cacheObjItemId map[int64]int64
|
||||||
|
cacheObjItemCraft map[string]int64
|
||||||
)
|
)
|
||||||
|
|
||||||
func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange string, auction bool) (int64, error) {
|
func addObjItem(code string, name string, itemTypeID64 int64, weight int64, exchange string, auction bool) (int64, error) {
|
||||||
@ -241,6 +242,15 @@ func addObjItemCraftItem(objID64 int64, itemID64 int64, quantity int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getCraftItemID(cmd string) (int64, error) {
|
||||||
|
muxObjItem.RLock()
|
||||||
|
defer muxObjItem.RUnlock()
|
||||||
|
|
||||||
|
for _, o := range objItems {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func loadObjItem() error {
|
func loadObjItem() error {
|
||||||
var (
|
var (
|
||||||
obj_id int64
|
obj_id int64
|
||||||
@ -254,6 +264,7 @@ func loadObjItem() error {
|
|||||||
defer muxObjItem.Unlock()
|
defer muxObjItem.Unlock()
|
||||||
cacheObjItem = make(map[string]int64)
|
cacheObjItem = make(map[string]int64)
|
||||||
cacheObjItemId = make(map[int64]int64)
|
cacheObjItemId = make(map[int64]int64)
|
||||||
|
cacheObjItemCraft = make(map[string]int64)
|
||||||
objItems = make([]ChatWarsItem, 0)
|
objItems = make([]ChatWarsItem, 0)
|
||||||
|
|
||||||
b, err := Asset("data/obj_item.json")
|
b, err := Asset("data/obj_item.json")
|
||||||
@ -347,6 +358,7 @@ func loadObjItem() error {
|
|||||||
|
|
||||||
for _, i := range cacheObjItem {
|
for _, i := range cacheObjItem {
|
||||||
if objItems[i].Craft != nil {
|
if objItems[i].Craft != nil {
|
||||||
|
cacheObjItemCraft[objItems[i].Craft.Command] = i
|
||||||
setObjItemCraft(objItems[i].ObjID64, objItems[i].Craft.Command, objItems[i].Craft.Mana)
|
setObjItemCraft(objItems[i].ObjID64, objItems[i].Craft.Command, objItems[i].Craft.Mana)
|
||||||
emptyObjItemCraftItem(objItems[i].ObjID64)
|
emptyObjItemCraftItem(objItems[i].ObjID64)
|
||||||
for k, o := range objItems[i].Craft.Items {
|
for k, o := range objItems[i].Craft.Items {
|
||||||
|
344
job.go
344
job.go
@ -144,6 +144,16 @@ func setJobTimeout(jobID64 int64, d time.Duration) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setJobPayloadJSON(jobID64 int64, payload interface{}) error {
|
||||||
|
b, err := json.Marshal(payload)
|
||||||
|
logOnError(err, "setJobPayloadJSON")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return setJobPayload(jobID64, b)
|
||||||
|
}
|
||||||
|
|
||||||
func setJobPayload(jobID64 int64, payload []byte) error {
|
func setJobPayload(jobID64 int64, payload []byte) error {
|
||||||
var (
|
var (
|
||||||
zb bytes.Buffer
|
zb bytes.Buffer
|
||||||
@ -191,6 +201,15 @@ func setJobPayload(jobID64 int64, payload []byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getJobPayload(j.ID64) []byte {
|
||||||
|
var b []byte
|
||||||
|
muxObjJob.Lock()
|
||||||
|
j := cacheObjJob[jobID64]
|
||||||
|
b = j.Payload
|
||||||
|
defer muxObjJob.Unlock()
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
func setJobDone(jobID64 int64) error {
|
func setJobDone(jobID64 int64) error {
|
||||||
stmt, err := db.Prepare(`UPDATE obj_job j SET j.is_done = 1, j.in_work = 0, j.ended = ? WHERE j.obj_id = ?;`)
|
stmt, err := db.Prepare(`UPDATE obj_job j SET j.is_done = 1, j.in_work = 0, j.ended = ? WHERE j.obj_id = ?;`)
|
||||||
logOnError(err, "setJobDone : prepare update obj_job")
|
logOnError(err, "setJobDone : prepare update obj_job")
|
||||||
@ -879,7 +898,10 @@ func jobBackupImport(j Job) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func jobGStock(j Job) {
|
func jobGStock(j Job) {
|
||||||
var p JobPayloadGStock
|
var (
|
||||||
|
p JobPayloadGStock
|
||||||
|
p2 JobPayloadGetVault
|
||||||
|
)
|
||||||
var resSize, resCount, alchSize, alchCount, miscSize, miscCount, recSize, recCount, partSize, partCount, otherSize, otherCount, totalSize int64
|
var resSize, resCount, alchSize, alchCount, miscSize, miscCount, recSize, recCount, partSize, partCount, otherSize, otherCount, totalSize int64
|
||||||
err := setJobStart(j.ID64)
|
err := setJobStart(j.ID64)
|
||||||
logOnError(err, "jobGStock : setJobStart")
|
logOnError(err, "jobGStock : setJobStart")
|
||||||
@ -890,109 +912,37 @@ func jobGStock(j Job) {
|
|||||||
fmt.Printf("jobGStock : Progress => %d\n", p.Progress)
|
fmt.Printf("jobGStock : Progress => %d\n", p.Progress)
|
||||||
fmt.Printf("jobGStock : UserID64 => %d\n", j.UserID64)
|
fmt.Printf("jobGStock : UserID64 => %d\n", j.UserID64)
|
||||||
|
|
||||||
switch p.Progress {
|
if p.Status == 0 {
|
||||||
case 0: // send /g_stock_res
|
p2.JobCallbackID64 = j.ID64
|
||||||
p.Progress = 1
|
p2.ItemTypeList = make([]int64, 0)
|
||||||
b, _ := json.Marshal(&p)
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_res`])
|
||||||
jobID64, err := createJob(cacheObjSubType[`job_gstock`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_alch`])
|
||||||
logOnError(err, "jobGStock : createJob")
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_misc`])
|
||||||
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_recipe`])
|
||||||
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_busy`])
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_part`])
|
||||||
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_battle`])
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_other`])
|
||||||
err = setJobTimeout(jobID64, 1*time.Minute)
|
|
||||||
logOnError(err, "jobGStock : setJobTimeout")
|
b2, err := json.Marshal(p2)
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_res")
|
logOnError(err, "jobGStock : Marshal(p2)")
|
||||||
case 1: // send /g_stock_alch
|
|
||||||
msg, err := getObjMsg(j.Trigger)
|
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
|
||||||
logOnError(err, "jobGStock : getObjMsg msg")
|
|
||||||
rule, err := getMsgParsingRule(msg)
|
p.Status = 1
|
||||||
logOnError(err, "jobGStock : getMsgParsingRule")
|
b, err = json.Marshal(p)
|
||||||
if rule.MsgTypeID64 == cacheObjSubType[`msg_gstock_any_ack`] {
|
logOnError(err, "jobGStock : Marshal(p)")
|
||||||
cwm, err := parseSubTypeMessageGStockAnyAck(msg, rule.re)
|
|
||||||
for _, v := range cwm.Stock {
|
err = setJobPayloadJSON(j.ID64, p)
|
||||||
p.Stock = append(p.Stock, v)
|
logOnError(err, "jobGStock : setJobPayloadJSON(p)")
|
||||||
|
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
p.Progress = 2
|
|
||||||
b, _ := json.Marshal(&p)
|
b = getJobPayload(p.VaultJobID64)
|
||||||
err = createJobCallback(cacheObjSubType[`job_gstock`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, 1*time.Minute)
|
err = json.Unmarshal(b, &p2)
|
||||||
logOnError(err, "jobGStock : createJobCallback")
|
logOnError(err, "jobGStock : Unmarshal(p2)")
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_alch")
|
|
||||||
} else if rule.MsgTypeID64 == cacheObjSubType[`msg_busy`] || rule.MsgTypeID64 == cacheObjSubType[`msg_battle`] {
|
for _, v := range p2.Vault {
|
||||||
m := TGCommand{
|
|
||||||
Type: commandReplyMsg,
|
|
||||||
Text: "Busy, please retry later.",
|
|
||||||
FromMsgID64: p.MsgID64,
|
|
||||||
FromChatID64: p.ChatID64,
|
|
||||||
ParseMode: cmdParseModeHTML,
|
|
||||||
}
|
|
||||||
TGCmdQueue <- m
|
|
||||||
}
|
|
||||||
case 2: // send /g_stock_misc
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
p.Progress = 3
|
|
||||||
b, _ := json.Marshal(&p)
|
|
||||||
err = createJobCallback(cacheObjSubType[`job_gstock`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, 1*time.Minute)
|
|
||||||
logOnError(err, "jobGStock : createJobCallback")
|
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_misc")
|
|
||||||
case 3: // send /g_stock_rec
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
p.Progress = 4
|
|
||||||
b, _ := json.Marshal(&p)
|
|
||||||
err = createJobCallback(cacheObjSubType[`job_gstock`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, 1*time.Minute)
|
|
||||||
logOnError(err, "jobGStock : createJobCallback")
|
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_rec")
|
|
||||||
case 4: // send /g_stock_parts
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
p.Progress = 5
|
|
||||||
b, _ := json.Marshal(&p)
|
|
||||||
err = createJobCallback(cacheObjSubType[`job_gstock`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, 1*time.Minute)
|
|
||||||
logOnError(err, "jobGStock : createJobCallback")
|
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_parts")
|
|
||||||
case 5: // send /g_stock_other
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
p.Progress = 6
|
|
||||||
b, _ := json.Marshal(&p)
|
|
||||||
err = createJobCallback(cacheObjSubType[`job_gstock`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, 1*time.Minute)
|
|
||||||
logOnError(err, "jobGStock : createJobCallback")
|
|
||||||
clientSendCWMsg(j.UserID64, "/g_stock_other")
|
|
||||||
case 6: // collate everything and reply
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
for _, v := range p.Stock {
|
|
||||||
item, err := getObjItem(v.ItemID64)
|
item, err := getObjItem(v.ItemID64)
|
||||||
logOnError(err, "jobGStock : getObjItem")
|
logOnError(err, "jobGStock : getObjItem")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -1039,7 +989,6 @@ func jobGStock(j Job) {
|
|||||||
ParseMode: cmdParseModeHTML,
|
ParseMode: cmdParseModeHTML,
|
||||||
}
|
}
|
||||||
TGCmdQueue <- m
|
TGCmdQueue <- m
|
||||||
}
|
|
||||||
|
|
||||||
err = setJobDone(j.ID64)
|
err = setJobDone(j.ID64)
|
||||||
logOnError(err, "jobGStock : setJobDone")
|
logOnError(err, "jobGStock : setJobDone")
|
||||||
@ -1950,3 +1899,190 @@ func jobGetHammerTime(j Job) {
|
|||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func jobGetVault(j Job) {
|
||||||
|
var (
|
||||||
|
p JobPayloadGetVault
|
||||||
|
reqTab map[int64]int64
|
||||||
|
doneTab map[int64]int64
|
||||||
|
)
|
||||||
|
|
||||||
|
log.Printf("jobGetVault[%d] : Starting.\n", j.ID64)
|
||||||
|
|
||||||
|
reqTab = make(map[int64]int64)
|
||||||
|
reqTab[cacheObjSubType[`item_res`]] = 1 << 0
|
||||||
|
reqTab[cacheObjSubType[`item_alch`]] = 1 << 1
|
||||||
|
reqTab[cacheObjSubType[`item_misc`]] = 1 << 2
|
||||||
|
reqTab[cacheObjSubType[`item_recipe`]] = 1 << 3
|
||||||
|
reqTab[cacheObjSubType[`item_part`]] = 1 << 4
|
||||||
|
reqTab[cacheObjSubType[`item_other`]] = 1 << 5
|
||||||
|
|
||||||
|
doneTab = make(map[int64]int64)
|
||||||
|
doneTab[cacheObjSubType[`item_res`]] = 1 << 10
|
||||||
|
doneTab[cacheObjSubType[`item_alch`]] = 1 << 11
|
||||||
|
doneTab[cacheObjSubType[`item_misc`]] = 1 << 12
|
||||||
|
doneTab[cacheObjSubType[`item_recipe`]] = 1 << 13
|
||||||
|
doneTab[cacheObjSubType[`item_part`]] = 1 << 14
|
||||||
|
doneTab[cacheObjSubType[`item_other`]] = 1 << 15
|
||||||
|
|
||||||
|
err := setJobStart(j.ID64)
|
||||||
|
logOnError(err, "jobGetVault : setJobStart")
|
||||||
|
|
||||||
|
err = json.Unmarshal(j.Payload, &p)
|
||||||
|
logOnError(err, "jobGetVault : Unmarshal payload")
|
||||||
|
|
||||||
|
if p.Status == 0 {
|
||||||
|
for k, typeID64 := range p.ItemTypeList {
|
||||||
|
p.Status = p.Status | reqTab[typeID64]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]]
|
||||||
|
}
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == 0 {
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if j.Trigger != 0 {
|
||||||
|
id, err := getObjSubTypeId(j.Trigger)
|
||||||
|
logOnError(err, "jobGetVault : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
|
||||||
|
if err == nil {
|
||||||
|
m, err := getObjMsg(j.Trigger)
|
||||||
|
logOnError(err, "jobGetVault : getObjMsg")
|
||||||
|
rule, err := getMsgParsingRule(m)
|
||||||
|
logOnError(err, "jobGetVault : getMsgParsingRule")
|
||||||
|
|
||||||
|
switch id {
|
||||||
|
case cacheObjSubType[`msg_gstock_any_ack`]:
|
||||||
|
cwm, err := parseSubTypeMessageGStockAnyAck(m, rule.re)
|
||||||
|
logOnError(err, "jobGetVault : parseSubTypeMessageGStockAnyAck")
|
||||||
|
|
||||||
|
for _, disp := range cwm.Stock {
|
||||||
|
item := ChatWarsItem{
|
||||||
|
Code: disp.Code,
|
||||||
|
ItemID64: disp.ItemID64,
|
||||||
|
Name: disp.Name,
|
||||||
|
Quantity: disp.Quantity,
|
||||||
|
}
|
||||||
|
p.Vault = append(p.Vault, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
p.CleanupMsg = append(p.CleanupMsg, *m)
|
||||||
|
|
||||||
|
case cacheObjSubType[`msg_gstock_oth_req`]:
|
||||||
|
fallthrough
|
||||||
|
case cacheObjSubType[`msg_gstock_res_req`]:
|
||||||
|
fallthrough
|
||||||
|
case cacheObjSubType[`msg_gstock_alch_req`]:
|
||||||
|
fallthrough
|
||||||
|
case cacheObjSubType[`msg_gstock_misc_req`]:
|
||||||
|
fallthrough
|
||||||
|
case cacheObjSubType[`msg_gstock_rec_req`]:
|
||||||
|
fallthrough
|
||||||
|
case cacheObjSubType[`msg_gstock_part_req`]:
|
||||||
|
p.CleanupMsg = append(p.CleanupMsg, *m)
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == reqTab[cacheObjSubType[`item_res`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting res.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_res_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_res`)
|
||||||
|
return
|
||||||
|
} else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting alch.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_alch_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_res`)
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_alch`)
|
||||||
|
return
|
||||||
|
} else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting misc.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_misc_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_misc`)
|
||||||
|
return
|
||||||
|
} else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting recipe.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_rec_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_rec`)
|
||||||
|
return
|
||||||
|
} else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting part.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_part_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_part`)
|
||||||
|
return
|
||||||
|
} else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] {
|
||||||
|
log.Printf("jobGetVault[%d] : Requesting other.\n", j.ID64)
|
||||||
|
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]]
|
||||||
|
p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]]
|
||||||
|
setJobPayloadJSON(j.ID64, p)
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_oth_req`])
|
||||||
|
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
clientSendCWMsg(j.UserID64, `/g_stock_other`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clean up the messages */
|
||||||
|
for _, d := range p.CleanupMsg {
|
||||||
|
delmsg := tb.StoredMessage{
|
||||||
|
MessageID: fmt.Sprintf("%d", d.ID64),
|
||||||
|
ChatID: d.ChatID64,
|
||||||
|
}
|
||||||
|
err = bot.Delete(delmsg)
|
||||||
|
logOnError(err, "jobGetVault : Delete")
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wake up the callback */
|
||||||
|
err = rescheduleJob(p.JobCallbackID64, 0, time.Now().UTC())
|
||||||
|
logOnError(err, "jobGetVault : rescheduleJob")
|
||||||
|
|
||||||
|
/* no more req to send, all ack came through, we can finish the job */
|
||||||
|
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobGetVault : setJobDone")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
10
rules.go
10
rules.go
@ -75,6 +75,16 @@ func resetMsgParsingRules() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = MessageParsingRule{
|
||||||
|
Priority: 9999,
|
||||||
|
Description: "Get Stock",
|
||||||
|
Rule: "^/g_stock$",
|
||||||
|
MsgTypeID64: cacheObjSubType[`msg_bot_g_stock`],
|
||||||
|
ChatID64: cfg.Bot.Mainchat,
|
||||||
|
SenderUserID64: 0,
|
||||||
|
}
|
||||||
|
rules2 = append(rules2, r)
|
||||||
|
|
||||||
r = MessageParsingRule{
|
r = MessageParsingRule{
|
||||||
Priority: 1,
|
Priority: 1,
|
||||||
Description: "Default Main chat",
|
Description: "Default Main chat",
|
||||||
|
@ -508,7 +508,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
case cacheObjSubType[`msg_job_gwithdraw_ack`]:
|
case cacheObjSubType[`msg_job_gwithdraw_ack`]:
|
||||||
_, err := parseSubTypeMessageJobGWithdrawAck(m, rule.re)
|
_, err := parseSubTypeMessageJobGWithdrawAck(m, rule.re)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]")
|
||||||
|
case cacheObjSubType[`msg_bot_g_stock`]:
|
||||||
|
botGStock(m)
|
||||||
case cacheObjSubType[`msg_bot_craft_item`]:
|
case cacheObjSubType[`msg_bot_craft_item`]:
|
||||||
|
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
Text: `<b>test</b>`,
|
Text: `<b>test</b>`,
|
||||||
@ -620,6 +623,8 @@ func JobWorker(id int, jobs <-chan Job) {
|
|||||||
jobSetDef(j)
|
jobSetDef(j)
|
||||||
case cacheObjSubType[`job_get_hammer_time`]:
|
case cacheObjSubType[`job_get_hammer_time`]:
|
||||||
jobGetHammerTime(j)
|
jobGetHammerTime(j)
|
||||||
|
case cacheObjSubType[`job_get_vault`]:
|
||||||
|
jobGetVault(j)
|
||||||
default:
|
default:
|
||||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user