From 0dda861863c2b18eb7d86e3e0868c0138b1c288b Mon Sep 17 00:00:00 2001 From: Kanri Date: Wed, 6 Oct 2021 10:33:22 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=F0=9F=8E=A8=20=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=20fortune?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +++- plugin_fortune/fortune.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 150373a1..bcefee75 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,10 @@ zerobot [-d] [-g] qq1 qq2 qq3 ... - [x] 设置随机图片网址[url] - [x] 太涩了(撤回最近发的图) - [x] 评价图片(发送一张图片让bot评分) +- **每日运势** `github.com/FloatTech/ZeroBot-Plugin/plugin_fortune` + - [x] 运势 - **浅草寺求签** `github.com/FloatTech/ZeroBot-Plugin/plugin_omikuji` - - [x] 求签|运势|占卜 + - [x] 求签|占卜 - **bilibili** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_bilibili"` - [x] >vup info [名字|uid] - [x] >user info [名字|uid] diff --git a/plugin_fortune/fortune.go b/plugin_fortune/fortune.go index 6bada185..a9565fe1 100644 --- a/plugin_fortune/fortune.go +++ b/plugin_fortune/fortune.go @@ -7,7 +7,6 @@ import ( "encoding/base64" "encoding/json" "errors" - "fmt" "image/jpeg" "io" "io/ioutil" @@ -29,6 +28,8 @@ import ( var ( // 底图缓存位置 base = "data/fortune/" + // 素材下载网站 + site = "https://pan.dihe.moe/fortune/" // int64 群号 string 底图类型 // 底图类型列表:车万 DC4 爱因斯坦 星空列车 樱云之恋 富婆妹 李清歌 // 公主连结 原神 明日方舟 碧蓝航线 碧蓝幻想 战双 阴阳师 @@ -40,7 +41,7 @@ var ( func init() { // 插件主体 - control.Register("runcode", &control.Options{ + control.Register("fortune", &control.Options{ DisableOnDefault: false, Help: "每日运势: \n" + "- 运势", @@ -49,7 +50,7 @@ func init() { // 检查签文文件是否存在 if _, err := os.Stat(base + "运势签文.json"); err != nil && !os.IsExist(err) { ctx.SendChain(message.Text("正在下载签文文件,请稍后...")) - _, err := download("https://pan.dihe.moe/fortune/运势签文.json", base) + _, err := download(site+"运势签文.json", base) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -59,7 +60,7 @@ func init() { // 检查字体文件是否存在 if _, err := os.Stat(base + "sakura.ttf"); err != nil && !os.IsExist(err) { ctx.SendChain(message.Text("正在下载字体文件,请稍后...")) - _, err := download("https://pan.dihe.moe/fortune/sakura.ttf", base) + _, err := download(site+"sakura.ttf", base) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -76,7 +77,7 @@ func init() { // 检查背景图片是否存在 if _, err := os.Stat(base + kind); err != nil && !os.IsExist(err) { ctx.SendChain(message.Text("正在下载背景图片,请稍后...")) - file, err := download("https://pan.dihe.moe/fortune/"+kind+".zip", base) + file, err := download(site+kind+".zip", base) if err != nil { ctx.SendChain(message.Text("ERROR: ", err)) return @@ -139,8 +140,6 @@ func download(link, dest string) (string, error) { length, _ := strconv.Atoi(resp.Header.Get("Content-Length")) data, _ := ioutil.ReadAll(resp.Body) if length > len(data) { - fmt.Println(len(data)) - fmt.Println(length) return "", errors.New("download not complete") } // 获取文件名 @@ -301,7 +300,7 @@ func draw(background, title, text string) ([]byte, error) { } } } - // 保存 + // 转成 base64 buffer := new(bytes.Buffer) encoder := base64.NewEncoder(base64.StdEncoding, buffer) var opt jpeg.Options @@ -310,5 +309,6 @@ func draw(background, title, text string) ([]byte, error) { if err != nil { return nil, err } + encoder.Close() return buffer.Bytes(), nil }