test craft

This commit is contained in:
shoopea 2020-01-27 12:05:38 +08:00
parent 2fac84340c
commit 8a1d244d08
4 changed files with 260 additions and 279 deletions

49
bot.go
View File

@ -672,8 +672,7 @@ func botGStock(m *ChatWarsMessage) {
TGCmdQueue <- c
return
}
userID64 := cfg.Bot.Admin
//userID64 := clt.TGUserID64
userID64 := clt.TGUserID64
clt.Mux.Unlock()
p := JobPayloadGStock{
@ -706,6 +705,52 @@ func botGStock(m *ChatWarsMessage) {
return
}
func botCraftItem(m *ChatWarsMessage) {
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
userID64 := clt.TGUserID64
clt.Mux.Unlock()
p := JobPayloadCraftItem{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
ObjItemID64: getCraftItemID(m.Text),
Status: 0,
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err = createJob(cacheObjSubType[`job_craft_item`], objJobPriority, userID64, 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Craft summary coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
func botSaveRes(m *tb.Message) {
if !m.Private() {
return

13
def.go
View File

@ -489,13 +489,12 @@ type JobPayloadVaultItemStatus struct {
}
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"`
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
UserID64 int64 `json:"user_id"`
ObjItemID64 int64 `json:"item_id"`
Status int64 `json:"status"`
VaultJobID64 int64 `json:"vault_job_id"`
}
type JobPayloadGetVault struct {

465
job.go
View File

@ -902,11 +902,18 @@ func jobBackupImport(j Job) {
func jobGStock(j Job) {
var (
p JobPayloadGStock
p2 JobPayloadGetVault
b []byte
p JobPayloadGStock
p2 JobPayloadGetVault
b []byte
resSize, resCount int64
alchSize, alchCount int64
miscSize, miscCount int64
recSize, recCount int64
partSize, partCount int64
otherSize, otherCount int64
totalSize int64
)
var resSize, resCount, alchSize, alchCount, miscSize, miscCount, recSize, recCount, partSize, partCount, otherSize, otherCount, totalSize int64
err := setJobStart(j.ID64)
logOnError(err, "jobGStock : setJobStart")
@ -1395,29 +1402,13 @@ func jobVaultUserStatus(j Job) {
func jobGWithdraw(j Job) {
var (
p JobPayloadGWithdraw
reqTab map[int64]int64
doneTab map[int64]int64
p JobPayloadGWithdraw
p2 JobPayloadGetVault
b []byte
)
log.Printf("jobGWithdraw[%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, "jobGWithdraw : setJobStart")
@ -1425,92 +1416,45 @@ func jobGWithdraw(j Job) {
logOnError(err, "jobGWithdraw : Unmarshal payload")
if p.Status == 0 {
p2.JobCallbackID64 = j.ID64
p2.ItemTypeList = make([]int64, 0)
for k, item := range p.Items {
id := getSilentObjItemID(item.Code, ``)
if id != 0 {
obj, _ := getObjItem(id)
p.Status = p.Status | reqTab[obj.ItemTypeID]
p2.ItemTypeList = append(p2.ItemTypeList, obj.ItemTypeID)
} else if ok, _ := regexp.MatchString(`^u[0-9]+$`, item.Code); ok {
p.Items[k].Inspect = true
p.Status = p.Status | reqTab[cacheObjSubType[`item_other`]]
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_other`])
}
}
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`]]
}
b, err = json.Marshal(p2)
logOnError(err, "jobGWithdraw : Marshal(p2)")
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
p.Status = 1
p.VaultJobID64 = jobID64
b, err = json.Marshal(p)
logOnError(err, "jobGWithdraw : Marshal(p)")
err = setJobPayloadJSON(j.ID64, p)
logOnError(err, "jobGWithdraw : setJobPayloadJSON(p)")
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
return
} else if p.Status == 1 {
/* loop through items and get unique/inspect */
}
if j.Trigger != 0 {
id, err := getObjSubTypeId(j.Trigger)
logOnError(err, "jobGWithdraw : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil {
if id == cacheObjSubType[`msg_gstock_any_ack`] {
var isUnique bool
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGWithdraw : getObjMsg")
rule, err := getMsgParsingRule(m)
logOnError(err, "jobGWithdraw : getMsgParsingRule")
cwm, err := parseSubTypeMessageGStockAnyAck(m, rule.re)
logOnError(err, "jobGWithdraw : parseSubTypeMessageGStockAnyAck")
for k, req := range p.Items {
for _, disp := range cwm.Stock {
if req.Code == disp.Code {
p.Items[k].Available = disp.Quantity
p.Items[k].Name = disp.Name
p.Items[k].Inspect = false
log.Printf("jobGWithdraw[%d] : Found %s - %s : %d.\n", j.ID64, disp.Code, disp.Name, disp.Quantity)
}
if ok, _ := regexp.MatchString(`^u[0-9]+$`, disp.Code); ok {
isUnique = true
}
}
}
p.CleanupMsg = append(p.CleanupMsg, *m)
if isUnique {
for _, req := range p.Items {
if req.Inspect {
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_g_inspect_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
p.Inspecting = req.Code
b, _ := json.Marshal(p)
id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGWithdraw : createJob")
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_invalid_action`])
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_inspect_ack`])
clientSendCWMsg(j.UserID64, fmt.Sprintf("/g_inspect_%s", p.Inspecting))
err = setJobDone(j.ID64)
logOnError(err, "jobGWithdraw : setJobDone")
return
}
}
}
} else if id == cacheObjSubType[`msg_inspect_ack`] {
if id == cacheObjSubType[`msg_inspect_ack`] {
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGWithdraw : getObjMsg")
rule, err := getMsgParsingRule(m)
@ -1660,170 +1604,78 @@ func jobGWithdraw(j Job) {
}
}
if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == reqTab[cacheObjSubType[`item_res`]] {
log.Printf("jobGWithdraw[%d] : Requesting res.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]]
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_res_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
/*
c, err := getLockedRoleClient(`commander`)
logOnError(err, "jobGWithdraw: getLockedRoleClient(commander)")
if err == nil {
c.Mux.Unlock()
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_res`)
} else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] {
log.Printf("jobGWithdraw[%d] : Requesting alch.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]]
*/
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_alch_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
var stock string
for _, i := range p.Items {
if i.Available > i.Required {
stock = fmt.Sprintf("%s\n%d x %s", stock, i.Required, i.Name)
} else if i.Available > 0 {
stock = fmt.Sprintf("%s\n%d x %s", stock, i.Available, i.Name)
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_alch`)
} else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] {
log.Printf("jobGWithdraw[%d] : Requesting misc.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]]
}
if len(stock) > 0 {
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_misc_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_misc`)
} else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] {
log.Printf("jobGWithdraw[%d] : Requesting recipe.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]]
id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGWithdraw : createJob")
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_job_gwithdraw_ack`])
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_rec_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_rec`)
} else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] {
log.Printf("jobGWithdraw[%d] : Requesting part.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]]
sha256 := sha256.Sum256([]byte(cfg.Telegram.Token))
sha128 := sha256[:aes.BlockSize]
c, err := aes.NewCipher(sha128)
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_part_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_parts`)
} else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] {
log.Printf("jobGWithdraw[%d] : Requesting other.\n", j.ID64)
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]]
in := make([]byte, 0)
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(id))
in = append(in, buf...)
binary.LittleEndian.PutUint64(buf, uint64(p.UserID64))
in = append(in, buf...)
out := make([]byte, len(in))
b, _ := json.Marshal(p)
p2 := JobPayloadMsgDel{
MsgTypeID64: cacheObjSubType[`msg_gstock_oth_req`],
Delay: (10 * time.Second),
ObjMsgID64: 0,
ref := hex.EncodeToString(in)
log.Printf("jobGWithdraw[%d] : in string : %s.\n", j.ID64, ref)
c.Encrypt(out, in)
ref = hex.EncodeToString(out)
log.Printf("jobGWithdraw[%d] : out string : %s.\n", j.ID64, ref)
ref = hex.EncodeToString(out)
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGWithdraw : getObjMsg")
p.CleanupMsg = append(p.CleanupMsg, *m)
b, err = json.Marshal(p)
log.Printf("jobGWithdraw[%d] : %s\n", j.ID64, string(b))
u, err := bot.ChatByID(fmt.Sprintf("%d", p.UserID64))
logOnError(err, "jobGWithdraw : ChatByID")
msg := fmt.Sprintf("Click to validate @%s's withdrawal of<code>%s</code>\n/withdraw_%s", u.Username, stock, string(ref))
cmd := TGCommand{
Type: commandSendMsg,
Text: msg,
ToChatID64: cfg.Bot.Mainchat,
ParseMode: cmdParseModeHTML,
}
b2, _ := json.Marshal(p2)
createJobCallback(cacheObjSubType[`job_gwithdraw`], j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], b, time.Minute)
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_other`)
TGCmdQueue <- cmd
} else {
/*
c, err := getLockedRoleClient(`commander`)
logOnError(err, "jobGWithdraw: getLockedRoleClient(commander)")
if err == nil {
c.Mux.Unlock()
}
*/
var stock string
for _, i := range p.Items {
if i.Available > i.Required {
stock = fmt.Sprintf("%s\n%d x %s", stock, i.Required, i.Name)
} else if i.Available > 0 {
stock = fmt.Sprintf("%s\n%d x %s", stock, i.Available, i.Name)
}
}
if len(stock) > 0 {
b, _ := json.Marshal(p)
id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGWithdraw : createJob")
setJobCallback(id, int64(bot.Me.ID), cacheObjSubType[`msg_job_gwithdraw_ack`])
sha256 := sha256.Sum256([]byte(cfg.Telegram.Token))
sha128 := sha256[:aes.BlockSize]
c, err := aes.NewCipher(sha128)
in := make([]byte, 0)
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(id))
in = append(in, buf...)
binary.LittleEndian.PutUint64(buf, uint64(p.UserID64))
in = append(in, buf...)
out := make([]byte, len(in))
ref := hex.EncodeToString(in)
log.Printf("jobGWithdraw[%d] : in string : %s.\n", j.ID64, ref)
c.Encrypt(out, in)
ref = hex.EncodeToString(out)
log.Printf("jobGWithdraw[%d] : out string : %s.\n", j.ID64, ref)
ref = hex.EncodeToString(out)
m, err := getObjMsg(j.Trigger)
logOnError(err, "jobGWithdraw : getObjMsg")
p.CleanupMsg = append(p.CleanupMsg, *m)
b, err = json.Marshal(p)
log.Printf("jobGWithdraw[%d] : %s\n", j.ID64, string(b))
u, err := bot.ChatByID(fmt.Sprintf("%d", p.UserID64))
logOnError(err, "jobGWithdraw : ChatByID")
msg := fmt.Sprintf("Click to validate @%s's withdrawal of<code>%s</code>\n/withdraw_%s", u.Username, stock, string(ref))
cmd := TGCommand{
Type: commandSendMsg,
Text: msg,
ToChatID64: cfg.Bot.Mainchat,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- cmd
} else {
cmd := TGCommand{
Type: commandReplyMsg,
Text: "No stock available whatsoever",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- cmd
cmd := TGCommand{
Type: commandReplyMsg,
Text: "No stock available whatsoever",
FromMsgID64: p.MsgID64,
FromChatID64: p.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- cmd
}
err = setJobDone(j.ID64)
@ -1903,6 +1755,111 @@ func jobGetHammerTime(j Job) {
return
}
func jobCraftItem(j Job) {
var (
p JobPayloadCraftItem
p2 JobPayloadGetVault
b []byte
item *ChatWarsItem
totalMana int64
requiredItems map[string]int64
missingItems map[string]int64
availableItems map[string]int64
craftItems map[string]int64
)
err := setJobStart(j.ID64)
logOnError(err, "jobCraftItem : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobCraftItem : Unmarshal payload")
if p.Status == 0 {
p2.JobCallbackID64 = j.ID64
p2.ItemTypeList = make([]int64, 0)
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_res`])
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_recipe`])
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_part`])
b, err = json.Marshal(p2)
logOnError(err, "jobCraftItem : Marshal(p2)")
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
p.Status = 1
p.VaultJobID64 = jobID64
b, err = json.Marshal(p)
logOnError(err, "jobCraftItem : Marshal(p)")
err = setJobPayloadJSON(j.ID64, p)
logOnError(err, "jobCraftItem : setJobPayloadJSON(p)")
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
return
}
b = getJobPayload(p.VaultJobID64)
err = json.Unmarshal(b, &p2)
logOnError(err, "jobCraftItem : Unmarshal(p2)")
item = getObjItem(p.ObjItemID64)
availableItems = make(map[string]int64)
requiredItems = make(map[string]int64)
missingItems = make(map[string]int64)
totalMana = item.Craft.Mana
for _, v := range item.Craft.Items {
log.Printf("jobCraftItem[%s] : %s - %d\n", item.Code, v.Code, v.Quantity)
requiredItems[v.Code] = v.Quantity
missingItems[v.Code] = 0
craftItems[v.Code] = 0
}
for _, v := range p2.Vault {
availableItems[v.Code] = v.Quantity
}
update := true
for update {
update = false
for code, req := range requiredItems {
ava, _ := availableItems[code]
craft, _ := craftItems[code]
missing, _ := missingItems[code]
if (ava + craft + missing) < req {
update = true
obj := getObjItem(getObjItemID(code, ``))
if obj.Craft != nil {
craftItems[code] = req - ava
totalMana = (req - ava) * obj.Craft.Mana
for _, v := range obj.Craft.Items {
req2, _ := requiredItems[v.Code]
requiredItems[v.Code] = req2 + v.Quantity*(req-ava)
}
} else {
missingItems[code] = req - ava
}
}
}
}
for code, req := range requiredItems {
ava, _ := availableItems[code]
craft, _ := craftItems[code]
missing, _ := missingItems[code]
log.Printf("jobCraftItem[%s] : %s - Req : %d / Ava : %d / Craft : %d / Missing : %d\n", item.Code, v.Code, req, ava, craft, missing)
}
/* we can finish the job */
err = setJobDone(j.ID64)
logOnError(err, "jobCraftItem : setJobDone")
return
}
func jobGetVault(j Job) {
var (
p JobPayloadGetVault
@ -1911,8 +1868,6 @@ func jobGetVault(j Job) {
)
items := []string{`item_res`, `item_alch`, `item_misc`, `item_recipe`, `item_part`, `item_other`}
log.Printf("jobGetVault[%d] : Starting.\n", j.ID64)
reqTab = make(map[int64]int64)
for k, v := range items {
reqTab[cacheObjSubType[v]] = 1 << uint(k)
@ -1987,7 +1942,6 @@ func jobGetVault(j Job) {
}
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)
@ -1997,7 +1951,6 @@ func jobGetVault(j Job) {
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)
@ -2007,7 +1960,6 @@ func jobGetVault(j Job) {
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)
@ -2017,7 +1969,6 @@ func jobGetVault(j Job) {
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)
@ -2027,7 +1978,6 @@ func jobGetVault(j Job) {
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)
@ -2037,7 +1987,6 @@ func jobGetVault(j Job) {
clientSendCWMsg(j.UserID64, `/g_stock_parts`)
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)
@ -2050,23 +1999,17 @@ func jobGetVault(j Job) {
setJobPayloadJSON(j.ID64, p)
}
log.Printf("jobGetVault[%d] : Cleaning up.\n", j.ID64)
/* clean up the messages */
for _, d := range p.CleanupMsg {
clientDelTGMsg(j.UserID64, d.ID64, d.ChatID64)
}
log.Printf("jobGetVault[%d] : Rescheduling callback.\n", j.ID64)
/* 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 */
log.Printf("jobGetVault[%d] : All done.\n", j.ID64)
err = setJobDone(j.ID64)
logOnError(err, "jobGetVault : setJobDone")

View File

@ -511,15 +511,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case cacheObjSubType[`msg_bot_g_stock`]:
botGStock(m)
case cacheObjSubType[`msg_bot_craft_item`]:
c := TGCommand{
Type: commandReplyMsg,
Text: `<b>test</b>`,
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
botCraftItem(m)
case cacheObjSubType[`msg_bot_craft_all`]:
c := TGCommand{
Type: commandReplyMsg,
@ -625,6 +617,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobGetHammerTime(j)
case cacheObjSubType[`job_get_vault`]:
jobGetVault(j)
case cacheObjSubType[`job_craft_item`]:
jobCraftItem(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
}