🎨 改进代码结构

This commit is contained in:
Yiwen-Chan
2021-04-12 18:48:12 +08:00
parent 45a2808c13
commit f19721a683
7 changed files with 132 additions and 116 deletions

View File

@@ -1,15 +1,31 @@
package chat
import (
"math/rand"
"time"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
)
var poke = rate.NewManager(time.Minute*5, 8) // 戳一戳
func init() { // 插件主体
var NICKNAME = zero.BotConfig.NickName[0]
// 被喊名字
zero.OnFullMatchGroup(zero.BotConfig.NickName).SetBlock(false).FirstPriority().
Handle(func(ctx *zero.Ctx) {
time.Sleep(time.Second * 1)
ctx.SendChain(message.Text(
[]string{
NICKNAME + "在此,有何贵干~",
"(っ●ω●)っ在~",
"这里是" + NICKNAME + "(っ●ω●)っ",
NICKNAME + "不在呢~",
}[rand.Intn(4)],
))
})
// 戳一戳
zero.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).FirstPriority().
Handle(func(ctx *zero.Ctx) {
@@ -17,11 +33,11 @@ func init() { // 插件主体
case poke.Load(ctx.Event.UserID).AcquireN(3):
// 5分钟共8块命令牌 一次消耗3块命令牌
time.Sleep(time.Second * 1)
ctx.Send("请不要戳我 >_<")
ctx.SendChain(message.Text("请不要戳", NICKNAME, " >_<"))
case poke.Load(ctx.Event.UserID).Acquire():
// 5分钟共8块命令牌 一次消耗1块命令牌
time.Sleep(time.Second * 1)
ctx.Send("喂(#`O) 戳我干嘛!")
ctx.SendChain(message.Text("喂(#`O) 戳", NICKNAME, "干嘛!"))
default:
// 频繁触发,不回复
}