This commit is contained in:
shoopea 2019-05-11 11:15:42 +08:00
parent 8534c71620
commit fbe5d028e5
4 changed files with 29 additions and 18 deletions

15
bot.go
View File

@ -44,6 +44,8 @@ func StartBot() {
b.Handle(tb.OnQuery, botQuery)
b.Handle(tb.OnText, botText)
b.Send("tiennou", "test")
b.Start()
}
@ -89,10 +91,8 @@ func botMsgRescan(m *tb.Message) (string, error) {
}
r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) {
msgID64, _ := strconv.ParseInt(m.Payload, 10, 64)
p := JobPayloadRescanMsg{
MsgID64: msgID64,
}
p := JobPayloadRescanMsg{}
fmt.Sprintf(p.Query, "SELECT o.id from obj o where o.id = %d and o.obj_type_id = %d and o.obj_sub_type_id = %d;", m.Payload, objTypeMessage, objSubTypeMessageUnprocessed)
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobRescanMsg, 2, time.Now(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
@ -105,10 +105,11 @@ func botMsgRescan(m *tb.Message) (string, error) {
}
r = regexp.MustCompile("^all$")
if r.MatchString(m.Payload) {
p := JobPayloadRescanAllMsg{}
p := JobPayloadRescanMsg{}
fmt.Sprintf(p.Query, "SELECT o.id from obj o where o.obj_type_id = %d and o.obj_sub_type_id = %d;", objTypeMessage, objSubTypeMessageUnprocessed)
b, _ := json.Marshal(p)
err := createJob(objSubTypeJobRescanAllMsg, 3, time.Now(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanAllMsg)")
err := createJob(objSubTypeJobRescanMsg, 3, time.Now(), b)
logOnError(err, "botMsgRescan : createJob(objSubTypeJobRescanMsg)")
if err != nil {
return "Error scheduling the rescan for all msg", nil
} else {

13
def.go
View File

@ -1,6 +1,7 @@
package main
import (
tb "gopkg.in/tucnak/telebot.v2"
"regexp"
"time"
)
@ -36,6 +37,11 @@ type MessageParsingRule struct {
re *regexp.Regexp
}
type BotMsg struct {
To tb.Recipient
Text string
}
type Job struct {
ID64 int64
JobTypeID int32
@ -63,10 +69,7 @@ type JobPayloadGStock struct {
}
type JobPayloadRescanMsg struct {
MsgID64 int64 `json:"msg_id"`
}
type JobPayloadRescanAllMsg struct {
Query string `json:"query"`
}
const (
@ -103,7 +106,7 @@ const (
objSubTypeJobWithdrawal = 604
objSubTypeJobGStock = 605
objSubTypeJobRescanMsg = 606
objSubTypeJobRescanAllMsg = 607
objSubTypeJobMarkAsDone = 607
objSubTypeItemResource = 701
objSubTypeItemAlch = 702
objSubTypeItemMisc = 703

12
sql.go
View File

@ -236,11 +236,11 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageTime) + `, "time", "Time", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeJobPillage) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGStock) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobRescanMsg) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobRescanAllMsg) + `, "job_pillage", "Pillage job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobTribute) + `, "job_tribute", "Tribute job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobWithdrawal) + `, "job_withdraw", "Withdrawal job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobGStock) + `, "job_gstock", "GStock job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobRescanMsg) + `, "job_rescan_msg", "Rescan message job", ` + strconv.Itoa(objTypeJob) + `)
,(` + strconv.Itoa(objSubTypeJobMarkAsDone) + `, "job_mark_as_done", "Mark job as done 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) + `)
@ -1431,7 +1431,7 @@ func loadCurrentJobs() ([]Job, error) {
}
defer tx.Rollback()
stmt, err := tx.Prepare("SELECT o.id, o.obj_sub_type_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.status = ? AND j.schedule <= ? ORDER BY j.priority ASC LIMIT ? FOR UPDATE;")
stmt, err := tx.Prepare("SELECT o.id, o.obj_sub_type_id, j.payload FROM obj_job j, obj o WHERE j.obj_id = o.id AND j.status = ? AND j.schedule <= ? ORDER BY j.priority ASC, j.obj_id ASC LIMIT ? FOR UPDATE;")
logOnError(err, "loadCurrentJobs : prepare select statement")
rows, err := stmt.Query(objJobStatusNew, time.Now(), SQLJobSliceSize)

View File

@ -145,6 +145,9 @@ func SQLJobWorker(id int) {
logOnError(err, "SQLJobWorker["+strconv.Itoa(id)+"] : loadCurrentJobs")
if len(jobs) > 0 {
log.Printf("SQLJobWorker["+strconv.Itoa(id)+"] : %d jobs.\n", len(jobs))
}
for _, j := range jobs {
}
if len(jobs) < SQLJobSliceSize {
time.Sleep(100 * time.Millisecond)
@ -152,3 +155,7 @@ func SQLJobWorker(id int) {
}
log.Printf("SQLJobWorker[" + strconv.Itoa(id) + "] : Closing.")
}
/*
func BotMsgWorker(id int, botMsg <-chan
*/