test g withdraw

This commit is contained in:
shoopea 2020-01-14 11:34:29 +08:00
parent a608954411
commit f00082e80d
7 changed files with 45 additions and 52 deletions

15
bot.go
View File

@ -64,6 +64,11 @@ func BotHandlers(b *tb.Bot) {
b.Start()
}
func PrintText(m *tb.Message) {
log.Printf("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text)
return
}
func botPhoto(m *tb.Message) {
fmt.Println("botPhoto :", m.Text)
// photos only
@ -952,18 +957,18 @@ func botGWithdraw(m *tb.Message) {
ChatID64: m.Chat.ID,
Status: 0,
}
items := []ChatWarsItems{}
items := []JobPayloadGWithdrawItem{}
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {
log.Printf("botGWithdraw : %s / %s / %s\n", l[0], l[1], l[2])
i := l[1]
q, _ := strconv.ParseInt(l[2], 10, 64)
item := ChatWarsItems{
Item: i,
Quantity: q,
item := JobPayloadGWithdrawItem{
Code: i,
Required: q,
}
items = append(items, item)
}
p.Request = items
p.Items = items
b, _ := json.Marshal(p)
t := time.Now().UTC()

View File

@ -1,25 +0,0 @@
[telegram]
url = https://api.telegram.org
token = null
[SQL]
driver = mysql # mysql
type = tcp # tcp, unix
address = 127.0.0.1:3306 # ip:port, path
username = chirpnest
password = chirpnest
database = chirpnest
[rabbit]
user = chirpnest
password = chirpnest
host = localhost:5672
path = chirpnest
[bot]
admin = 0
guildname = Guild
guild = GLD
mainchat = 0
depositchat = 0
reportchat = 0

View File

@ -1 +0,0 @@
package main

23
def.go
View File

@ -144,9 +144,10 @@ type ChatWarsItemCraft struct {
}
type ChatWarsItems struct {
Item string `json:"item"`
ItemID64 int64
Quantity int64 `json:"quantity"`
ItemID64 int64 `json:"item_id"`
Code string `json:"code"`
Name string `json:"name"`
Quantity int64 `json:"quantity"`
}
type ChatWarsCallback struct {
@ -396,12 +397,18 @@ type JobPayloadGStock struct {
Stock []ChatWarsItems `json:"stock"`
}
type JobPayloadGWithdrawItem struct {
Code string `json:"code"`
Name string `json:"name"`
Available int64 `json:"available"`
Required int64 `json:"required"`
}
type JobPayloadGWithdraw struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
Request []ChatWarsItems `json:"request"`
Available []ChatWarsItems `json:"available"`
Status int64 `json:"status"`
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
Items []JobPayloadGWithdrawItem `json:"items"`
Status int64 `json:"status"`
}
type JobPayloadGDeposit struct {

21
job.go
View File

@ -1407,8 +1407,8 @@ func jobGWithdraw(j Job) {
logOnError(err, "jobGWithdraw : Unmarshal payload")
if p.Status == 0 {
for _, item := range p.Request {
id := getSilentObjItemID(item.Item, ``)
for k, item := range p.Items {
id := getSilentObjItemID(item.Code, ``)
if id != 0 {
obj, _ := getObjItem(id)
p.Status = p.Status | reqTab[obj.ItemTypeID]
@ -1441,6 +1441,20 @@ func jobGWithdraw(j Job) {
id, err := getObjSubTypeId(j.Trigger)
logOnError(err, "jobGWithdraw : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
if err == nil && id == cacheObjSubType[`msg_gstock_any_ack`] {
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
}
}
}
p2 := JobPayloadMsgDel{
Delay: (10 * time.Second),
ObjMsgID64: j.Trigger,
@ -1541,7 +1555,8 @@ func jobGWithdraw(j Job) {
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_other`)
} else {
log.Printf("jobGWithdraw[%d] : got all the info\n", j.ID64)
b, err := json.Marshal(p)
log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b))
}
err = setJobDone(j.ID64)

2
msg.go
View File

@ -255,6 +255,8 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha
q, _ := strconv.ParseInt(l[3], 10, 64)
if i != 0 {
item := ChatWarsItems{
Code: l[1],
Name: l[2],
ItemID64: i,
Quantity: q,
}

View File

@ -8,8 +8,6 @@ import (
"regexp"
"strconv"
"time"
tb "gopkg.in/tucnak/telebot.v2"
)
func failOnError(err error, msg string) {
@ -40,11 +38,6 @@ func MaxInt(a int, b int) int {
}
}
func PrintText(m *tb.Message) {
log.Printf("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text)
return
}
func ReadConfig(path string) error {
b, err := Asset("data/config.json")
logOnError(err, "readConfig : load data/config.json")
@ -64,9 +57,6 @@ func ReadConfig(path string) error {
err = json.Unmarshal(b, &cfg)
logOnError(err, "readConfig : Unmarshal("+path+")")
b, err = json.Marshal(cfg)
log.Printf("ReadConfig : %s\n", b)
return nil
}