test g withdraw
This commit is contained in:
parent
a608954411
commit
f00082e80d
15
bot.go
15
bot.go
@ -64,6 +64,11 @@ func BotHandlers(b *tb.Bot) {
|
|||||||
b.Start()
|
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) {
|
func botPhoto(m *tb.Message) {
|
||||||
fmt.Println("botPhoto :", m.Text)
|
fmt.Println("botPhoto :", m.Text)
|
||||||
// photos only
|
// photos only
|
||||||
@ -952,18 +957,18 @@ func botGWithdraw(m *tb.Message) {
|
|||||||
ChatID64: m.Chat.ID,
|
ChatID64: m.Chat.ID,
|
||||||
Status: 0,
|
Status: 0,
|
||||||
}
|
}
|
||||||
items := []ChatWarsItems{}
|
items := []JobPayloadGWithdrawItem{}
|
||||||
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {
|
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {
|
||||||
log.Printf("botGWithdraw : %s / %s / %s\n", l[0], l[1], l[2])
|
log.Printf("botGWithdraw : %s / %s / %s\n", l[0], l[1], l[2])
|
||||||
i := l[1]
|
i := l[1]
|
||||||
q, _ := strconv.ParseInt(l[2], 10, 64)
|
q, _ := strconv.ParseInt(l[2], 10, 64)
|
||||||
item := ChatWarsItems{
|
item := JobPayloadGWithdrawItem{
|
||||||
Item: i,
|
Code: i,
|
||||||
Quantity: q,
|
Required: q,
|
||||||
}
|
}
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
p.Request = items
|
p.Items = items
|
||||||
|
|
||||||
b, _ := json.Marshal(p)
|
b, _ := json.Marshal(p)
|
||||||
t := time.Now().UTC()
|
t := time.Now().UTC()
|
||||||
|
@ -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
|
|
23
def.go
23
def.go
@ -144,9 +144,10 @@ type ChatWarsItemCraft struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ChatWarsItems struct {
|
type ChatWarsItems struct {
|
||||||
Item string `json:"item"`
|
ItemID64 int64 `json:"item_id"`
|
||||||
ItemID64 int64
|
Code string `json:"code"`
|
||||||
Quantity int64 `json:"quantity"`
|
Name string `json:"name"`
|
||||||
|
Quantity int64 `json:"quantity"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatWarsCallback struct {
|
type ChatWarsCallback struct {
|
||||||
@ -396,12 +397,18 @@ type JobPayloadGStock struct {
|
|||||||
Stock []ChatWarsItems `json:"stock"`
|
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 {
|
type JobPayloadGWithdraw struct {
|
||||||
MsgID64 int64 `json:"msg_id"`
|
MsgID64 int64 `json:"msg_id"`
|
||||||
ChatID64 int64 `json:"chat_id"`
|
ChatID64 int64 `json:"chat_id"`
|
||||||
Request []ChatWarsItems `json:"request"`
|
Items []JobPayloadGWithdrawItem `json:"items"`
|
||||||
Available []ChatWarsItems `json:"available"`
|
Status int64 `json:"status"`
|
||||||
Status int64 `json:"status"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type JobPayloadGDeposit struct {
|
type JobPayloadGDeposit struct {
|
||||||
|
21
job.go
21
job.go
@ -1407,8 +1407,8 @@ func jobGWithdraw(j Job) {
|
|||||||
logOnError(err, "jobGWithdraw : Unmarshal payload")
|
logOnError(err, "jobGWithdraw : Unmarshal payload")
|
||||||
|
|
||||||
if p.Status == 0 {
|
if p.Status == 0 {
|
||||||
for _, item := range p.Request {
|
for k, item := range p.Items {
|
||||||
id := getSilentObjItemID(item.Item, ``)
|
id := getSilentObjItemID(item.Code, ``)
|
||||||
if id != 0 {
|
if id != 0 {
|
||||||
obj, _ := getObjItem(id)
|
obj, _ := getObjItem(id)
|
||||||
p.Status = p.Status | reqTab[obj.ItemTypeID]
|
p.Status = p.Status | reqTab[obj.ItemTypeID]
|
||||||
@ -1441,6 +1441,20 @@ func jobGWithdraw(j Job) {
|
|||||||
id, err := getObjSubTypeId(j.Trigger)
|
id, err := getObjSubTypeId(j.Trigger)
|
||||||
logOnError(err, "jobGWithdraw : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
|
logOnError(err, "jobGWithdraw : getObjSubType("+strconv.FormatInt(j.Trigger, 10)+")")
|
||||||
if err == nil && id == cacheObjSubType[`msg_gstock_any_ack`] {
|
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{
|
p2 := JobPayloadMsgDel{
|
||||||
Delay: (10 * time.Second),
|
Delay: (10 * time.Second),
|
||||||
ObjMsgID64: j.Trigger,
|
ObjMsgID64: j.Trigger,
|
||||||
@ -1541,7 +1555,8 @@ func jobGWithdraw(j Job) {
|
|||||||
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
|
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
|
||||||
clientSendCWMsg(j.UserID64, `/g_stock_other`)
|
clientSendCWMsg(j.UserID64, `/g_stock_other`)
|
||||||
} else {
|
} 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)
|
err = setJobDone(j.ID64)
|
||||||
|
2
msg.go
2
msg.go
@ -255,6 +255,8 @@ func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*Cha
|
|||||||
q, _ := strconv.ParseInt(l[3], 10, 64)
|
q, _ := strconv.ParseInt(l[3], 10, 64)
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
item := ChatWarsItems{
|
item := ChatWarsItems{
|
||||||
|
Code: l[1],
|
||||||
|
Name: l[2],
|
||||||
ItemID64: i,
|
ItemID64: i,
|
||||||
Quantity: q,
|
Quantity: q,
|
||||||
}
|
}
|
||||||
|
10
utils.go
10
utils.go
@ -8,8 +8,6 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
tb "gopkg.in/tucnak/telebot.v2"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func failOnError(err error, msg string) {
|
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 {
|
func ReadConfig(path string) error {
|
||||||
b, err := Asset("data/config.json")
|
b, err := Asset("data/config.json")
|
||||||
logOnError(err, "readConfig : load data/config.json")
|
logOnError(err, "readConfig : load data/config.json")
|
||||||
@ -64,9 +57,6 @@ func ReadConfig(path string) error {
|
|||||||
err = json.Unmarshal(b, &cfg)
|
err = json.Unmarshal(b, &cfg)
|
||||||
logOnError(err, "readConfig : Unmarshal("+path+")")
|
logOnError(err, "readConfig : Unmarshal("+path+")")
|
||||||
|
|
||||||
b, err = json.Marshal(cfg)
|
|
||||||
log.Printf("ReadConfig : %s\n", b)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user