mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
🐛 hyaku
This commit is contained in:
parent
a2ada0b67e
commit
4b288a59b9
2
data
2
data
@ -1 +1 @@
|
||||
Subproject commit 5ce4b48c12ea42fc999823ea119b69a9d5dfa451
|
||||
Subproject commit aa8f7eb30a360babcbd7d658d4bebc4643d478df
|
||||
@ -4,6 +4,7 @@ package hyaku
|
||||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"os"
|
||||
"reflect"
|
||||
@ -12,6 +13,7 @@ import (
|
||||
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/floatbox/web"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
@ -61,16 +63,25 @@ func init() {
|
||||
})
|
||||
csvfile := engine.DataFolder() + "hyaku.csv"
|
||||
go func() {
|
||||
var f *os.File
|
||||
if file.IsNotExist(csvfile) {
|
||||
err := file.DownloadTo(bed+"小倉百人一首.csv", csvfile, true)
|
||||
data, err := web.RequestDataWith(web.NewTLS12Client(), bed+"小倉百人一首.csv", "GET", "gitcode.net", web.RandUA())
|
||||
if err != nil {
|
||||
_ = os.Remove(csvfile)
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
f, err := os.Open(csvfile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
f, err = os.Create(csvfile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
_, _ = f.Write(data)
|
||||
_, _ = f.Seek(0, io.SeekStart)
|
||||
} else {
|
||||
var err error
|
||||
f, err = os.Open(csvfile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
records, err := csv.NewReader(f).ReadAll()
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user