FloatTech / ZeroBot-Plugin

基于 ZeroBot 的 OneBot 插件

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nativesetu功能返回多图 数量可选

502milk opened this issue · comments

engine.OnRegex(`^本地(\S+)?(\d+)?`, fcext.ValueInList(func(ctx *zero.Ctx) string { return ctx.State["regex_matched"].([]string)[1] }, ns)).SetBlock(true).
	Handle(func(ctx *zero.Ctx) {
		match := ctx.State["regex_matched"].([]string)
		classname := match[1]   // 获取分类名
		imgcountStr := match[2] // 获取数量
		if imgcountStr == "" {
			imgcountStr = "1" // 如果没有指定数量,则默认为 1
		}
		imgcount, _ := strconv.Atoi(imgcountStr)
		if imgcount > 20 {
			imgcount = 20 // 如果数量大于 20,则将其设为 20
		}
		// 在分类列表中查找数量与请求匹配的分类名
		ns.mu.RLock()
		for _, c := range ns.List() {
			n, err := ns.db.Count(c)
			if err != nil {
				continue
			}
			if n == imgcount {
				classname = c
				break
			}
		}
		ns.mu.RUnlock()

		// 如果找到了匹配的分类名,则获取分类下的一张随机图片并返回
		if classname != "" {
			sc := new(setuclass)
			ns.mu.RLock()
			err := ns.db.Pick(classname, sc)
			ns.mu.RUnlock()
			if err != nil {
				ctx.SendChain(message.Text("ERROR: ", err))
			} else {
				p := "file:///" + setupath + "/" + sc.Path
				if ctx.Event.GroupID != 0 {
					ctx.SendGroupForwardMessage(ctx.Event.GroupID, message.Message{
						ctxext.FakeSenderForwardNode(ctx,
							message.Text(classname, ": ", sc.Name, "\n"), message.Image(p),
						)})
					return
				}
				ctx.SendChain(message.Text(classname, ": ", sc.Name, "\n"), message.Image(p))
			}
		}
	})

不会改了·-·
[ERROR] [api] 调用 send_group_forward_msg 时出现错误, 返回值: 100 , 信息: EMPTY_NODES 解释: 未找到任何可发送的合并转发信息
[2023-03-26 10:29:08] [WARNING]: 警告: 合并转发 685816675 图片上传失败: upload failed: dial tcp 112.80.250.229:443: connectex: An operation was attempted on something that is not a socket.
救命啊

问题在于 err := ns.db.Pick(classname, sc) 一次只能随机一张。要改得改得幅度比较大,我觉得你可以选择多发几次(

问题在于 err := ns.db.Pick(classname, sc) 一次只能随机一张。要改得改得幅度比较大,我觉得你可以选择多发几次(

水平太菜了(改不明白

不得行。。。只能写到编辑器不报错(捂脸)

engine.OnRegex(`^本地(.*)$`, fcext.ValueInList(func(ctx *zero.Ctx) string { return ctx.State["regex_matched"].([]string)[1] }, ns)).SetBlock(true).
	Handle(func(ctx *zero.Ctx) {
		imgtype := ctx.State["regex_matched"].([]string)[1]
		num := 1 // 默认返回1张图片
		if ctx.State["cli_args"] != nil && len(ctx.State["cli_args"].([]string)) > 0 {
			n, err := strconv.Atoi(ctx.State["cli_args"].([]string)[0])
			if err == nil && n > 0 && n <= 20 { // 最多返回20张图片
				num = n
			}
		}
		ns.mu.RLock()
		defer ns.mu.RUnlock()
		for i := 0; i < num; i++ {
			sc := new(setuclass)
			err := ns.db.Pick(imgtype, sc)
			if err != nil {
				ctx.SendChain(message.Text("ERROR: ", err))
				return
			}
			p := "file:///" + setupath + "/" + sc.Path
			if ctx.Event.GroupID != 0 {
				ctx.SendGroupForwardMessage(ctx.Event.GroupID, message.Message{
					ctxext.FakeSenderForwardNode(ctx,
						message.Text(imgtype, ": ", sc.Name, "\n"), message.Image(p),
					)})
				continue
			}
			ctx.SendChain(message.Text(imgtype, ": ", sc.Name, "\n"), message.Image(p))
		}
	})

望天
依旧没写对(((

是不是你的sqlite得支持这种方法,要不然写raw sql了

是不是你的sqlite得支持这种方法,要不然写raw sql了

实际上已经写完了(群里dalao已经写过了,但pr并没有过(

是不是你的sqlite得支持这种方法,要不然写raw sql了

sqlite现已增加PickFor函数