🎨 🔥 统一限速器

This commit is contained in:
fumiama
2022-02-08 14:46:35 +08:00
parent 259b29f6e3
commit a16bcda7da
28 changed files with 92 additions and 222 deletions

View File

@@ -6,23 +6,18 @@ import (
"fmt"
"io/ioutil"
"net/http"
"time"
"github.com/tidwall/gjson"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
control "github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
"github.com/FloatTech/zbputils/process"
"github.com/FloatTech/ZeroBot-Plugin/order"
)
var (
bucket = rate.NewManager(time.Minute, 20) // 接口回复
)
func tl(d string) ([]byte, error) {
url := "https://api.cloolc.club/fanyi?data=" + d
resp, err := http.Get(url)
@@ -47,12 +42,8 @@ func init() {
DisableOnDefault: false,
Help: "翻译\n" +
">TL 你好",
}).OnRegex(`^>TL\s(-.{1,10}? )?(.*)$`).SetBlock(true).
}).OnRegex(`^>TL\s(-.{1,10}? )?(.*)$`).SetBlock(true).Limit(ctxext.LimitByUser).
Handle(func(ctx *zero.Ctx) {
if !bucket.Load(ctx.Event.UserID).Acquire() {
// 频繁触发,不回复
return
}
msg := []string{ctx.State["regex_matched"].([]string)[2]}
rely, err := tl(msg[0])
if err != nil {