diff --git a/README.md b/README.md index e9f1532f..1d37c646 100644 --- a/README.md +++ b/README.md @@ -350,8 +350,8 @@ print("run[CQ:image,file="+j["img"]+"]") - **b站视频链接解析** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili_parse"` - [x] https://www.bilibili.com/video/BV1xx411c7BF | https://www.bilibili.com/video/av1605 | https://b23.tv/I8uzWCA | https://www.bilibili.com/video/bv1xx411c7BF - **煎蛋网无聊图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan"` - - [x] 来份屌图 - - [x] 更新屌图 + - [x] 来份[屌|弔|吊]图 + - [x] 更新[屌|弔|吊]图 - **月幕galgame图** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal"` - [x] 随机galCG - [x] 随机gal表情包 diff --git a/plugin/jandan/jandan.go b/plugin/jandan/jandan.go index d3493d81..bc1623ed 100644 --- a/plugin/jandan/jandan.go +++ b/plugin/jandan/jandan.go @@ -25,7 +25,7 @@ const ( func init() { engine := control.Register("jandan", order.AcquirePrio(), &control.Options{ DisableOnDefault: false, - Help: "煎蛋网无聊图\n- 来份屌图\n- 更新屌图\n", + Help: "煎蛋网无聊图\n- 来份[屌|弔|吊]图\n- 更新[屌|弔|吊]图\n", PublicDataFolder: "Jandan", }) @@ -44,7 +44,7 @@ func init() { logrus.Printf("[jandan]读取%d张图片", n) }() - engine.OnFullMatch("来份屌图").SetBlock(true). + engine.OnRegex(`来份[屌|弔|吊]图`).SetBlock(true). Handle(func(ctx *zero.Ctx) { u, err := getRandomPicture() if err != nil { @@ -54,7 +54,7 @@ func init() { ctx.SendChain(message.Image(u)) }) - engine.OnFullMatch("更新屌图", zero.SuperUserPermission).SetBlock(true). + engine.OnRegex(`更新[屌|弔|吊]图`, zero.SuperUserPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { ctx.Send("少女更新中...") webpageURL := api diff --git a/plugin/manager/manager.go b/plugin/manager/manager.go index 8e34a00c..da31233e 100644 --- a/plugin/manager/manager.go +++ b/plugin/manager/manager.go @@ -48,8 +48,10 @@ const ( "- 取消在\"cron\"的提醒\n" + "- 列出所有提醒\n" + "- 翻牌\n" + - "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像\n" + + "- 设置欢迎语XXX 可选添加 [{at}] [{nickname}] [{avatar}] [{id}] {at}可在发送时艾特被欢迎者 {nickname}是被欢迎者名字 {avatar}是被欢迎者头像 {id}是被欢迎者QQ号\n" + "- 测试欢迎语\n" + + "- 设置告别辞 参数同设置欢迎语\n" + + "- 测试告别辞\n" + "- [开启 | 关闭]入群验证" ) @@ -76,6 +78,10 @@ func init() { // 插件主体 if err != nil { panic(err) } + err = db.Create("farewell", &welcome{}) + if err != nil { + panic(err) + } }() // 升为管理 @@ -430,8 +436,14 @@ func init() { // 插件主体 engine.OnNotice().SetBlock(false). Handle(func(ctx *zero.Ctx) { if ctx.Event.NoticeType == "group_decrease" { - userid := ctx.Event.UserID - ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + var w welcome + err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) + if err == nil { + ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg))) + } else { + userid := ctx.Event.UserID + ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + } } }) // 设置欢迎语 @@ -459,6 +471,32 @@ func init() { // 插件主体 ctx.SendChain(message.Text("欢迎~")) } }) + // 设置告别辞 + engine.OnRegex(`^设置告别辞([\s\S]*)$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + w := &welcome{ + GrpID: ctx.Event.GroupID, + Msg: ctx.State["regex_matched"].([]string)[1], + } + err := db.Insert("farewell", w) + if err == nil { + ctx.SendChain(message.Text("记住啦!")) + } else { + ctx.SendChain(message.Text("出错啦: ", err)) + } + }) + // 测试告别辞 + engine.OnFullMatch("测试告别辞", zero.OnlyGroup, zero.AdminPermission).SetBlock(true). + Handle(func(ctx *zero.Ctx) { + var w welcome + err := db.Find("farewell", &w, "where gid = "+strconv.FormatInt(ctx.Event.GroupID, 10)) + if err == nil { + ctx.SendGroupMessage(ctx.Event.GroupID, message.ParseMessageFromString(welcometocq(ctx, w.Msg))) + } else { + userid := ctx.Event.UserID + ctx.SendChain(message.Text(ctx.CardOrNickName(userid), "(", userid, ")", "离开了我们...")) + } + }) // 入群后验证开关 engine.OnRegex(`^(.*)入群验证$`, zero.OnlyGroup, zero.AdminPermission).SetBlock(true). Handle(func(ctx *zero.Ctx) { @@ -543,11 +581,13 @@ func init() { // 插件主体 // 传入 ctx 和 welcome格式string 返回cq格式string 使用方法:welcometocq(ctx,w.Msg) func welcometocq(ctx *zero.Ctx, welcome string) string { - nickname := ctx.GetGroupMemberInfo(ctx.Event.GroupID, ctx.Event.UserID, false).Get("nickname").Str at := "[CQ:at,qq=" + strconv.FormatInt(ctx.Event.UserID, 10) + "]" avatar := "[CQ:image,file=" + "http://q4.qlogo.cn/g?b=qq&nk=" + strconv.FormatInt(ctx.Event.UserID, 10) + "&s=640]" + id := strconv.FormatInt(ctx.Event.UserID, 10) + nickname := ctx.CardOrNickName(ctx.Event.UserID) cqstring := strings.ReplaceAll(welcome, "{at}", at) cqstring = strings.ReplaceAll(cqstring, "{nickname}", nickname) cqstring = strings.ReplaceAll(cqstring, "{avatar}", avatar) + cqstring = strings.ReplaceAll(cqstring, "{id}", id) return cqstring }