update set def

This commit is contained in:
shoopea 2019-12-13 16:34:32 +08:00
parent 0d6cce136d
commit 0fb27e8309
5 changed files with 42 additions and 2 deletions

20
cron.go
View File

@ -10,7 +10,8 @@ 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("15 0,8,16 * * *", cronSendWarReport) c.AddFunc("15 7,15,23 * * *", cronSendWarReport)
c.AddFunc("58 6,14,22 * * *", cronSetDef)
c.Start() c.Start()
return c return c
} }
@ -30,7 +31,22 @@ func cronSendWarReport() {
b, _ := json.Marshal(&p) b, _ := json.Marshal(&p)
err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute) err := createJobCallback(objSubTypeJobFwdMsg, c.TGUserID64, objSubTypeMessageReportAck, b, 1*time.Minute)
logOnError(err, "cronSendWarReport : createJobCallback") 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() muxClients.RUnlock()

4
def.go
View File

@ -290,6 +290,9 @@ type Job struct {
Payload []byte Payload []byte
} }
type JobPayloadSetDef struct {
}
type JobPayloadFwdMsg struct { type JobPayloadFwdMsg struct {
ChatID64 int64 `json:"chat_id"` ChatID64 int64 `json:"chat_id"`
} }
@ -535,6 +538,7 @@ const (
objSubTypeJobVaultUserStatus = 615 objSubTypeJobVaultUserStatus = 615
objSubTypeJobVaultItemStatus = 616 objSubTypeJobVaultItemStatus = 616
objSubTypeJobFwdMsg = 617 objSubTypeJobFwdMsg = 617
objSubTypeJobSetDef = 618
objSubTypeItemResource = 701 objSubTypeItemResource = 701
objSubTypeItemAlch = 702 objSubTypeItemAlch = 702
objSubTypeItemMisc = 703 objSubTypeItemMisc = 703

17
job.go
View File

@ -1168,3 +1168,20 @@ func jobFwdMsg(j Job) {
return 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
}

1
sql.go
View File

@ -567,6 +567,7 @@ func initDB() {
,(` + 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(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(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) + `)

View File

@ -577,6 +577,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobVaultItemStatus(j) jobVaultItemStatus(j)
case objSubTypeJobFwdMsg: case objSubTypeJobFwdMsg:
jobFwdMsg(j) jobFwdMsg(j)
case objSubTypeJobSetDef:
jobSetDef(j)
default: default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID) log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
} }