diff --git a/main.go b/main.go index b82f3145..9f4d6819 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,8 @@ import ( zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/driver" "github.com/wdvxdr1123/ZeroBot/message" + + "github.com/FloatTech/ZeroBot-Plugin/order" ) var ( @@ -156,6 +158,7 @@ func getKanban() string { } func main() { + order.Wait() printBanner() // 帮助 zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true). diff --git a/order/init.go b/order/init.go new file mode 100644 index 00000000..2a2bde3f --- /dev/null +++ b/order/init.go @@ -0,0 +1,14 @@ +package order + +import "sync" + +var wg sync.WaitGroup + +// DoneOnExit 在退出时执行 Done +func DoneOnExit() func() { + wg.Add(1) + return wg.Done +} + +// Wait 等待 +var Wait = wg.Wait diff --git a/plugin_bilibili_push/data.go b/plugin_bilibili_push/data.go index e69be501..caa38c18 100644 --- a/plugin_bilibili_push/data.go +++ b/plugin_bilibili_push/data.go @@ -5,6 +5,8 @@ import ( "github.com/FloatTech/zbputils/process" log "github.com/sirupsen/logrus" + + "github.com/FloatTech/ZeroBot-Plugin/order" ) const ( @@ -19,6 +21,7 @@ var bdb *bilibilipushdb // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) os.RemoveAll(cachePath) diff --git a/plugin_book_review/data.go b/plugin_book_review/data.go index dd4feee2..a0ce02e2 100644 --- a/plugin_book_review/data.go +++ b/plugin_book_review/data.go @@ -5,6 +5,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -18,6 +19,7 @@ var db = &sql.Sqlite{DBPath: dbfile} // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() // os.RemoveAll(dbpath) _ = os.MkdirAll(dbpath, 0755) diff --git a/plugin_chat/data.go b/plugin_chat/data.go index 9237b946..e64de1d9 100644 --- a/plugin_chat/data.go +++ b/plugin_chat/data.go @@ -6,6 +6,7 @@ import ( "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" ) @@ -14,6 +15,7 @@ type kimo = map[string]*[]string func initChatList(postinit func()) { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) data, err := file.GetLazyData(dbfile, true, true) diff --git a/plugin_chouxianghua/data.go b/plugin_chouxianghua/data.go index 3ae0d0c7..585f1725 100644 --- a/plugin_chouxianghua/data.go +++ b/plugin_chouxianghua/data.go @@ -5,6 +5,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -20,6 +21,7 @@ var db = &sql.Sqlite{DBPath: dbfile} // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() // os.RemoveAll(dbpath) _ = os.MkdirAll(dbpath, 0755) diff --git a/plugin_cpstory/data.go b/plugin_cpstory/data.go index b212e52d..4ab02866 100644 --- a/plugin_cpstory/data.go +++ b/plugin_cpstory/data.go @@ -5,6 +5,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -20,6 +21,7 @@ var db = &sql.Sqlite{DBPath: dbfile} // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() // os.RemoveAll(dbpath) _ = os.MkdirAll(dbpath, 0755) diff --git a/plugin_curse/data.go b/plugin_curse/data.go index a9ad2992..cb56f70b 100644 --- a/plugin_curse/data.go +++ b/plugin_curse/data.go @@ -5,6 +5,7 @@ import ( "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -22,6 +23,7 @@ var ( // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) _, err := file.GetLazyData(dbfile, false, true) diff --git a/plugin_diana/data/text.go b/plugin_diana/data/text.go index 04c04443..76c5dfbf 100644 --- a/plugin_diana/data/text.go +++ b/plugin_diana/data/text.go @@ -9,6 +9,7 @@ import ( log "github.com/sirupsen/logrus" "github.com/wdvxdr1123/ZeroBot/utils/helper" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -28,6 +29,7 @@ type text struct { func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() err := os.MkdirAll(datapath, 0755) if err != nil { diff --git a/plugin_funny/data.go b/plugin_funny/data.go index cb07ad57..ead19e5f 100644 --- a/plugin_funny/data.go +++ b/plugin_funny/data.go @@ -5,6 +5,7 @@ import ( "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" ) @@ -22,6 +23,7 @@ const ( // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) _, err := file.GetLazyData(dbfile, false, true) diff --git a/plugin_manager/manager.go b/plugin_manager/manager.go index 2c625bc4..4a6ac6a8 100644 --- a/plugin_manager/manager.go +++ b/plugin_manager/manager.go @@ -68,6 +68,7 @@ var engine = control.Register("manager", order.PrioManager, &control.Options{ func init() { // 插件主体 go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(datapath, 0755) clock = timer.NewClock(db) diff --git a/plugin_nativesetu/data.go b/plugin_nativesetu/data.go index 76376dd7..c680e73a 100644 --- a/plugin_nativesetu/data.go +++ b/plugin_nativesetu/data.go @@ -13,6 +13,7 @@ import ( "github.com/wdvxdr1123/ZeroBot/utils/helper" _ "golang.org/x/image/webp" // import webp decoding + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -29,6 +30,7 @@ var ns = &nsetu{db: &sql.Sqlite{DBPath: dbfile}} func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() err := os.MkdirAll(datapath, 0755) if err != nil { diff --git a/plugin_omikuji/data.go b/plugin_omikuji/data.go index 3b782223..c66e1890 100644 --- a/plugin_omikuji/data.go +++ b/plugin_omikuji/data.go @@ -5,6 +5,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/sql" @@ -19,11 +20,7 @@ var db = &sql.Sqlite{DBPath: dbfile} func init() { go func() { - defer func() { - if err := recover(); err != nil { - log.Println(err) - } - }() + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) _, _ = file.GetLazyData(dbfile, false, true) diff --git a/plugin_reborn/load.go b/plugin_reborn/load.go index b0cb2461..f6a12e80 100644 --- a/plugin_reborn/load.go +++ b/plugin_reborn/load.go @@ -7,6 +7,7 @@ import ( wr "github.com/mroth/weightedrand" log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" ) @@ -27,6 +28,7 @@ var ( func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() err := os.MkdirAll(datapath, 0755) if err != nil { diff --git a/plugin_score/data.go b/plugin_score/data.go index 8fae0c8f..00c94318 100644 --- a/plugin_score/data.go +++ b/plugin_score/data.go @@ -5,6 +5,7 @@ import ( log "github.com/sirupsen/logrus" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" "github.com/FloatTech/zbputils/txt2img" @@ -22,6 +23,7 @@ var sdb *scoredb // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _, err := file.GetLazyData(txt2img.BoldFontFile, false, true) if err != nil { diff --git a/plugin_setutime/setu_geter.go b/plugin_setutime/setu_geter.go index 807429ce..9e53e1b8 100644 --- a/plugin_setutime/setu_geter.go +++ b/plugin_setutime/setu_geter.go @@ -55,6 +55,7 @@ func init() { // 插件主体 _ = os.MkdirAll("data/SetuTime", 0755) go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() // 如果数据库不存在则下载 _, _ = fileutil.GetLazyData(pool.db.DBPath, false, false) diff --git a/plugin_sleep_manage/data.go b/plugin_sleep_manage/data.go index 82b82f1b..9c96e96c 100644 --- a/plugin_sleep_manage/data.go +++ b/plugin_sleep_manage/data.go @@ -3,20 +3,15 @@ package sleepmanage import ( "os" - log "github.com/sirupsen/logrus" - "github.com/FloatTech/zbputils/process" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/ZeroBot-Plugin/plugin_sleep_manage/model" ) func init() { go func() { - defer func() { - if err := recover(); err != nil { - log.Println(err) - } - }() + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) model.Initialize(dbfile) diff --git a/plugin_vtb_quotation/cron.go b/plugin_vtb_quotation/cron.go index b0c3f721..aceaeb2b 100644 --- a/plugin_vtb_quotation/cron.go +++ b/plugin_vtb_quotation/cron.go @@ -6,11 +6,13 @@ import ( "github.com/FloatTech/zbputils/process" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/ZeroBot-Plugin/plugin_vtb_quotation/model" ) func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() log.Println("[vtb/cron] 开启vtb数据库日常更新") vtbDaily() diff --git a/plugin_vtb_quotation/data.go b/plugin_vtb_quotation/data.go index e4fc804e..a98227d7 100644 --- a/plugin_vtb_quotation/data.go +++ b/plugin_vtb_quotation/data.go @@ -3,6 +3,7 @@ package vtbquotation import ( "os" + "github.com/FloatTech/ZeroBot-Plugin/order" "github.com/FloatTech/zbputils/file" "github.com/FloatTech/zbputils/process" ) @@ -10,6 +11,7 @@ import ( // 加载数据库 func init() { go func() { + defer order.DoneOnExit()() process.SleepAbout1sTo2s() _ = os.MkdirAll(dbpath, 0755) _, _ = file.GetLazyData(dbfile, false, false)