forked from FloatTech/ZeroBot-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tl.go
28 lines (26 loc) · 809 Bytes
/
tl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Package translation 翻译
package translation
import (
"github.com/FloatTech/AnimeAPI/tl"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
control.Register("translation", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "单词翻译",
Help: ">TL [好|good]",
}).OnRegex(`^>TL\s(-.{1,10}? )?(.*)$`).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
msg := []string{ctx.State["regex_matched"].([]string)[2]}
data, err := tl.Translate(msg[0])
if err != nil {
ctx.SendChain(message.Text("ERROR: ", data))
return
}
ctx.SendChain(message.Text(data))
})
}