This commit is contained in:
shoopea 2019-08-27 23:10:57 +08:00
parent 418f62c07e
commit 5102375a0e
9 changed files with 78 additions and 11 deletions

View File

@ -20,3 +20,5 @@ path = chirpnest
admin = 0
guildname = Guild
guild = GLD
mainchat = 0
depositchat = 0

View File

@ -30,6 +30,17 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
}
}
func clientFwdCWMsg(fromMsgID64 int64, fromChatID64 int64, toChatID64 int64) {
c := TGCommand{
Type: commandForwardMsg,
FromMsgID64: fromMsgID64,
FromChatID64: fromChatID64,
ToChatID64: toChatID64,
}
MQTGCmdQueue <- c
}
func clientSendCWMsg(userID64 int64, s string) {
clientSendCWMsgDelay(userID64, s, 0)
}

16
def.go
View File

@ -109,6 +109,12 @@ type ChatWarsMessageGStock struct {
ItemList []ChatWarsItems `json:"item_list"`
}
type ChatWarsMessageGDepositAck struct {
Msg *ChatWarsMessage `json:"msg"`
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
}
type ChatWarsMessageReportAck struct {
ObjID64 int64 `json:"obj_id"`
}
@ -268,6 +274,11 @@ type JobPayloadGDeposit struct {
Status int `json:"status"`
}
type JobPayloadGDepositFwd struct {
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
}
type JobPayloadSaveRes struct {
MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"`
@ -410,6 +421,8 @@ const (
objSubTypeMessageBusy = 365 // too busy now
objSubTypeMessageStockEmpty = 366 // [empty]
objSubTypeMessageStockAnyAck = 367 // list of stock
objSubTypeMessageGDepositReq = 368 // /g_deposit xx y (done)
objSubTypeMessageGDepositAck = 369 // Deposited successfully: xx (y) (done)
objSubTypeJobPillage = 601
objSubTypeJobTribute = 602
objSubTypeJobStatus = 603
@ -422,7 +435,8 @@ const (
objSubTypeJobBackupExport = 610
objSubTypeJobBackupImport = 611
objSubTypeJobGDeposit = 612
objSubTypeJobSaveRes = 613
objSubTypeJobGDepositForward = 613
objSubTypeJobSaveRes = 614
objSubTypeItemResource = 701
objSubTypeItemAlch = 702
objSubTypeItemMisc = 703

25
job.go
View File

@ -724,6 +724,31 @@ func jobGStock(j Job) {
return
}
func jobGDepositForward(j Job) {
var p JobPayloadGDepositFwd
err := setJobStart(j.ID64)
logOnError(err, "jobGDepositForward : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobGDepositForward : Unmarshal payload")
msg, err := getObjMsg(j.Trigger)
logOnError(err, "jobGDepositForward : getObjMsg")
rule, err := getMsgParsingRule(msg)
logOnError(err, "jobGDepositForward : getMsgParsingRule")
cwm, err := parseSubTypeMessageGDepositAck(msg, rule.re)
if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity {
clientFwdCWMsg(cwm.Msg.ID64, cwm.Msg.ChatID64, cfg.Bot.Depositchat)
err = setJobDone(j.ID64)
logOnError(err, "jobGDeposit : setJobDone")
} else {
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositAck)
}
return
}
func jobGDeposit(j Job) {
var p JobPayloadGDeposit
err := setJobStart(j.ID64)

View File

@ -38,6 +38,8 @@ type Config struct {
Admin int64
Guildname string
Guild string
Mainchat int64
Depositchat int64
}
}

14
msg.go
View File

@ -23,14 +23,20 @@ func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
}
}
func parseSubTypeMessageGDepositAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageGDepositAck, error) {
cwm := ChatWarsMessageGDepositAck{}
cwm.Item, _ = getObjItemID(``, r.ReplaceAllString(m.Text, "${Used}"))
cwm.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
cwm.Msg = m
return &cwm, nil
}
func parseSubTypeMessageStockAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStockAck, error) {
cwm := ChatWarsMessageStockAck{}
items := []ChatWarsItems{}
log.Printf("parseSubTypeMessageReport : Stock Ack identified\n")
log.Printf("parseSubTypeMessageReport : Used : %s\n", r.ReplaceAllString(m.Text, "${Used}"))
log.Printf("parseSubTypeMessageReport : Available : %s\n", r.ReplaceAllString(m.Text, "${Available}"))
re := regexp.MustCompile(`\n([a-zA-Z ]+) \(([0-9]+)\)`)
for _, l := range re.FindAllStringSubmatch(r.ReplaceAllString(m.Text, "${Items}"), -1) {
i := getObjItemID(``, l[1])

View File

@ -197,6 +197,8 @@ func resetMsgParsingRules() {
,(5000, ` + strconv.Itoa(objSubTypeMessageBusy) + `, "Too busy now", "^You are too busy with a different adventure. Try a bit later.$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockEmpty) + `, "Stock Empty", "^\\[empty\\]$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockAnyAck) + `, "Any Stock Ack", "^$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGDepositReq) + `, "GDeposit Req", "^/g_deposit (?P<Item>[0-9]+) (?P<Quantity>[0-9]+)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `, "GDeposit Ack", "^Deposited successfully: (?P<Item>.+) \\((?P<Quantity>[0-9]+)\\)$")
;`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
}

3
sql.go
View File

@ -502,6 +502,8 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeMessageBusy) + `, "busy", "Busy", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageStockEmpty) + `, "stock_empty", "Stock Empty", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageStockAnyAck) + `, "stock_any_ack", "Stock Any Ack", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageGDepositReq) + `, "g_deposit_req", "GDeposit Req", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageGDepositAck) + `, "g_deposit_ack", "GDeposit Ack", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeJobPillage) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_withdraw", "Withdrawal job", ` + strconv.Itoa(objTypeJob) + `)
@ -513,6 +515,7 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeJobBackupExport) + `, "job_backup_export", "Export Backup", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobBackupImport) + `, "job_backup_import", "Import Backup", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGDeposit) + `, "job_gdeposit", "GDeposit job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGDepositForward) + `, "job_gdeposit_fwd", "GDeposit Forward job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)

View File

@ -533,6 +533,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobGStock(j)
case objSubTypeJobGDeposit:
jobGDeposit(j)
case objSubTypeJobGDepositForward:
jobGDepositForward(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}