Skip to content

Commit b2cff86

Browse files
Jiang-Redfumiama
andauthored
Update manager.go (#132)
* Update manager.go 修改 自定义欢迎语可带图 添加 修改名片/修改头衔/申请头衔字数限制 * Update manager.go * Update manager.go 添加 测试欢迎语 * Update manager.go * Update manager.go * Update manager.go Co-authored-by: 源文雨 <[email protected]>
1 parent dc348f8 commit b2cff86

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

plugin_manager/manager.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const (
4848
"- 取消在\"cron\"的提醒\n" +
4949
"- 列出所有提醒\n" +
5050
"- 翻牌\n" +
51-
"- 设置欢迎语XXX\n" +
51+
"- 设置欢迎语XXX(可加{at}在欢迎时@对方)\n" +
52+
"- 测试欢迎语\n" +
5253
"- [开启 | 关闭]入群验证"
5354
)
5455

@@ -210,6 +211,10 @@ func init() { // 插件主体
210211
// 修改名片
211212
engine.OnRegex(`^修改名片.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
212213
Handle(func(ctx *zero.Ctx) {
214+
if len(ctx.State["regex_matched"].([]string)[2]) > 60 {
215+
ctx.SendChain(message.Text("名字太长啦!"))
216+
return
217+
}
213218
ctx.SetGroupCard(
214219
ctx.Event.GroupID,
215220
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被修改群名片的人
@@ -220,6 +225,10 @@ func init() { // 插件主体
220225
// 修改头衔
221226
engine.OnRegex(`^修改头衔.*?(\d+).*?\s(.*)`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
222227
Handle(func(ctx *zero.Ctx) {
228+
if len(ctx.State["regex_matched"].([]string)[1]) > 18 {
229+
ctx.SendChain(message.Text("头衔太长啦!"))
230+
return
231+
}
223232
ctx.SetGroupSpecialTitle(
224233
ctx.Event.GroupID,
225234
math.Str2Int64(ctx.State["regex_matched"].([]string)[1]), // 被修改群头衔的人
@@ -230,6 +239,10 @@ func init() { // 插件主体
230239
// 申请头衔
231240
engine.OnRegex(`^申请头衔(.*)`, zero.OnlyGroup).SetBlock(true).
232241
Handle(func(ctx *zero.Ctx) {
242+
if len(ctx.State["regex_matched"].([]string)[1]) > 18 {
243+
ctx.SendChain(message.Text("头衔太长啦!"))
244+
return
245+
}
233246
ctx.SetGroupSpecialTitle(
234247
ctx.Event.GroupID,
235248
ctx.Event.UserID, // 被修改群头衔的人
@@ -369,7 +382,7 @@ func init() { // 插件主体
369382
var w welcome
370383
err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
371384
if err == nil {
372-
ctx.SendChain(message.Text(w.Msg))
385+
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(strings.ReplaceAll(w.Msg, "{at}", "[CQ:at,qq="+strconv.FormatInt(ctx.Event.UserID, 10)+"]")))
373386
} else {
374387
ctx.SendChain(message.Text("欢迎~"))
375388
}
@@ -436,6 +449,17 @@ func init() { // 插件主体
436449
ctx.SendChain(message.Text("出错啦: ", err))
437450
}
438451
})
452+
// 测试欢迎语
453+
engine.OnFullMatch("测试欢迎语", zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
454+
Handle(func(ctx *zero.Ctx) {
455+
var w welcome
456+
err := db.Find("welcome", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10))
457+
if err == nil {
458+
ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(strings.ReplaceAll(w.Msg, "{at}", "[CQ:at,qq="+strconv.FormatInt(ctx.Event.UserID, 10)+"]")))
459+
} else {
460+
ctx.SendChain(message.Text("欢迎~"))
461+
}
462+
})
439463
// 入群后验证开关
440464
engine.OnRegex(`^(.*)入群验证$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).
441465
Handle(func(ctx *zero.Ctx) {

0 commit comments

Comments
 (0)