test
This commit is contained in:
parent
21a1132250
commit
19cb2856dc
27
bot.go
27
bot.go
@ -123,7 +123,7 @@ func botMsgRescan(m *tb.Message) {
|
||||
}
|
||||
b, _ := json.Marshal(p)
|
||||
log.Printf("botMsgRescan : json : %s\n", string(b))
|
||||
err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanMsg, int64(m.Sender.ID), time.Now(), b)
|
||||
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanMsg, int64(m.Sender.ID), time.Now(), b)
|
||||
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
|
||||
if err != nil {
|
||||
c := TGCommand{
|
||||
@ -160,7 +160,7 @@ func botMsgRescanAll(m *tb.Message) {
|
||||
ChatID64: m.Chat.ID,
|
||||
}
|
||||
b, _ := json.Marshal(p)
|
||||
err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b)
|
||||
_, err := createJob(objSubTypeJobRescanMsg, objJobPriorityRescanAllMsg, int64(m.Sender.ID), time.Now(), b)
|
||||
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
|
||||
|
||||
if err != nil {
|
||||
@ -272,8 +272,6 @@ func botListParsingRule(m *tb.Message) {
|
||||
func botTimer(m *tb.Message) {
|
||||
r := regexp.MustCompile("^(?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
|
||||
if r.MatchString(m.Payload) {
|
||||
log.Printf("Timer : Duration : %s\n", r.ReplaceAllString(m.Payload, "${Duration}"))
|
||||
log.Printf("Timer : Msg : %s\n", r.ReplaceAllString(m.Payload, "${Msg}"))
|
||||
d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}"))
|
||||
if err != nil {
|
||||
c := TGCommand{
|
||||
@ -284,7 +282,6 @@ func botTimer(m *tb.Message) {
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
} else {
|
||||
log.Printf("Timer : Event : %s\n", time.Now().Add(d).Format(time.RFC850))
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
Text: r.ReplaceAllString(m.Payload, "${Msg}"),
|
||||
@ -292,8 +289,26 @@ func botTimer(m *tb.Message) {
|
||||
ToChatID64: userID64ChtWrsBot,
|
||||
}
|
||||
b, _ := json.Marshal(c)
|
||||
err := createJob(objSubTypeJobMsgClient, objJobPriority, int64(m.Sender.ID), time.Now().Add(d), b)
|
||||
t := time.Now().Add(d)
|
||||
objID64, err := createJob(objSubTypeJobMsgClient, objJobPriority, int64(m.Sender.ID), t, b)
|
||||
logOnError(err, "botTimer : createJob")
|
||||
if err != nil {
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: fmt.Sprintf("%s", err),
|
||||
FromMsgID64: int64(m.ID),
|
||||
FromChatID64: m.Chat.ID,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
} else {
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: fmt.Sprintf("Job #%d scheduled at %s", objId, t.Format(time.RFC850)),
|
||||
FromMsgID64: int64(m.ID),
|
||||
FromChatID64: m.Chat.ID,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
2
job.go
2
job.go
@ -30,7 +30,7 @@ func jobRescan(j Job) {
|
||||
Text: fmt.Sprintf("%d messages processed in %s.", len(ids), time.Since(start)),
|
||||
}
|
||||
b, _ := json.Marshal(p)
|
||||
err := createJob(objSubTypeJobSetJobDone, objJobPriorityRescanAllMsg, j.UserID64, time.Now(), b)
|
||||
_, err := createJob(objSubTypeJobSetJobDone, objJobPriorityRescanAllMsg, j.UserID64, time.Now(), b)
|
||||
logOnError(err, "jobRescan : createJob(objSubTypeJobSetJobDone)")
|
||||
|
||||
} else if len(ids) == 1 {
|
||||
|
14
sql.go
14
sql.go
@ -1505,12 +1505,12 @@ func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Time, payload []byte) error {
|
||||
func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Time, payload []byte) (int64, error) {
|
||||
stmt, err := db.Prepare(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
|
||||
VALUES (? , ?);`)
|
||||
logOnError(err, "createJob : prepare insert obj")
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
@ -1518,30 +1518,30 @@ func createJob(jobTypeID int32, priority int32, userID64 int64, schedule time.Ti
|
||||
s := fmt.Sprintf("createJob, insert obj(%d, %d)", objTypeJob, jobTypeID)
|
||||
logOnError(err, s)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
objId, err := res.LastInsertId()
|
||||
logOnError(err, "createJob : get last insert Id")
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
stmt, err = db.Prepare(`INSERT INTO obj_job (obj_id, priority, user_id, session_id, status, schedule, is_done, in_work, inserted, pulled, started, ended, payload)
|
||||
VALUES (?, ?, ?, NULL, ?, ?, 0, 0, ?, NULL, NULL, NULL, ?);`)
|
||||
logOnError(err, "createJob : prepare insert obj_job")
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(objId, priority, userID64, objJobStatusNew, schedule, time.Now(), payload)
|
||||
logOnError(err, "createJob : insert obj_job")
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return objId, nil
|
||||
}
|
||||
|
||||
func setJobDone(jobId int64) error {
|
||||
|
@ -114,7 +114,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
ObjID64: objId,
|
||||
}
|
||||
b, _ := json.Marshal(&p)
|
||||
err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b)
|
||||
_, err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
||||
// only advertise live pillages
|
||||
if m.Date.Add(3 * time.Minute).After(time.Now()) {
|
||||
|
Loading…
Reference in New Issue
Block a user