From 12f96bb95cdbe85148fdd12175b90798227f5257 Mon Sep 17 00:00:00 2001 From: fumiama Date: Mon, 22 Nov 2021 22:33:29 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20=E4=BF=AE=E5=A4=8D=20vt?= =?UTF-8?q?b=20panic=20=E5=88=A4=E6=96=AD=E5=A4=B1=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin_vtb_quotation/data.go | 41 ++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/plugin_vtb_quotation/data.go b/plugin_vtb_quotation/data.go index 703aa3bb..1821440a 100644 --- a/plugin_vtb_quotation/data.go +++ b/plugin_vtb_quotation/data.go @@ -7,31 +7,36 @@ import ( "os" "github.com/FloatTech/ZeroBot-Plugin/utils/file" + "github.com/FloatTech/ZeroBot-Plugin/utils/process" ) const pburl = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/" + dbfile // 加载数据库 func init() { - _ = os.MkdirAll(dbpath, 0755) - if !file.IsExist(dbfile) { // 如果没有数据库,则从 url 下载 - f, err := os.Create(dbfile) - if err != nil { - panic(err) - } - defer f.Close() - resp, err := http.Get(pburl) - if err == nil { - defer resp.Body.Close() - if resp.ContentLength > 0 { - log.Printf("[vtb]从镜像下载数据库%d字节...", resp.ContentLength) - data, err := io.ReadAll(resp.Body) - if err == nil && len(data) > 0 { - _, _ = f.Write(data) - } + go func() { + process.SleepAbout1sTo2s() + _ = os.MkdirAll(dbpath, 0755) + if !file.IsExist(dbfile) { // 如果没有数据库,则从 url 下载 + f, err := os.Create(dbfile) + if err != nil { panic(err) } + defer f.Close() + resp, err := http.Get(pburl) + if err == nil { + defer resp.Body.Close() + if resp.ContentLength > 0 { + log.Printf("[vtb]从镜像下载数据库%d字节...", resp.ContentLength) + data, err := io.ReadAll(resp.Body) + if err == nil && len(data) > 0 { + _, _ = f.Write(data) + return + } + panic(err) + } + } + panic(err) } - panic(err) - } + }() }