mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
fix: wifegame (#1225)
This commit is contained in:
parent
d304cda7f0
commit
dd328afae8
@ -25,19 +25,7 @@ var (
|
|||||||
Brief: "从老婆库抽每日老婆",
|
Brief: "从老婆库抽每日老婆",
|
||||||
PublicDataFolder: "Wife",
|
PublicDataFolder: "Wife",
|
||||||
}).ApplySingle(ctxext.DefaultSingle)
|
}).ApplySingle(ctxext.DefaultSingle)
|
||||||
)
|
getJSON = fcext.DoOnceOnSuccess(
|
||||||
|
|
||||||
func card2name(card string) (string, string) {
|
|
||||||
match := re.FindStringSubmatch(card)
|
|
||||||
if len(match) >= 3 {
|
|
||||||
return match[1], match[2]
|
|
||||||
}
|
|
||||||
return "", ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
_ = os.MkdirAll(engine.DataFolder()+"wives", 0755)
|
|
||||||
engine.OnFullMatch("抽老婆", fcext.DoOnceOnSuccess(
|
|
||||||
func(ctx *zero.Ctx) bool {
|
func(ctx *zero.Ctx) bool {
|
||||||
data, err := engine.GetLazyData("wife.json", true)
|
data, err := engine.GetLazyData("wife.json", true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -52,7 +40,20 @@ func init() {
|
|||||||
logrus.Infof("[wife]加载%d个老婆", len(cards))
|
logrus.Infof("[wife]加载%d个老婆", len(cards))
|
||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
)).SetBlock(true).
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
func card2name(card string) (string, string) {
|
||||||
|
match := re.FindStringSubmatch(card)
|
||||||
|
if len(match) >= 3 {
|
||||||
|
return match[1], match[2]
|
||||||
|
}
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_ = os.MkdirAll(engine.DataFolder()+"wives", 0755)
|
||||||
|
engine.OnFullMatch("抽老婆", getJSON).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
card := cards[fcext.RandSenderPerDayN(ctx.Event.UserID, len(cards))]
|
card := cards[fcext.RandSenderPerDayN(ctx.Event.UserID, len(cards))]
|
||||||
data, err := engine.GetLazyData("wives/"+card, true)
|
data, err := engine.GetLazyData("wives/"+card, true)
|
||||||
|
|||||||
@ -2,16 +2,13 @@
|
|||||||
package wife
|
package wife
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"bytes"
|
||||||
|
"image"
|
||||||
"image/color"
|
"image/color"
|
||||||
"io/fs"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/FloatTech/floatbox/file"
|
|
||||||
"github.com/FloatTech/gg"
|
|
||||||
ctrl "github.com/FloatTech/zbpctrl"
|
ctrl "github.com/FloatTech/zbpctrl"
|
||||||
"github.com/FloatTech/zbputils/control"
|
"github.com/FloatTech/zbputils/control"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
@ -32,25 +29,18 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// _ = os.MkdirAll(engine.DataFolder()+"wives", 0755)
|
enguess.OnFullMatch("猜老婆", getJSON).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
enguess.OnFullMatch("猜老婆").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
|
||||||
var err error
|
|
||||||
class := 3
|
class := 3
|
||||||
|
|
||||||
fileName, err := lottery()
|
card := cards[rand.Intn(len(cards))]
|
||||||
|
pic, err := engine.GetLazyData("wives/"+card, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
|
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
work, name := card2name(card)
|
||||||
work, name := card2name(fileName)
|
name = strings.ToLower(name)
|
||||||
picFile := file.BOTPATH + "/" + engine.DataFolder() + "wives/" + fileName
|
img, _, err := image.Decode(bytes.NewReader(pic))
|
||||||
pic, err := os.ReadFile(picFile)
|
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
img, err := gg.LoadImage(picFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
|
ctx.SendChain(message.Text("[猜老婆]error:\n", err))
|
||||||
return
|
return
|
||||||
@ -67,13 +57,13 @@ func init() {
|
|||||||
if id := ctx.SendChain(
|
if id := ctx.SendChain(
|
||||||
message.ImageBytes(q),
|
message.ImageBytes(q),
|
||||||
); id.ID() != 0 {
|
); id.ID() != 0 {
|
||||||
ctx.SendChain(message.Text("请回答该二次元角色名字\n以“xxx酱”格式回答"))
|
ctx.SendChain(message.Text("请回答该二次元角色名字\n以“xxx酱”格式回答\n发送“跳过”结束猜题"))
|
||||||
}
|
}
|
||||||
var next *zero.FutureEvent
|
var next *zero.FutureEvent
|
||||||
if ctx.Event.GroupID == 0 {
|
if ctx.Event.GroupID == 0 {
|
||||||
next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`(·)?.+酱$`), ctx.CheckSession())
|
next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(·)?[^酱]+酱|^跳过$`), ctx.CheckSession())
|
||||||
} else {
|
} else {
|
||||||
next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`(·)?.+酱$`), zero.CheckGroup(ctx.Event.GroupID))
|
next = zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(·)?[^酱]+酱|^跳过$`), zero.CheckGroup(ctx.Event.GroupID))
|
||||||
}
|
}
|
||||||
recv, cancel := next.Repeat()
|
recv, cancel := next.Repeat()
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@ -92,12 +82,22 @@ func init() {
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
case c := <-recv:
|
case c := <-recv:
|
||||||
tick.Reset(105 * time.Second)
|
// tick.Reset(105 * time.Second)
|
||||||
after.Reset(120 * time.Second)
|
// after.Reset(120 * time.Second)
|
||||||
msg := c.Event.Message.String()
|
msg := strings.ReplaceAll(c.Event.Message.String(), "酱", "")
|
||||||
msg, _, _ = strings.Cut(msg, "酱")
|
if msg == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if msg == "跳过" {
|
||||||
|
if msgID := ctx.Send(message.ReplyWithMessage(c.Event.MessageID,
|
||||||
|
message.Text("已跳过猜题\n角色是:\n", name, "\n出自《", work, "》\n"),
|
||||||
|
message.ImageBytes(pic))); msgID.ID() == 0 {
|
||||||
|
ctx.SendChain(message.Text("太棒了,你猜对了!\n图片发送失败,可能被风控\n角色是:\n", name, "\n出自《", work, "》"))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
class--
|
class--
|
||||||
if strings.Contains(name, msg) {
|
if strings.Contains(name, strings.ToLower(msg)) {
|
||||||
if msgID := ctx.Send(message.ReplyWithMessage(c.Event.MessageID,
|
if msgID := ctx.Send(message.ReplyWithMessage(c.Event.MessageID,
|
||||||
message.Text("太棒了,你猜对了!\n角色是:\n", name, "\n出自《", work, "》\n"),
|
message.Text("太棒了,你猜对了!\n角色是:\n", name, "\n出自《", work, "》\n"),
|
||||||
message.ImageBytes(pic))); msgID.ID() == 0 {
|
message.ImageBytes(pic))); msgID.ID() == 0 {
|
||||||
@ -120,8 +120,12 @@ func init() {
|
|||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
msg = ""
|
||||||
|
if class == 2 {
|
||||||
|
msg = "(提示:" + work + ")\n"
|
||||||
|
}
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.Text("回答错误,你还有", class, "次机会\n请继续作答(难度降低)\n"),
|
message.Text("回答错误,你还有", class, "次机会\n", msg, "请继续作答(难度降低)\n"),
|
||||||
message.ImageBytes(q),
|
message.ImageBytes(q),
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
@ -130,51 +134,6 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从本地图库随机抽取,规避网络问题
|
|
||||||
func lottery() (fileName string, err error) {
|
|
||||||
path := engine.DataFolder() + "wives" + "/"
|
|
||||||
if file.IsNotExist(path) {
|
|
||||||
err = errors.New("图库文件夹不存在,请先发送“抽老婆”扩展图库")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
files, err := os.ReadDir(path)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// 如果本地列表为空
|
|
||||||
if len(files) == 0 {
|
|
||||||
err = errors.New("本地数据为0,请先发送“抽老婆”扩展图库")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fileName = randPicture(files, 10)
|
|
||||||
if fileName == "" {
|
|
||||||
err = errors.New("抽取图库轮空了,请重试")
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func randPicture(files []fs.DirEntry, indexMax int) (fileName string) {
|
|
||||||
if len(files) > 1 {
|
|
||||||
picture := files[rand.Intn(len(files))]
|
|
||||||
// 如果是文件夹就递归
|
|
||||||
if picture.IsDir() {
|
|
||||||
indexMax--
|
|
||||||
if indexMax <= 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fileName = randPicture(files, indexMax)
|
|
||||||
} else {
|
|
||||||
fileName = picture.Name()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
music := files[0]
|
|
||||||
if !music.IsDir() {
|
|
||||||
fileName = files[0].Name()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 马赛克生成
|
// 马赛克生成
|
||||||
func mosaic(dst *imgfactory.Factory, level int) ([]byte, error) {
|
func mosaic(dst *imgfactory.Factory, level int) ([]byte, error) {
|
||||||
b := dst.Image().Bounds()
|
b := dst.Image().Bounds()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user