test exchange deals

This commit is contained in:
shoopea 2019-09-14 16:27:38 +08:00
parent d72abeaf73
commit 516b624627
5 changed files with 68 additions and 0 deletions

15
bot.go
View File

@ -34,6 +34,7 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/g_stock", botGStock)
b.Handle("/g_deposit_all", botGDepositAll)
b.Handle("/save_res", botSaveRes)
b.Handle("/backup_export", botBackupExport)
b.Handle("/backup_import", botBackupImport)
@ -627,6 +628,20 @@ func botGStock(m *tb.Message) {
return
}
func botSaveRes(m *tb.Message) {
if !m.Private() {
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: "Not coded yet.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
func botGDepositAll(m *tb.Message) {
if !m.Private() {
return

16
def.go
View File

@ -103,6 +103,20 @@ type ChatWarsMessage struct {
Text string `json:"text"`
}
type ChatWarsExchangeDeal struct {
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
Price int64 `json:"price"`
Link string `json:"link"`
}
type ChatWarsMessageExchangeAck struct {
Msg *ChatWarsMessage `json:"msg"`
ActiveDeals int64 `json:"active_deals"`
MaxDeals int64 `json:"max_deals"`
DealList []ChatWarsExchangeDeal `json:"deals"`
}
type ChatWarsMessageGStock struct {
Msg *ChatWarsMessage `json:"msg"`
OwnerID64 int64 `json:"owner_id"`
@ -446,6 +460,8 @@ const (
objSubTypeMessageBack = 379 // Back (done)
objSubTypeMessageCastleReq = 380 // Castle (done)
objSubTypeMessageCastleAck = 381 // Castle msg (not done)
objSubTypeMessageExchangeReq = 382 // ⚖Exchange (done)
objSubTypeMessageExchangeAck = 383 // List of deals (done)
objSubTypeJobPillage = 601
objSubTypeJobTribute = 602
objSubTypeJobStatus = 603

25
msg.go
View File

@ -23,6 +23,31 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
}
}
func parseSubTypeMessageExchangeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageExchangeAck, error) {
cwm := ChatWarsMessageExchangeAck{}
deals := []ChatWarsExchangeDeal{}
log.Printf("parseSubTypeMessageExchangeAck : ActiveDeals : %s\n", r.ReplaceAllString(m.Text, "${ActiveDeals}"))
log.Printf("parseSubTypeMessageExchangeAck : MaxDeals : %s\n", r.ReplaceAllString(m.Text, "${MaxDeals}"))
/*
re := regexp.MustCompile(`([a-zA-Z ]+)\n([0-9]+) x ([0-9]+)💰 [Cancelling] (.*)\n`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
i := getObjItemID(``, l[1])
q, _ := strconv.ParseInt(l[2], 10, 64)
if i != 0 {
item := ChatWarsItems{
ItemID64: i,
Quantity: q,
}
items = append(items, item)
}
}
*/
cwm.Deals = items
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAnyAck, error) {
cwm := ChatWarsMessageStockAnyAck{}
items := []ChatWarsItems{}

View File

@ -216,6 +216,15 @@ func resetMsgParsingRules() {
,(5000, ` + strconv.Itoa(objSubTypeMessageGoFastFight) + `, "Fast Fight", "^▶Fast fight$")
,(5000, ` + strconv.Itoa(objSubTypeMessageCastleReq) + `, "Castle Req", "^🏰Castle$")
,(5000, ` + strconv.Itoa(objSubTypeMessageCastleAck) + `, "Castle Ack", "^$")
,(5000, ` + strconv.Itoa(objSubTypeMessageExchangeReq) + `, "Exchange Req", "^⚖Exchange$")
,(5000, ` + strconv.Itoa(objSubTypeMessageExchangeAck) + `, "Exchange Ack", "^Here you can buy and sell some items.\\n` +
`To find a tradable item just type:\\n` +
`/t [item name]\\n` +
`Example:\\n` +
`/t coal\\n\\n` +
`Your deals \\((?P<ActiveDeals>[0-9]+)/(?P<MaxDeals>[0-9]+)\\):\\n` +
`(?P<Deals>.*)\\n` +
`Your last 10 comitted trades: /trades$")
;`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
}

View File

@ -471,6 +471,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageStockAnyAck:
_, err := parseSubTypeMessageStockAnyAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageStockAnyAck.")
case objSubTypeMessageExchangeAck:
_, err := parseSubTypeMessageExchangeAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageExchangeAck.")
default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID, objId, m.Text)
}