Skip to content

Commit

Permalink
✨ acgimage 增加限速器
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 31, 2021
1 parent 3084d4a commit ba9eb9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin_acgimage/classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (
"net/url"
"strconv"
"strings"
"time"

"github.com/FloatTech/AnimeAPI/classify"
"github.com/FloatTech/AnimeAPI/picture"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"

"github.com/FloatTech/ZeroBot-Plugin/control"
Expand All @@ -27,6 +29,7 @@ var (
randapi = "&loli=true&r18=true"
msgof = make(map[int64]int64)
block = false
limit = rate.NewManager(time.Minute, 1)
)

func init() { // 插件主体
Expand Down Expand Up @@ -54,7 +57,7 @@ func init() { // 插件主体
// 有保护的随机图片
engine.OnFullMatch("随机图片", zero.OnlyGroup).SetBlock(true).SetPriority(24).
Handle(func(ctx *zero.Ctx) {
if classify.CanVisit(5) {
if classify.CanVisit(5) && limit.Load(ctx.Event.UserID).Acquire() {
go func() {
class, lastvisit, dhash, comment := classify.Classify(randapi, false)
replyClass(ctx, dhash, class, false, lastvisit, comment)
Expand Down
2 changes: 2 additions & 0 deletions plugin_manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
"- 在MM月[每周|周几]的hh点mm分时(用http://url)提醒大家XXX\n" +
"- 取消在MM月dd日的hh点mm分的提醒\n" +
"- 取消在MM月[每周|周几]的hh点mm分的提醒\n" +
"- [x] 在\"cron\"时(用[url])提醒大家[xxx]\n" +
"- [x] 取消在\"cron\"的提醒\n" +
"- 列出所有提醒\n" +
"- 翻牌\n" +
"- 设置欢迎语XXX\n" +
Expand Down

0 comments on commit ba9eb9c

Please sign in to comment.