From 9cf92260e5c2b78012f82d68c8279bb9503582a4 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 11 Oct 2020 12:53:15 +0200 Subject: [PATCH] test --- bot.go | 31 +++++++++++++++++++++++++++++++ cron.go | 5 +++++ sql.go | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/bot.go b/bot.go index dca7cd8..37a6e91 100644 --- a/bot.go +++ b/bot.go @@ -51,6 +51,7 @@ func BotHandlers(b *tb.Bot) { b.Handle("/vault_item", botVaultItem) b.Handle("/restart_job", botRestartJob) + b.Handle("/cleanup_job", botCleanupJob) b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnChannelPost, botChannelPost) @@ -1680,6 +1681,36 @@ func botTimer(m *tb.Message) { 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) { if !m.Private() { return diff --git a/cron.go b/cron.go index 7b9a8c4..111bb6e 100644 --- a/cron.go +++ b/cron.go @@ -17,6 +17,7 @@ func startCron() *cron.Cron { c := cron.New(cron.WithLocation(time.UTC)) c.AddFunc("58 6,14,22 * * *", cronSetDef) 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("12 7,15,23 * * *", cronGetHammerTime) c.AddFunc("13 3,7,11,15,19,23 * * *", cronTribute) @@ -50,6 +51,10 @@ func cronUpdateAngryBirbs() { return } +func cronScrubData() { + cleanupJobData() +} + func cronSendWarReport() { muxClients.RLock() for _, c := range clients { diff --git a/sql.go b/sql.go index de7b45c..2080e51 100644 --- a/sql.go +++ b/sql.go @@ -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) - VALUES (?, ?, ?, ?, ?);`) + VALUES (?, ?, ?, ?, ?);`) logOnError(err, "insertMsgTributesStats : Prepare") if err != nil { return err @@ -959,3 +959,45 @@ func getSQLListID64(q string) []int64 { 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() + } + */ +}