-
Notifications
You must be signed in to change notification settings - Fork 2k
/
chat.go
106 lines (102 loc) · 3.19 KB
/
chat.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Package chat 对话插件
package chat
import (
"math/rand"
"strconv"
"time"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
)
var (
poke = rate.NewManager[int64](time.Minute*5, 8) // 戳一戳
engine = control.Register("chat", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "chat\n- [BOT名字]\n- [戳一戳BOT]\n- 空调开\n- 空调关\n- 群温度\n- 设置温度[正整数]",
})
)
func init() { // 插件主体
// 被喊名字
engine.OnFullMatch("", zero.OnlyToMe).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
var nickname = zero.BotConfig.NickName[0]
time.Sleep(time.Second * 1)
ctx.SendChain(message.Text(
[]string{
nickname + "在此,有何贵干~",
"(っ●ω●)っ在~",
"这里是" + nickname + "(っ●ω●)っ",
nickname + "不在呢~",
}[rand.Intn(4)],
))
})
// 戳一戳
engine.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).
Handle(func(ctx *zero.Ctx) {
var nickname = zero.BotConfig.NickName[0]
switch {
case poke.Load(ctx.Event.GroupID).AcquireN(3):
// 5分钟共8块命令牌 一次消耗3块命令牌
time.Sleep(time.Second * 1)
ctx.SendChain(message.Text("请不要戳", nickname, " >_<"))
case poke.Load(ctx.Event.GroupID).Acquire():
// 5分钟共8块命令牌 一次消耗1块命令牌
time.Sleep(time.Second * 1)
ctx.SendChain(message.Text("喂(#`O′) 戳", nickname, "干嘛!"))
default:
// 频繁触发,不回复
}
})
// 群空调
var AirConditTemp = map[int64]int{}
var AirConditSwitch = map[int64]bool{}
engine.OnFullMatch("空调开").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
AirConditSwitch[ctx.Event.GroupID] = true
ctx.SendChain(message.Text("❄️哔~"))
})
engine.OnFullMatch("空调关").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
AirConditSwitch[ctx.Event.GroupID] = false
delete(AirConditTemp, ctx.Event.GroupID)
ctx.SendChain(message.Text("💤哔~"))
})
engine.OnRegex(`设置温度(\d+)`).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
AirConditTemp[ctx.Event.GroupID] = 26
}
if AirConditSwitch[ctx.Event.GroupID] {
temp := ctx.State["regex_matched"].([]string)[1]
AirConditTemp[ctx.Event.GroupID], _ = strconv.Atoi(temp)
ctx.SendChain(message.Text(
"❄️风速中", "\n",
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
))
} else {
ctx.SendChain(message.Text(
"💤", "\n",
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
))
}
})
engine.OnFullMatch(`群温度`).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
AirConditTemp[ctx.Event.GroupID] = 26
}
if AirConditSwitch[ctx.Event.GroupID] {
ctx.SendChain(message.Text(
"❄️风速中", "\n",
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
))
} else {
ctx.SendChain(message.Text(
"💤", "\n",
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
))
}
})
}