test
This commit is contained in:
parent
9852ec56ff
commit
02619bde5e
32
bot.go
32
bot.go
@ -1044,6 +1044,38 @@ func botVaultVal(m *ChatWarsMessage) {
|
||||
return
|
||||
}
|
||||
|
||||
func botVaultValOth(m *ChatWarsMessage) {
|
||||
p := JobPayloadVaultValOth{
|
||||
MsgID64: m.ID64,
|
||||
ChatID64: m.ChatID64,
|
||||
Status: 0,
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(p)
|
||||
t := time.Now().UTC().Add(1 * time.Second)
|
||||
_, err := createJob(cacheObjSubType[`job_vault_val_oth`], objJobPriority, m.TGSenderUserID64, 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: "Vault val (other) coming",
|
||||
FromMsgID64: m.ID64,
|
||||
FromChatID64: m.ChatID64,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func botAlchAll(m *ChatWarsMessage) {
|
||||
|
||||
p := JobPayloadAlchAll{
|
||||
|
@ -744,6 +744,11 @@
|
||||
"name": "Vault valuation",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "msg_bot_vault_val_oth",
|
||||
"name": "Vault valuation (other)",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "job_pillage",
|
||||
"name": "Pillage job",
|
||||
@ -884,6 +889,11 @@
|
||||
"name": "Check vault valuation",
|
||||
"obj_type": "job"
|
||||
},
|
||||
{
|
||||
"intl_id": "job_vault_val_oth",
|
||||
"name": "Check vault valuation (other)",
|
||||
"obj_type": "job"
|
||||
},
|
||||
{
|
||||
"intl_id": "item_res",
|
||||
"name": "Resource",
|
||||
|
16
def.go
16
def.go
@ -613,6 +613,22 @@ type JobPayloadVaultVal struct {
|
||||
VaultJobID64 int64 `json:"vault_job_id`
|
||||
}
|
||||
|
||||
type JobPayloadVaultValOth struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
Status int64 `json:"status"`
|
||||
VaultJobID64 int64 `json:"vault_job_id`
|
||||
Val []JobPayloadVaultValTab `json:"val_tab"`
|
||||
}
|
||||
|
||||
type JobPayloadVaultValTab struct {
|
||||
ItemID64 int64 `json:"item_id"`
|
||||
Quality string `json:"quality"`
|
||||
Quantity int `json:"quantity"`
|
||||
Volume int `json:"volume"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
type JobPayloadGetVault struct {
|
||||
Status int64 `json:"status"`
|
||||
JobCallbackID64 int64 `json:"job_callback_id"`
|
||||
|
27
item.go
27
item.go
@ -461,7 +461,8 @@ func getObjItemVal(objID64 int64, quality string) float64 {
|
||||
row := db.QueryRow(`SELECT avg(omaa.price)
|
||||
FROM obj_msg_auction_announce omaa
|
||||
WHERE omaa.item_id = ?
|
||||
AND omaa.quality = ?`, objID64, quality)
|
||||
AND omaa.quality = ?
|
||||
AND status = 'Finished'`, objID64, quality)
|
||||
err = row.Scan(&val)
|
||||
if err != nil {
|
||||
logOnError(err, "getObjItemVal : row.Scan")
|
||||
@ -469,3 +470,27 @@ func getObjItemVal(objID64 int64, quality string) float64 {
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
func getObjItemValDet(objID64 int64, quality string, days int) (float64, int64) {
|
||||
var val, qty float64
|
||||
item, err := getObjItem(objID64)
|
||||
if err != nil {
|
||||
return 0, 0
|
||||
}
|
||||
if !item.Auction {
|
||||
return 0, 0
|
||||
}
|
||||
row := db.QueryRow(`SELECT avg(omaa.price)
|
||||
,count(*)
|
||||
FROM obj_msg_auction_announce omaa
|
||||
WHERE omaa.item_id = ?
|
||||
AND omaa.quality = ?
|
||||
AND omaa.end > CURRENT_TIMESTAMP - ?
|
||||
AND omaa.status = 'Finished'`, objID64, quality, days)
|
||||
err = row.Scan(&val, &qty)
|
||||
if err != nil {
|
||||
logOnError(err, "getObjItemValDet : row.Scan")
|
||||
return 0, 0
|
||||
}
|
||||
return val, qty
|
||||
}
|
||||
|
84
job.go
84
job.go
@ -15,6 +15,7 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -2682,13 +2683,13 @@ func jobVaultVal(j Job) {
|
||||
switch item.ItemTypeID {
|
||||
case cacheObjSubType[`item_part`]:
|
||||
price = getObjItemVal(v.ItemID64, v.Quality)
|
||||
part += price
|
||||
part += price * v.Quantity
|
||||
case cacheObjSubType[`item_recipe`]:
|
||||
price = getObjItemVal(v.ItemID64, v.Quality)
|
||||
rec += price
|
||||
rec += price * v.Quantity
|
||||
case cacheObjSubType[`item_other`]:
|
||||
price = getObjItemVal(v.ItemID64, v.Quality)
|
||||
other += price
|
||||
other += price * v.Quantity
|
||||
default:
|
||||
}
|
||||
log.Printf("jobVaultVal : %s (%s) - %s => %f\n", v.Code, v.Quality, item.Names[0], price)
|
||||
@ -2709,6 +2710,83 @@ func jobVaultVal(j Job) {
|
||||
return
|
||||
}
|
||||
|
||||
func jobVaultValOth(j Job) {
|
||||
var (
|
||||
p JobPayloadVaultValOth
|
||||
p2 JobPayloadGetVault
|
||||
b []byte
|
||||
)
|
||||
|
||||
err := setJobStart(j.ID64)
|
||||
logOnError(err, "jobVaultValOth : setJobStart")
|
||||
|
||||
err = json.Unmarshal(j.Payload, &p)
|
||||
logOnError(err, "jobVaultValOth : Unmarshal payload")
|
||||
|
||||
if p.Status == 0 {
|
||||
p2.JobCallbackID64 = j.ID64
|
||||
p2.ItemTypeList = make([]int64, 1)
|
||||
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_other`])
|
||||
|
||||
b, err = json.Marshal(p2)
|
||||
logOnError(err, "jobVaultValOth : 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, "jobVaultValOth : Marshal(p)")
|
||||
|
||||
err = setJobPayloadJSON(j.ID64, p)
|
||||
logOnError(err, "jobVaultValOth : setJobPayloadJSON(p)")
|
||||
|
||||
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||
return
|
||||
}
|
||||
|
||||
b = getJobPayload(p.VaultJobID64)
|
||||
err = json.Unmarshal(b, &p2)
|
||||
logOnError(err, "jobVaultValOth : Unmarshal(p2)")
|
||||
p.Val = make([]JobPayloadVaultValTab, 0)
|
||||
|
||||
for _, v := range p2.Vault {
|
||||
price, volume := getObjItemVal(v.ItemID64, v.Quality, 14)
|
||||
t := &JobPayloadVaultValTab{
|
||||
ItemID64: v.ItemID64,
|
||||
Quality: v.Quality,
|
||||
Quantity: v.Quantity,
|
||||
Volume: volume,
|
||||
Value: price,
|
||||
}
|
||||
p.Val = append(p.Val, t)
|
||||
}
|
||||
sort.Slice(p.Val, func(i, j int) bool { return p.Val[i].Volume < p.Val[j].Volume })
|
||||
|
||||
out := fmt.Sprintf("Value (other) :\n")
|
||||
total := 0
|
||||
for _, v := range p.Val {
|
||||
item, _ := getObjItem(v.ItemID64)
|
||||
log.Printf("jobVaultValOth : %s (%s) - %s => %d - %f\n", v.Code, v.Quality, item.Names[0], v.Volume, v.Price)
|
||||
out := fmt.Sprintf("- %s (%s) : %d / %f\n", v.Code, v.Quality, v.Volume, v.Price)
|
||||
}
|
||||
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: out,
|
||||
FromMsgID64: p.MsgID64,
|
||||
FromChatID64: p.ChatID64,
|
||||
ParseMode: cmdParseModeHTML,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
|
||||
err = setJobDone(j.ID64)
|
||||
logOnError(err, "jobVaultValOth : setJobDone")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func jobShops(j Job) {
|
||||
var p JobPayloadShops
|
||||
|
||||
|
11
rules.go
11
rules.go
@ -240,6 +240,17 @@ func resetMsgParsingRules() error {
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
r = MessageParsingRule{
|
||||
Priority: 9999,
|
||||
Description: "Vault valuation (other)",
|
||||
Rule: "^/vault_val_oth$",
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_vault_val_oth`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
}
|
||||
|
||||
// chats
|
||||
|
@ -586,6 +586,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
case cacheObjSubType[`msg_skill_too_low`]:
|
||||
case cacheObjSubType[`msg_bot_vault_val`]:
|
||||
botVaultVal(m)
|
||||
case cacheObjSubType[`msg_bot_vault_val_oth`]:
|
||||
botVaultValOth(m)
|
||||
case cacheObjSubType[`msg_refresh_cmd`]:
|
||||
botRefreshMsg(m, rule.re)
|
||||
default:
|
||||
@ -701,6 +703,8 @@ func JobWorker(id int, jobs <-chan Job) {
|
||||
jobAlchAll(j)
|
||||
case cacheObjSubType[`job_vault_val`]:
|
||||
jobVaultVal(j)
|
||||
case cacheObjSubType[`job_vault_val_oth`]:
|
||||
jobVaultValOth(j)
|
||||
default:
|
||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user