diff --git a/cron.go b/cron.go index 7f15644..03af37b 100644 --- a/cron.go +++ b/cron.go @@ -10,7 +10,8 @@ import ( func startCron() *cron.Cron { c := cron.New(cron.WithLocation(time.UTC)) - c.AddFunc("15 0,8,16 * * *", cronSendWarReport) + c.AddFunc("15 7,15,23 * * *", cronSendWarReport) + c.AddFunc("58 6,14,22 * * *", cronSetDef) c.Start() return c } @@ -30,7 +31,22 @@ func cronSendWarReport() { b, _ := json.Marshal(&p) err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute) logOnError(err, "cronSendWarReport : createJobCallback") - clientSendCWMsg(c.TGUserID64, `/report`) + clientSendCWMsgDelay(c.TGUserID64, `/report`, 0) + } + } + muxClients.RUnlock() + return +} + +func cronSetDef() { + muxClients.RLock() + for _, c := range clients { + if c.Active { + p := JobPayloadSetDef{} + b, _ := json.Marshal(&p) + err := createJobCallback(objSubTypeJobSetDef, c.TGUserID64, objSubTypeMessageMeAck, b, 1*time.Minute) + logOnError(err, "cronSetDef : createJobCallback") + clientSendCWMsgDelay(c.TGUserID64, `🏅Me`, 0) } } muxClients.RUnlock() diff --git a/def.go b/def.go index 1b72d33..030e7cd 100644 --- a/def.go +++ b/def.go @@ -290,6 +290,9 @@ type Job struct { Payload []byte } +type JobPayloadSetDef struct { +} + type JobPayloadFwdMsg struct { ChatID64 int64 `json:"chat_id"` } @@ -535,6 +538,7 @@ const ( objSubTypeJobVaultUserStatus = 615 objSubTypeJobVaultItemStatus = 616 objSubTypeJobFwdMsg = 617 + objSubTypeJobSetDef = 618 objSubTypeItemResource = 701 objSubTypeItemAlch = 702 objSubTypeItemMisc = 703 diff --git a/job.go b/job.go index 42dce19..b5f4b97 100644 --- a/job.go +++ b/job.go @@ -1168,3 +1168,20 @@ func jobFwdMsg(j Job) { return } + +func jobSetDef(j Job) { + var p JobPayloadSetDef + err := setJobStart(j.ID64) + logOnError(err, "jobSetDef : setJobStart") + + err = json.Unmarshal(j.Payload, &p) + logOnError(err, "jobSetDef : Unmarshal payload") + + cwm, err := getObjMsg(j.Trigger) + logOnError(err, "jobSetDef : getObjMsg msg") + + err = setJobDone(j.ID64) + logOnError(err, "jobSetDef : setJobDone") + + return +} diff --git a/sql.go b/sql.go index 7f70a17..34c7d2d 100644 --- a/sql.go +++ b/sql.go @@ -567,6 +567,7 @@ func initDB() { ,(` + 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(objSubTypeJobSetDef) + `, "job_set_def", "Set Defense 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) + `) diff --git a/workers.go b/workers.go index b5c4e6a..5f654dd 100644 --- a/workers.go +++ b/workers.go @@ -577,6 +577,8 @@ func JobWorker(id int, jobs <-chan Job) { jobVaultItemStatus(j) case objSubTypeJobFwdMsg: jobFwdMsg(j) + case objSubTypeJobSetDef: + jobSetDef(j) default: log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) }