From d1b83f47646a843657bbeb5fed0839da3550f540 Mon Sep 17 00:00:00 2001 From: vatebur <67186678+vatebur@users.noreply.github.com> Date: Mon, 6 May 2024 18:43:26 +0800 Subject: [PATCH] [mcfish] Add one click selling (#894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [mcfish] Add one click selling Add one click waste selling function to mcfish plugin 给mcfish 添加一键售卖垃圾功能 * 🔖 v1.7.8 * chore: del aipaint due to 过气 * chore: del baidu due to 使えない * chore: del cangtoushi due to 使えない * chore: del dress due to 删库 * chore: del heisi due to 跑路 * chore: del jiami due to 跑路 * chore: del jiuejuezi due to 跑路 * chore: del quan due to 跑路 * chore: del wangyiyun due to 跑路 * chore: del wenben due to 跑路 * fix: atri 早安 conflict with sleep_manage & add 回应表情 * fix: version limit * fix: version limit * fix: version limit * chore: update deps * fix(searcher): forward node * 💩👌 make lint happy * revert: fix(searcher): forward node * fix(github): get api method * chore: del imgfinder due to 跑路 * optimize: saucenao head * chore: tidy * chore: del vtbxxx due to 跑路 * fix(drawlots): draw gif noise * fix(emojimix): connection issue in some regions * 💩👌 make lint happy * fix(drawlots): draw gif noise * fix(emojimix): add more logs * feat: add uwu logo * optimize: README uwu icon * chore: update deps * optimize: 赞我 触发失败时静默 * fix: update img pool * fix: imgpool on LLOB * fix(manager): 回应表情 * ✨ 修复b站小程序解析 (#895) * add control for saucenao & bilibili_parse (#839) * add control for saucenao&bilibili_parse * not only group * update control * reuse variables --------- Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com> * fix(bilibili): parse config * fix(manager): 撤回 * fix: reply face * fix: reply face * 💩👌 make lint happy * feat: add option `-mirror` * chore: update deps * chore: update deps * chore: update deps * chore: update deps * chore: update deps * chore: update deps * chore: update deps * 🔖 v1.8.0 * revert: emojimix http2 * 📝 update README * [mcfish] Add one click selling Add one click waste selling function to mcfish plugin 给mcfish 添加一键售卖垃圾功能 * Update robbery plugin Update robbery plugin 修改打劫功能 --------- Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com> Co-authored-by: himawari <54976075+guohuiyuan@users.noreply.github.com> Co-authored-by: 莫思潋 <55676105+shudorcl@users.noreply.github.com> --- README.md | 2 +- plugin/mcfish/main.go | 22 ++++++++++++- plugin/mcfish/store.go | 71 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 565835e8..33628187 100644 --- a/README.md +++ b/README.md @@ -900,7 +900,7 @@ print("run[CQ:image,file="+j["img"]+"]") - [x] 钓鱼商店 - [x] 购买xxx [数量] - - [x] 出售xxx [数量] + - [x] 出售[xxx [数量]|所有垃圾] - [x] 钓鱼背包 - [x] 装备[xx竿|三叉戟|美西螈] - [x] 附魔[诱钓|海之眷顾] diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index 150263db..8b58a585 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -131,7 +131,7 @@ var ( DisableOnDefault: false, Brief: "钓鱼", Help: "一款钓鱼模拟器\n----------指令----------\n" + - "- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n" + + "- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n- 出售所有垃圾\n" + "- 钓鱼背包\n- 装备[xx竿|三叉戟|美西螈]\n- 附魔[诱钓|海之眷顾]\n- 修复鱼竿\n- 合成[xx竿|三叉戟]\n- 消除[绑定|宝藏]诅咒\n- 消除[绑定|宝藏]诅咒 [数量]\n" + "- 进行钓鱼\n- 进行n次钓鱼\n- 当前装备概率明细\n" + "规则V" + version + ":\n" + @@ -530,6 +530,26 @@ func (sql *fishdb) getNumberFor(uid int64, thing string) (number int, err error) return } +// 获取用户的某类物品信息 +func (sql *fishdb) getUserTypeInfo(uid int64, thingType string) (thingInfos []article, err error) { + name := strconv.FormatInt(uid, 10) + "Pack" + sql.Lock() + defer sql.Unlock() + userInfo := article{} + err = sql.db.Create(name, &userInfo) + if err != nil { + return + } + if !sql.db.CanFind(name, "where Type = '"+thingType+"'") { + return + } + err = sql.db.FindFor(name, &userInfo, "where Type = '"+thingType+"'", func() error { + thingInfos = append(thingInfos, userInfo) + return nil + }) + return +} + /*********************************************************/ /************************商店相关函数***********************/ /*********************************************************/ diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index a7d59354..85e90dc2 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -306,6 +306,77 @@ func init() { } ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, msg))) }) + engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) { + uid := ctx.Event.UserID + + articles, err := dbdata.getUserTypeInfo(uid, "waste") + if err != nil { + ctx.SendChain(message.Text("[ERROR]:获取背包信息错误", err)) + return + } + if len(articles) == 0 { + ctx.SendChain(message.Text("你的背包不存在该物品")) + return + } + if len(articles) > 1 { + msg := make(message.Message, 0, 3+len(articles)) + msg = append(msg, message.Reply(ctx.Event.MessageID), message.Text("找到以下物品:\n")) + for i, info := range articles { + msg = append(msg, message.Text( + "[", i, "]", info.Name, " 数量: ", info.Number, "\n")) + } + ctx.Send(msg) + } + + pice := 0 + for _, info := range articles { + pice += (priceList[info.Name] * discountList[info.Name] / 100) * info.Number * 8 / 10 + } + + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice, "收购全部垃圾", "?\n回答\"是\"或\"否\""))) + // 等待用户下一步选择 + recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat() + defer cancel1() + buy := false + for { + select { + case <-time.After(time.Second * 60): + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("等待超时,取消钓鱼"))) + return + case e := <-recv: + nextcmd := e.Event.Message.String() + if nextcmd == "否" { + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消出售"))) + return + } + buy = true + } + if buy { + break + } + } + + msg := "" + curse, err := dbdata.getNumberFor(uid, "宝藏诅咒") + if err != nil { + ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err)) + return + } + if curse != 0 { + msg = "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)" + pice = pice * (100 - 10*curse) / 100 + } + + for _, info := range articles { + info.Number = 0 + err = dbdata.updateUserThingInfo(uid, info) + if err != nil { + ctx.SendChain(message.Text("[ERROR at store.go.6]:", err)) + return + } + } + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice, msg))) + }) engine.OnRegex(`^购买(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) { uid := ctx.Event.UserID numberOfPole, err := dbdata.getNumberFor(uid, "竿")