Skip to content

Commit 8936edd

Browse files
committed
optimize: performance
1 parent 036690d commit 8936edd

File tree

9 files changed

+25
-21
lines changed

9 files changed

+25
-21
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/zbpctrl v1.6.0
1313
github.com/FloatTech/zbputils v1.7.1-0.20231017135158-7e6c839764eb
1414
github.com/disintegration/imaging v1.6.2
15-
github.com/fumiama/NanoBot v0.0.0-20231018063321-f6748029989a
15+
github.com/fumiama/NanoBot v0.0.0-20231018155514-da5cad685a28
1616
github.com/fumiama/go-base16384 v1.7.0
1717
github.com/fumiama/go-registry v0.2.6
1818
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+Jl
3636
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM=
3737
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
3838
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
39-
github.com/fumiama/NanoBot v0.0.0-20231018063321-f6748029989a h1:PvvehKtRzag51IqijFLeOOSXdqE9Ubok3th61hmuZQc=
40-
github.com/fumiama/NanoBot v0.0.0-20231018063321-f6748029989a/go.mod h1:uveUWnqIjAod3AI5XHlEuG41bMIVKwEDzLAjAxxHmfw=
39+
github.com/fumiama/NanoBot v0.0.0-20231018155514-da5cad685a28 h1:JTdPj+t8emfMILq4iasN5rcj8KskS9BNeCfNDxzRPC0=
40+
github.com/fumiama/NanoBot v0.0.0-20231018155514-da5cad685a28/go.mod h1:uveUWnqIjAod3AI5XHlEuG41bMIVKwEDzLAjAxxHmfw=
4141
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE=
4242
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
4343
github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo=
@@ -60,7 +60,6 @@ github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430 h1:XL4SnagpaVHYy
6060
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430/go.mod h1:lEaZsT4FRSqcjnQ5q8y+mkenkzR/r1D3BJmfdp0vqDg=
6161
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
6262
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
63-
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
6463
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
6564
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
6665
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ func main() {
128128

129129
nano.OnMessageCommandGroup([]string{"help", "帮助", "menu", "菜单"}, nano.OnlyToMe).SetBlock(true).
130130
Handle(func(ctx *nano.Ctx) {
131-
_, _ = ctx.SendPlainMessage(false, banner.Banner)
131+
_, _ = ctx.SendChain(nano.Text(banner.Banner))
132132
})
133133
nano.OnMessageFullMatch("查看nbp公告", nano.OnlyToMe, nano.AdminPermission).SetBlock(true).
134134
Handle(func(ctx *nano.Ctx) {
135-
_, _ = ctx.SendPlainMessage(false, strings.ReplaceAll(kanban.Kanban(), "\t", ""))
135+
_, _ = ctx.SendChain(nano.Text(strings.ReplaceAll(kanban.Kanban(), "\t", "")))
136136
})
137137
_ = nano.Run(process.GlobalInitMutex.Unlock, bot...)
138138
}

plugin/genshin/ys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ func init() {
9595
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
9696
return
9797
}
98-
b, err := imgfactory.ToBase64(img)
98+
b, err := imgfactory.ToBytes(img)
9999
if err != nil {
100100
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
101101
return
102102
}
103-
_, err = ctx.SendImage("base64://"+nano.BytesToString(b), true, func() string {
103+
_, err = ctx.SendImageBytes(b, true, func() string {
104104
if mode {
105105
return "恭喜你抽到了:\n" + str
106106
}

plugin/score/sign_in.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func init() {
6262
}
6363
sdb = initialize(engine.DataFolder() + "score.db")
6464
}()
65-
engine.OnMessageRegex("签到").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *nano.Ctx) {
65+
engine.OnMessageFullMatch("签到").Limit(ctxext.LimitByUser).SetBlock(true).Handle(func(ctx *nano.Ctx) {
6666
uid := ctx.Message.Author.ID
6767
if uid == "" {
6868
_, _ = ctx.SendPlainMessage(false, "ERROR: 未获取到用户uid")
@@ -152,7 +152,7 @@ func init() {
152152
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
153153
return
154154
}
155-
_, err = ctx.SendImage("base64://"+nano.BytesToString(data), false)
155+
_, err = ctx.SendImageBytes(data, false)
156156
if err != nil {
157157
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
158158
}

plugin/status/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,12 @@ func init() { // 插件主体
7272
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
7373
return
7474
}
75-
sendimg, err := imgfactory.ToBase64(img)
75+
sendimg, err := imgfactory.ToBytes(img)
7676
if err != nil {
7777
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
7878
return
7979
}
80-
if _, err := ctx.SendImage("base64://"+nano.BytesToString(sendimg), false); err != nil {
80+
if _, err := ctx.SendImageBytes(sendimg, false); err != nil {
8181
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
8282
}
8383
})

plugin/tarot/main.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/FloatTech/floatbox/file"
1313
"github.com/FloatTech/floatbox/process"
1414
"github.com/FloatTech/floatbox/web"
15+
"github.com/FloatTech/imgfactory"
1516
ctrl "github.com/FloatTech/zbpctrl"
1617

1718
"github.com/FloatTech/NanoBot-Plugin/utils/ctxext"
@@ -190,12 +191,17 @@ func init() {
190191
build.WriteString(strings.Join(majorArcanaName[14:22], " "))
191192
build.WriteString("\n小阿尔卡纳:\n[圣杯|星币|宝剑|权杖] [0-10|侍从|骑士|王后|国王]")
192193
txt := build.String()
193-
cardList, err := text.RenderToBase64(txt, text.FontFile, 420, 20)
194+
cardList, err := text.Render(txt, text.FontFile, 420, 20)
194195
if err != nil {
195196
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
196197
return
197198
}
198-
_, err = ctx.SendImage("base64://"+nano.BytesToString(cardList), false, "没有找到", match, "噢~")
199+
data, err := imgfactory.ToBytes(cardList)
200+
if err != nil {
201+
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
202+
return
203+
}
204+
_, err = ctx.SendImageBytes(data, false, "没有找到", match, "噢~")
199205
if err != nil {
200206
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
201207
}

plugin/wife/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package wife
33

44
import (
5-
"encoding/base64"
65
"encoding/json"
76
"os"
87
"strconv"
@@ -51,13 +50,13 @@ func init() {
5150
data, err := engine.GetLazyData("wives/"+card, true)
5251
card, _, _ = strings.Cut(card, ".")
5352
if err != nil {
54-
_, err = ctx.SendPlainMessage(false, "<@", uid, ">今天的二次元老婆是~【", card, "】哒\n【图片下载失败: ", err, "】")
53+
_, err = ctx.SendChain(nano.At(uid), nano.Text("今天的二次元老婆是~【", card, "】哒\n【图片下载失败: ", err, "】"))
5554
if err != nil {
5655
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
5756
}
5857
return
5958
}
60-
_, err = ctx.SendImage("base64://"+base64.StdEncoding.EncodeToString(data), false, "<@", uid, ">今天的二次元老婆是~【", card, "】哒")
59+
_, err = ctx.SendChain(nano.At(uid), nano.Text("今天的二次元老婆是~【", card, "】哒"), nano.ImageBytes(data))
6160
if err != nil {
6261
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
6362
}

plugin/wordle/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func init() {
132132
}
133133
game := newWordleGame(target)
134134
_, img, _ := game("")
135-
_, err = ctx.SendImage("base64://"+nano.BytesToString(img), true, "你有", class+1, "次机会猜出单词,单词长度为", class, ",请发送单词")
135+
_, err = ctx.SendImageBytes(img, true, "你有", class+1, "次机会猜出单词,单词长度为", class, ",请发送单词")
136136
if err != nil {
137137
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
138138
return
@@ -172,7 +172,7 @@ func init() {
172172
case win:
173173
tick.Stop()
174174
after.Stop()
175-
_, err := ctx.SendImage("base64://"+nano.BytesToString(img), true, "太棒了,你猜出来了!答案是: ", target, "(", tt, ")")
175+
_, err := ctx.SendImageBytes(img, true, "太棒了,你猜出来了!答案是: ", target, "(", tt, ")")
176176
if err != nil {
177177
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
178178
}
@@ -198,7 +198,7 @@ func init() {
198198
return
199199
}
200200
default:
201-
_, err := ctx.SendImage("base64://"+nano.BytesToString(img), true)
201+
_, err := ctx.SendImageBytes(img, true)
202202
if err != nil {
203203
_, _ = ctx.SendPlainMessage(false, "ERROR: ", err)
204204
return
@@ -262,7 +262,7 @@ func newWordleGame(target string) func(string) (bool, []byte, error) {
262262
}
263263
}
264264
}
265-
data, err = imgfactory.ToBase64(ctx.Image())
265+
data, err = imgfactory.ToBytes(ctx.Image())
266266
return
267267
}
268268
}

0 commit comments

Comments
 (0)