@@ -48,8 +48,10 @@ const (
48
48
"- 取消在\" cron\" 的提醒\n " +
49
49
"- 列出所有提醒\n " +
50
50
"- 翻牌\n " +
51
- "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] { at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像\n " +
51
+ "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] [{id}] { at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像 {id}是被欢迎者QQ号 \n " +
52
52
"- 测试欢迎语\n " +
53
+ "- 设置告别辞 参数同设置欢迎语\n " +
54
+ "- 测试告别辞\n " +
53
55
"- [开启 | 关闭]入群验证"
54
56
)
55
57
@@ -76,6 +78,10 @@ func init() { // 插件主体
76
78
if err != nil {
77
79
panic (err )
78
80
}
81
+ err = db .Create ("farewell" , & welcome {})
82
+ if err != nil {
83
+ panic (err )
84
+ }
79
85
}()
80
86
81
87
// 升为管理
@@ -430,8 +436,14 @@ func init() { // 插件主体
430
436
engine .OnNotice ().SetBlock (false ).
431
437
Handle (func (ctx * zero.Ctx ) {
432
438
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
+ }
435
447
}
436
448
})
437
449
// 设置欢迎语
@@ -459,6 +471,32 @@ func init() { // 插件主体
459
471
ctx .SendChain (message .Text ("欢迎~" ))
460
472
}
461
473
})
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
+ })
462
500
// 入群后验证开关
463
501
engine .OnRegex (`^(.*)入群验证$` , zero .OnlyGroup , zero .AdminPermission ).SetBlock (true ).
464
502
Handle (func (ctx * zero.Ctx ) {
@@ -543,11 +581,13 @@ func init() { // 插件主体
543
581
544
582
// 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg)
545
583
func welcometocq (ctx * zero.Ctx , welcome string ) string {
546
- nickname := ctx .GetGroupMemberInfo (ctx .Event .GroupID , ctx .Event .UserID , false ).Get ("nickname" ).Str
547
584
at := "[CQ:at,qq=" + strconv .FormatInt (ctx .Event .UserID , 10 ) + "]"
548
585
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 )
549
588
cqstring := strings .ReplaceAll (welcome , "{at}" , at )
550
589
cqstring = strings .ReplaceAll (cqstring , "{nickname}" , nickname )
551
590
cqstring = strings .ReplaceAll (cqstring , "{avatar}" , avatar )
591
+ cqstring = strings .ReplaceAll (cqstring , "{id}" , id )
552
592
return cqstring
553
593
}
0 commit comments