From 5e2547813776d8f790a3345bbd5791e0c8f7b6b0 Mon Sep 17 00:00:00 2001 From: shoopea Date: Thu, 16 Jan 2020 19:25:13 +0800 Subject: [PATCH] upd --- cron.go | 1 - main.go | 18 +----------------- obj.go | 25 ++++++++++++++++++++++++- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/cron.go b/cron.go index 95b5818..591e9e9 100644 --- a/cron.go +++ b/cron.go @@ -103,7 +103,6 @@ func cronSaveClients() { logOnError(err, "cronSaveClients : Marshal") pb := pretty.Pretty(b) - log.Printf("cronSaveClients :\n%s\n", string(pb)) err = ioutil.WriteFile("./clients_new.json", pb, 0644) logOnError(err, "cronSaveClients : WriteFile") diff --git a/main.go b/main.go index 7b73921..294d24f 100644 --- a/main.go +++ b/main.go @@ -86,23 +86,7 @@ func main() { initDB() } - initCache() - - if *initdb { - _, _ = addObjCastle(`🦌`, `Deerhorn`) - _, _ = addObjCastle(`🐉`, `Dragonscale`) - _, _ = addObjCastle(`🦅`, `Highnest`) - _, _ = addObjCastle(`🌑`, `Moonlight`) - _, _ = addObjCastle(`🥔`, `Potato`) - _, _ = addObjCastle(`🦈`, `Sharkteeth`) - _, _ = addObjCastle(`🐺`, `Wolfpack`) - _, _ = addObjCastle(`⛔`, `Unknown`) - _, _ = addObjGuild(``, `No Guild`) - } - - log.Println("Caching castles ..") - err = loadObjCastle() - logOnError(err, "initCache : caching castles") + initCache(*initdb) // Registering bot bot, err := tb.NewBot(tb.Settings{ diff --git a/obj.go b/obj.go index 129e63f..672c7d6 100644 --- a/obj.go +++ b/obj.go @@ -30,7 +30,7 @@ var ( muxObjJob sync.Mutex ) -func initCache() { +func initCache(initDB bool) { var err error log.Println("Caching obj_type ..") @@ -66,6 +66,29 @@ func initCache() { err = loadObjJob() logOnError(err, "initCache : caching jobs") + if initDB { + _, _ = addObjCastle(`🦌`, `Deerhorn`) + _, _ = addObjCastle(`🐉`, `Dragonscale`) + _, _ = addObjCastle(`🦅`, `Highnest`) + _, _ = addObjCastle(`🌑`, `Moonlight`) + _, _ = addObjCastle(`🥔`, `Potato`) + _, _ = addObjCastle(`🦈`, `Sharkteeth`) + _, _ = addObjCastle(`🐺`, `Wolfpack`) + _, _ = addObjCastle(`⛔`, `Unknown`) + _, _ = addObjGuild(``, `No Guild`) + } + + log.Println("Caching castles ..") + err = loadObjCastle() + logOnError(err, "initCache : caching castles") + + log.Println("Caching clients ..") + err = loadClients() + + if initDB { + + } + } func loadObjType() error {