test jobfwdmsg

This commit is contained in:
shoopea 2019-12-12 18:24:12 +08:00
parent e09ac8e515
commit b0d128af4c
6 changed files with 38 additions and 5 deletions

View File

@ -21,4 +21,5 @@ admin = 0
guildname = Guild guildname = Guild
guild = GLD guild = GLD
mainchat = 0 mainchat = 0
depositchat = 0 depositchat = 0
reportchat = 0

10
cron.go
View File

@ -9,7 +9,7 @@ import (
func startCron() *cron.Cron { func startCron() *cron.Cron {
c := cron.New(cron.WithLocation(time.UTC)) c := cron.New(cron.WithLocation(time.UTC))
c.AddFunc("@every 1m", cronSendReport) c.AddFunc("15 0,8,16 * * *", cronSendWarReport)
c.Start() c.Start()
return c return c
} }
@ -19,10 +19,16 @@ func stopCron(c *cron.Cron) {
return return
} }
func cronSendReport() { func cronSendWarReport() {
muxClients.RLock() muxClients.RLock()
for _, c := range clients { for _, c := range clients {
if c.Active { if c.Active {
p := JobPayloadFwdMsg{
ChatID64: cfg.Bot.Reportchat,
}
b, _ = json.Marshal(&p)
err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute)
logOnError(err, "cronSendWarReport : createJobCallback")
clientSendCWMsg(c.TGUserID64, `/report`) clientSendCWMsg(c.TGUserID64, `/report`)
} }
} }

5
def.go
View File

@ -290,6 +290,10 @@ type Job struct {
Payload []byte Payload []byte
} }
type JobPayloadFwdMsg struct {
ChatID64 int64 `json:"chat_id"`
}
type JobPayloadMsgRefresh struct { type JobPayloadMsgRefresh struct {
ObjID64 int64 `json:"obj_id"` ObjID64 int64 `json:"obj_id"`
} }
@ -530,6 +534,7 @@ const (
objSubTypeJobSaveRes = 614 objSubTypeJobSaveRes = 614
objSubTypeJobVaultUserStatus = 615 objSubTypeJobVaultUserStatus = 615
objSubTypeJobVaultItemStatus = 616 objSubTypeJobVaultItemStatus = 616
objSubTypeJobFwdMsg = 617
objSubTypeItemResource = 701 objSubTypeItemResource = 701
objSubTypeItemAlch = 702 objSubTypeItemAlch = 702
objSubTypeItemMisc = 703 objSubTypeItemMisc = 703

23
job.go
View File

@ -741,14 +741,14 @@ func jobGDepositForward(j Job) {
cwm, err := parseSubTypeMessageGDepositReq(msg, rule.re) cwm, err := parseSubTypeMessageGDepositReq(msg, rule.re)
if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity { if cwm.ItemID64 == p.ItemID64 && cwm.Quantity == p.Quantity {
log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity) //log.Printf("jobGDepositForward : match (%d / %d).\n", cwm.ItemID64, cwm.Quantity)
gDepositForwardMux.Lock() gDepositForwardMux.Lock()
gDepositForwardMsg = append(gDepositForwardMsg, j.Trigger) gDepositForwardMsg = append(gDepositForwardMsg, j.Trigger)
gDepositForwardMux.Unlock() gDepositForwardMux.Unlock()
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "jobGDeposit : setJobDone") logOnError(err, "jobGDeposit : setJobDone")
} else { } else {
log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity) //log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity)
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC()) err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
logOnError(err, "jobGDepositForward : rescheduleJob") logOnError(err, "jobGDepositForward : rescheduleJob")
setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositReq) setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositReq)
@ -1149,3 +1149,22 @@ func jobGWithdraw(j Job) {
return return
} }
func jobFwdMsg(j Job) {
var p JobPayloadFwdMsg
err := setJobStart(j.ID64)
logOnError(err, "jobFwdMsg : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobFwdMsg : Unmarshal payload")
cwm, err := getObjMsg(j.Trigger)
logOnError(err, "jobFwdMsg : getObjMsg msg")
clientFwdCWMsg(j.UserID64, cwm.ID64, cwm.ChatID64, p.ChatID64)
err = setJobDone(j.ID64)
logOnError(err, "jobFwdMsg : setJobDone")
return
}

View File

@ -42,6 +42,7 @@ type Config struct {
Guild string Guild string
Mainchat int64 Mainchat int64
Depositchat int64 Depositchat int64
Reportchat int64
} }
} }

1
sql.go
View File

@ -566,6 +566,7 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `) ,(` + strconv.Itoa(objSubTypeJobSaveRes) + `, "job_save_res", "Save resources job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobVaultUserStatus) + `, "job_vault_user_status", "Vault User Status job", ` + strconv.Itoa(objTypeJob) + `) ,(` + strconv.Itoa(objSubTypeJobVaultUserStatus) + `, "job_vault_user_status", "Vault User Status job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobVaultItemStatus) + `, "job_vault_item_status", "Vault Item Status job", ` + strconv.Itoa(objTypeJob) + `) ,(` + strconv.Itoa(objSubTypeJobVaultItemStatus) + `, "job_vault_item_status", "Vault Item Status job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobFwdMsg) + `, "job_fwd_msg", "Forward Message job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemResource) + `, "item_res", "Time", ` + strconv.Itoa(objTypeItem) + `)
,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `)
,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)