forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
117 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,17 @@ | ||
package vtbquotation | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"os" | ||
|
||
log "github.com/sirupsen/logrus" | ||
|
||
"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() { | ||
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) | ||
} | ||
_, _ = file.GetLazyData(dbfile, false, true) | ||
}() | ||
} |
Oops, something went wrong.