Skip to content

Commit 87e3297

Browse files
authored
定制退群提醒+调整煎蛋网无聊图触发 (#166)
* 优化在两个命令中使用空格分隔的体验 - fortune的设置底图功能 - b14的加密功能 * 优化四个插件中使用空格分隔的体验 - 加密 - 哔哩哔哩推送 - 藏头诗 - 运势 * 优化并修正了上一个commit - 加上了因为复制粘贴疏忽又没有注意测试遗漏的`?` - 调整藏头诗和加密的正则触发,使其不必多此一举 - 删去了未被发现的测试代码 * - 删去了遗漏的Trim * 优化了更多插件中使用空格的体验 - 优化了music bilibili image_finder 中使用空格的体验 - 补上了plugin_bilibili中未实现的vup开头触发 - 为plugin_bilibili_parse输出的消息加上一个换行符,优化排版 * 小调整 - 考虑到屌字既难打又有碍观瞻,改为正则匹配`[屌|弔|吊]图` - 增加了退群提醒的定制 * - 修复退群提醒本身忘记修改了的问题
1 parent 81a4297 commit 87e3297

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ print("run[CQ:image,file="+j["img"]+"]")
350350
- **b站视频链接解析** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_parse"`
351351
- [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF
352352
- **煎蛋网无聊图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan"`
353-
- [x] 来份屌图
354-
- [x] 更新屌图
353+
- [x] 来份[屌|弔|吊]
354+
- [x] 更新[屌|弔|吊]
355355
- **月幕galgame图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal"`
356356
- [x] 随机galCG
357357
- [x] 随机gal表情包

plugin/jandan/jandan.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
func init() {
2626
engine := control.Register("jandan", order.AcquirePrio(), &control.Options{
2727
DisableOnDefault: false,
28-
Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n",
28+
Help: "煎蛋网无聊图\n- 来份[屌|弔|吊]图\n- 更新[屌|弔|吊]图\n",
2929
PublicDataFolder: "Jandan",
3030
})
3131

@@ -44,7 +44,7 @@ func init() {
4444
logrus.Printf("[jandan]读取%d张图片", n)
4545
}()
4646

47-
engine.OnFullMatch("来份屌图").SetBlock(true).
47+
engine.OnRegex(`来份[屌|弔|吊]图`).SetBlock(true).
4848
Handle(func(ctx *zero.Ctx) {
4949
u, err := getRandomPicture()
5050
if err != nil {
@@ -54,7 +54,7 @@ func init() {
5454
ctx.SendChain(message.Image(u))
5555
})
5656

57-
engine.OnFullMatch("更新屌图", zero.SuperUserPermission).SetBlock(true).
57+
engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission).SetBlock(true).
5858
Handle(func(ctx *zero.Ctx) {
5959
ctx.Send("少女更新中...")
6060
webpageURL := api

plugin/manager/manager.go

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ const (
4848
"- 取消在\"cron\"的提醒\n" +
4949
"- 列出所有提醒\n" +
5050
"- 翻牌\n" +
51-
"- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像\n" +
51+
"- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] [{id}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像 {id}是被欢迎者QQ号\n" +
5252
"- 测试欢迎语\n" +
53+
"- 设置告别辞 参数同设置欢迎语\n" +
54+
"- 测试告别辞\n" +
5355
"- [开启 | 关闭]入群验证"
5456
)
5557

@@ -76,6 +78,10 @@ func init() { // 插件主体
7678
if err != nil {
7779
panic(err)
7880
}
81+
err = db.Create("farewell", &welcome{})
82+
if err != nil {
83+
panic(err)
84+
}
7985
}()
8086

8187
// 升为管理
@@ -430,8 +436,14 @@ func init() { // 插件主体
430436
engine.OnNotice().SetBlock(false).
431437
Handle(func(ctx *zero.Ctx) {
432438
if ctx.Event.NoticeType == "group_decrease" {
433-
userid := ctx.Event.UserID
434-
ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们..."))
439+
var w welcome
440+
err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
441+
if err == nil {
442+
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg)))
443+
} else {
444+
userid := ctx.Event.UserID
445+
ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们..."))
446+
}
435447
}
436448
})
437449
// 设置欢迎语
@@ -459,6 +471,32 @@ func init() { // 插件主体
459471
ctx.SendChain(message.Text("欢迎~"))
460472
}
461473
})
474+
// 设置告别辞
475+
engine.OnRegex(`^设置告别辞([\s\S]*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
476+
Handle(func(ctx *zero.Ctx) {
477+
w := &welcome{
478+
GrpID: ctx.Event.GroupID,
479+
Msg: ctx.State["regex_matched"].([]string)[1],
480+
}
481+
err := db.Insert("farewell", w)
482+
if err == nil {
483+
ctx.SendChain(message.Text("记住啦!"))
484+
} else {
485+
ctx.SendChain(message.Text("出错啦: ", err))
486+
}
487+
})
488+
// 测试告别辞
489+
engine.OnFullMatch("测试告别辞", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
490+
Handle(func(ctx *zero.Ctx) {
491+
var w welcome
492+
err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
493+
if err == nil {
494+
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg)))
495+
} else {
496+
userid := ctx.Event.UserID
497+
ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们..."))
498+
}
499+
})
462500
// 入群后验证开关
463501
engine.OnRegex(`^(.*)入群验证$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
464502
Handle(func(ctx *zero.Ctx) {
@@ -543,11 +581,13 @@ func init() { // 插件主体
543581

544582
// 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg)
545583
func welcometocq(ctx *zero.Ctx, welcome string) string {
546-
nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("nickname").Str
547584
at := "[CQ:at,qq=" + strconv.FormatInt(ctx.Event.UserID, 10) + "]"
548585
avatar := "[CQ:image,file=" + "http://q4.qlogo.cn/g?b=qq&nk=" + strconv.FormatInt(ctx.Event.UserID, 10) + "&s=640]"
586+
id := strconv.FormatInt(ctx.Event.UserID, 10)
587+
nickname := ctx.CardOrNickName(ctx.Event.UserID)
549588
cqstring := strings.ReplaceAll(welcome, "{at}", at)
550589
cqstring = strings.ReplaceAll(cqstring, "{nickname}", nickname)
551590
cqstring = strings.ReplaceAll(cqstring, "{avatar}", avatar)
591+
cqstring = strings.ReplaceAll(cqstring, "{id}", id)
552592
return cqstring
553593
}

0 commit comments

Comments
 (0)