This commit is contained in:
shoopea 2020-10-11 12:53:15 +02:00
parent 9077f64268
commit 9cf92260e5
3 changed files with 79 additions and 1 deletions

31
bot.go
View File

@ -51,6 +51,7 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/vault_item", botVaultItem) b.Handle("/vault_item", botVaultItem)
b.Handle("/restart_job", botRestartJob) b.Handle("/restart_job", botRestartJob)
b.Handle("/cleanup_job", botCleanupJob)
b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost) b.Handle(tb.OnChannelPost, botChannelPost)
@ -1680,6 +1681,36 @@ func botTimer(m *tb.Message) {
return return
} }
func botCleanupJob(m *tb.Message) {
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
clt.Mux.Unlock()
c := TGCommand{
Type: commandReplyMsg,
Text: "Cleanup started",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
cleanupJobData()
return
}
func botRestartJob(m *tb.Message) { func botRestartJob(m *tb.Message) {
if !m.Private() { if !m.Private() {
return return

View File

@ -17,6 +17,7 @@ func startCron() *cron.Cron {
c := cron.New(cron.WithLocation(time.UTC)) c := cron.New(cron.WithLocation(time.UTC))
c.AddFunc("58 6,14,22 * * *", cronSetDef) c.AddFunc("58 6,14,22 * * *", cronSetDef)
c.AddFunc("00 0 * * *", cronUpdateAngryBirbs) c.AddFunc("00 0 * * *", cronUpdateAngryBirbs)
c.AddFunc("01 0 * * *", cronScrubData)
c.AddFunc("02 1,3,5,9,11,13,17,19,21 * * *", cronGetHammerTime) c.AddFunc("02 1,3,5,9,11,13,17,19,21 * * *", cronGetHammerTime)
c.AddFunc("12 7,15,23 * * *", cronGetHammerTime) c.AddFunc("12 7,15,23 * * *", cronGetHammerTime)
c.AddFunc("13 3,7,11,15,19,23 * * *", cronTribute) c.AddFunc("13 3,7,11,15,19,23 * * *", cronTribute)
@ -50,6 +51,10 @@ func cronUpdateAngryBirbs() {
return return
} }
func cronScrubData() {
cleanupJobData()
}
func cronSendWarReport() { func cronSendWarReport() {
muxClients.RLock() muxClients.RLock()
for _, c := range clients { for _, c := range clients {

44
sql.go
View File

@ -812,7 +812,7 @@ func insertMsgTributesStats(m *ChatWarsMessageTributesStatsAck) error {
} }
stmt, err := db.Prepare(`INSERT INTO obj_tribute (tg_user_id, item_id, quantity, exp, date) stmt, err := db.Prepare(`INSERT INTO obj_tribute (tg_user_id, item_id, quantity, exp, date)
VALUES (?, ?, ?, ?, ?);`) VALUES (?, ?, ?, ?, ?);`)
logOnError(err, "insertMsgTributesStats : Prepare") logOnError(err, "insertMsgTributesStats : Prepare")
if err != nil { if err != nil {
return err return err
@ -959,3 +959,45 @@ func getSQLListID64(q string) []int64 {
return ids return ids
} }
func cleanupJobData() {
var jobID int64
jobStmt, err := db.Prepare(`SELECT o.id FROM obj o WHERE o.obj_type_id = ?;`)
logOnError(err, "cleanupJobData : prepare jobStmt")
if err != nil {
jobStmt.Close()
return
}
jobs, err := jobStmt.Query(r)
err = stmt.QueryRow(jobTypeID64).Scan(&cacheObjType[`job`])
logOnError(err, "cleanupJobData : query jobStmt")
if err != nil {
jobStmt.Close()
return
}
for jobs.Next() {
err = rows.Scan(&jobID)
logOnError(err, "cleanupJobData : scan jobStmt")
if err != nil {
return
}
log.Printf("cleanupJobData : JobID : %d\n", jobID)
}
/*
for _, id := range ids {
job, err := db.Query(`SELECT oj.is_done FROM obj_job oj WHERE oj.obj_id = ?;`)
if err != nil {
return err
}
defer jobs.Close()
stmt, err := db.Prepare(`DELETE FROM obj WHERE id = ?`)
if err != nil {
return err
}
defer stmt.Close()
}
*/
}