Skip to content

Commit 793cac0

Browse files
guohuiyuanGuohuiyuan
andauthored
新增统计睡眠时间和添加协程里的异常捕获 (#84)
* fix:捕获协程异常 * feat:添加睡眠时间 * feat:添加睡眠管理功能 * fix:修改对标时间 * fix:修改注释函数名,使用一个时间 * feat:让大家能够更加清楚的看到每一个功能 * feat:把群管放在control,增加退群信息 * fix:不会recover * fix:原本的正则限制机器人回复回复的消息,故去掉正则 * fix:添加服务详情,整理manager * feat:chat进control Co-authored-by: Guohuiyuan <[email protected]>
1 parent d0d0760 commit 793cac0

File tree

15 files changed

+339
-77
lines changed

15 files changed

+339
-77
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ zerobot -h -t token -u url [-d|w] [-g 监听地址:端口] qq1 qq2 qq3 ...
6868
- [x] 修改头衔[@xxx][xxx]
6969
- [x] 申请头衔[xxx]
7070
- [x] 踢出群聊[@xxx]
71-
- [x] 退出群聊[群号]
71+
- [x] 退出群聊[群号]@Bot
7272
- [x] *入群欢迎
7373
- [x] *退群通知
7474
- [x] 设置欢迎语[欢迎~]

control/rule.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,42 @@ func init() {
309309
})
310310
ctx.SendChain(message.Text(msg))
311311
})
312+
313+
zero.OnCommandGroup([]string{"服务详情", "service_detail"}, zero.OnlyGroup).
314+
Handle(func(ctx *zero.Ctx) {
315+
var m message.Message
316+
m = append(m,
317+
message.CustomNode(
318+
ctx.Event.Sender.NickName,
319+
ctx.Event.UserID,
320+
"---服务详情---",
321+
))
322+
i := 0
323+
ForEach(func(key string, manager *Control) bool {
324+
service, _ := Lookup(key)
325+
help := service.options.Help
326+
i++
327+
msg := strconv.Itoa(i) + `: `
328+
if manager.IsEnabledIn(ctx.Event.GroupID) {
329+
msg += "●" + key
330+
} else {
331+
msg += "○" + key
332+
}
333+
msg += "\n" + help
334+
m = append(m,
335+
message.CustomNode(
336+
ctx.Event.Sender.NickName,
337+
ctx.Event.UserID,
338+
msg,
339+
))
340+
return true
341+
})
342+
343+
ctx.SendGroupForwardMessage(
344+
ctx.Event.GroupID,
345+
m,
346+
)
347+
})
312348
}
313349
}
314350
mu.Unlock()

main.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_qingyunke" // 青云客
1919

2020
// 实用类
21-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_b14" // base16384加解密
22-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_github" // 搜索GitHub仓库
23-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_manager" // 群管
24-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh" // 拼音首字母缩写释义工具
25-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode" // 在线运行代码
26-
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 翻译
21+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_b14" // base16384加解密
22+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_github" // 搜索GitHub仓库
23+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_manager" // 群管
24+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh" // 拼音首字母缩写释义工具
25+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_runcode" // 在线运行代码
26+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_sleep_manage" // 统计睡眠时间
27+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_translation" // 翻译
2728

2829
// 娱乐类
2930
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin_wtf" // 鬼东西
@@ -120,6 +121,7 @@ func main() {
120121
// 帮助
121122
zero.OnFullMatchGroup([]string{"/help", ".help", "菜单"}, zero.OnlyToMe).SetBlock(true).FirstPriority().
122123
Handle(func(ctx *zero.Ctx) {
124+
ctx.SendChain(message.Text("可发送\"/服务详情\"等指令,查看bot功能"))
123125
ctx.SendChain(message.Text(banner))
124126
})
125127
zero.RunAndBlock(

plugin_atri/atri.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,21 @@ const (
2020
// 服务名
2121
servicename = "atri"
2222
// ATRI 所有命令的优先级
23-
prio = 2
23+
prio = 5
2424
// ATRI 表情的 codechina 镜像
2525
res = "https://codechina.csdn.net/u011570312/ZeroBot-Plugin/-/raw/master/plugin_atri/"
2626
)
2727

2828
func init() { // 插件主体
29-
engine := control.Register(servicename, &control.Options{})
29+
engine := control.Register(servicename, &control.Options{
30+
DisableOnDefault: false,
31+
Help: "本插件基于 ATRI ,为 Golang 移植版\n" +
32+
"- ATRI醒醒\n- ATRI睡吧\n- 萝卜子\n- 喜欢|爱你|爱|suki|daisuki|すき|好き|贴贴|老婆|亲一个|mua\n" +
33+
"- 草你妈|操你妈|脑瘫|废柴|fw|废物|战斗|爬|爪巴|sb|SB|傻B\n- 早安|早哇|早上好|ohayo|哦哈哟|お早う|早好|早|早早早\n" +
34+
"- 中午好|午安|午好\n- 晚安|oyasuminasai|おやすみなさい|晚好|晚上好\n- 高性能|太棒了|すごい|sugoi|斯国一|よかった\n" +
35+
"- 没事|没关系|大丈夫|还好|不要紧|没出大问题|没伤到哪\n- 好吗|是吗|行不行|能不能|可不可以\n- 啊这\n- 我好了\n- ?|?|¿\n" +
36+
"- 离谱\n- 答应我",
37+
})
3038
zero.OnFullMatch("ATRI醒醒", zero.AdminPermission).SetBlock(true).SetPriority(prio).
3139
Handle(func(ctx *zero.Ctx) {
3240
c, ok := control.Lookup(servicename)
@@ -65,7 +73,7 @@ func init() { // 插件主体
6573
process.SleepAbout1sTo2s()
6674
ctx.SendChain(randImage("FN.jpg", "WQ.jpg", "WQ1.jpg"))
6775
})
68-
engine.OnFullMatchGroup([]string{"早安", "早哇", "早上好", "ohayo", "哦哈哟", "お早う", "早好", "早"}).SetBlock(true).SetPriority(prio).
76+
engine.OnFullMatchGroup([]string{"早安", "早哇", "早上好", "ohayo", "哦哈哟", "お早う", "早好", "早", "早早早"}).SetBlock(true).SetPriority(prio).
6977
Handle(func(ctx *zero.Ctx) {
7078
now := time.Now().Hour()
7179
process.SleepAbout1sTo2s()

plugin_chat/chat.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
package chat
33

44
import (
5+
"github.com/FloatTech/ZeroBot-Plugin/control"
56
"math/rand"
67
"strconv"
78
"time"
@@ -13,9 +14,14 @@ import (
1314

1415
var poke = rate.NewManager(time.Minute*5, 8) // 戳一戳
1516

17+
var engine = control.Register("chat", &control.Options{
18+
DisableOnDefault: false,
19+
Help: "chat\n- [BOT名字]\n- [戳一戳BOT]\n- 空调开\n- 空调关\n- 群温度\n- 设置温度[正整数]",
20+
})
21+
1622
func init() { // 插件主体
1723
// 被喊名字
18-
zero.OnFullMatch("", zero.OnlyToMe).SetBlock(false).FirstPriority().
24+
engine.OnFullMatch("", zero.OnlyToMe).SetBlock(true).FirstPriority().
1925
Handle(func(ctx *zero.Ctx) {
2026
var nickname = zero.BotConfig.NickName[0]
2127
time.Sleep(time.Second * 1)
@@ -29,7 +35,7 @@ func init() { // 插件主体
2935
))
3036
})
3137
// 戳一戳
32-
zero.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).FirstPriority().
38+
engine.On("notice/notify/poke", zero.OnlyToMe).SetBlock(false).FirstPriority().
3339
Handle(func(ctx *zero.Ctx) {
3440
var nickname = zero.BotConfig.NickName[0]
3541
switch {
@@ -48,18 +54,18 @@ func init() { // 插件主体
4854
// 群空调
4955
var AirConditTemp = map[int64]int{}
5056
var AirConditSwitch = map[int64]bool{}
51-
zero.OnFullMatch("空调开").SetBlock(true).FirstPriority().
57+
engine.OnFullMatch("空调开").SetBlock(true).FirstPriority().
5258
Handle(func(ctx *zero.Ctx) {
5359
AirConditSwitch[ctx.Event.GroupID] = true
5460
ctx.SendChain(message.Text("❄️哔~"))
5561
})
56-
zero.OnFullMatch("空调关").SetBlock(true).FirstPriority().
62+
engine.OnFullMatch("空调关").SetBlock(true).FirstPriority().
5763
Handle(func(ctx *zero.Ctx) {
5864
AirConditSwitch[ctx.Event.GroupID] = false
5965
delete(AirConditTemp, ctx.Event.GroupID)
6066
ctx.SendChain(message.Text("💤哔~"))
6167
})
62-
zero.OnRegex(`设置温度(\d+)`).SetBlock(true).FirstPriority().
68+
engine.OnRegex(`设置温度(\d+)`).SetBlock(true).FirstPriority().
6369
Handle(func(ctx *zero.Ctx) {
6470
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
6571
AirConditTemp[ctx.Event.GroupID] = 26
@@ -78,7 +84,7 @@ func init() { // 插件主体
7884
))
7985
}
8086
})
81-
zero.OnFullMatch(`群温度`).SetBlock(true).FirstPriority().
87+
engine.OnFullMatch(`群温度`).SetBlock(true).FirstPriority().
8288
Handle(func(ctx *zero.Ctx) {
8389
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
8490
AirConditTemp[ctx.Event.GroupID] = 26

plugin_choose/choose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func init() {
1717
DisableOnDefault: false,
1818
Help: "choose\n" +
1919
"- 选择可口可乐还是百事可乐\n" +
20-
"- 选择肯德基还是麦当劳还是必胜客\n",
20+
"- 选择肯德基还是麦当劳还是必胜客",
2121
})
2222
engine.OnPrefix("选择").SetBlock(true).FirstPriority().Handle(handle)
2323
}

0 commit comments

Comments
 (0)