From b0d128af4c0d85e5fd67bf2f0ccee70ce55fea66 Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 12 Dec 2019 18:24:12 +0800 Subject: [PATCH] test jobfwdmsg --- chirpnest.sample.cfg | 3 ++- cron.go | 10 ++++++++-- def.go | 5 +++++ job.go | 23 +++++++++++++++++++++-- main.go | 1 + sql.go | 1 + 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/chirpnest.sample.cfg b/chirpnest.sample.cfg index 23f5215..4dfb371 100644 --- a/chirpnest.sample.cfg +++ b/chirpnest.sample.cfg @@ -21,4 +21,5 @@ admin = 0 guildname = Guild guild = GLD mainchat = 0 -depositchat = 0 \ No newline at end of file +depositchat = 0 +reportchat = 0 \ No newline at end of file diff --git a/cron.go b/cron.go index 8e886c3..2e9b5c2 100644 --- a/cron.go +++ b/cron.go @@ -9,7 +9,7 @@ import ( func startCron() *cron.Cron { c := cron.New(cron.WithLocation(time.UTC)) - c.AddFunc("@every 1m", cronSendReport) + c.AddFunc("15 0,8,16 * * *", cronSendWarReport) c.Start() return c } @@ -19,10 +19,16 @@ func stopCron(c *cron.Cron) { return } -func cronSendReport() { +func cronSendWarReport() { muxClients.RLock() for _, c := range clients { 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`) } } diff --git a/def.go b/def.go index 92ca33d..1b72d33 100644 --- a/def.go +++ b/def.go @@ -290,6 +290,10 @@ type Job struct { Payload []byte } +type JobPayloadFwdMsg struct { + ChatID64 int64 `json:"chat_id"` +} + type JobPayloadMsgRefresh struct { ObjID64 int64 `json:"obj_id"` } @@ -530,6 +534,7 @@ const ( objSubTypeJobSaveRes = 614 objSubTypeJobVaultUserStatus = 615 objSubTypeJobVaultItemStatus = 616 + objSubTypeJobFwdMsg = 617 objSubTypeItemResource = 701 objSubTypeItemAlch = 702 objSubTypeItemMisc = 703 diff --git a/job.go b/job.go index 3bbbd1c..42dce19 100644 --- a/job.go +++ b/job.go @@ -741,14 +741,14 @@ func jobGDepositForward(j Job) { cwm, err := parseSubTypeMessageGDepositReq(msg, rule.re) 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() gDepositForwardMsg = append(gDepositForwardMsg, j.Trigger) gDepositForwardMux.Unlock() err = setJobDone(j.ID64) logOnError(err, "jobGDeposit : setJobDone") } 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()) logOnError(err, "jobGDepositForward : rescheduleJob") setJobCallback(j.ID64, j.UserID64, objSubTypeMessageGDepositReq) @@ -1149,3 +1149,22 @@ func jobGWithdraw(j Job) { 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 +} diff --git a/main.go b/main.go index d88c60b..aa7f8c0 100644 --- a/main.go +++ b/main.go @@ -42,6 +42,7 @@ type Config struct { Guild string Mainchat int64 Depositchat int64 + Reportchat int64 } } diff --git a/sql.go b/sql.go index 3ca6f67..7f70a17 100644 --- a/sql.go +++ b/sql.go @@ -566,6 +566,7 @@ func initDB() { ,(` + 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(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(objSubTypeItemAlch) + `, "item_alch", "Time", ` + strconv.Itoa(objTypeItem) + `) ,(` + strconv.Itoa(objSubTypeItemMisc) + `, "item_misc", "Time", ` + strconv.Itoa(objTypeItem) + `)