Skip to content

Commit

Permalink
fix: 修复[mcfish]交易检测对垃圾的处理
Browse files Browse the repository at this point in the history
  • Loading branch information
vatebur committed Nov 29, 2024
1 parent 57ced24 commit 4131aa2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
14 changes: 12 additions & 2 deletions plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ func (sql *fishdb) checkCanSalesFor(uid int64, saleName string, salesNum int) (i
if userInfo.SalesPole >= 10 {
salesNum = -1
}
} else {
} else if !checkIsWaste(saleName) {
maxSales := 150 - userInfo.BuyTing
if maxSales < 0 {
salesNum = 0
Expand All @@ -823,8 +823,18 @@ func (sql *fishdb) updateCanSalesFor(uid int64, saleName string, sales int) erro
_ = sql.db.Find("buff", &userInfo, "WHERE ID = ?", uid)
if strings.Contains(saleName, "竿") {
userInfo.SalesPole++
} else {
} else if !checkIsWaste(saleName) {
userInfo.BuyTing += sales
}
return sql.db.Insert("buff", &userInfo)
}

// 检测物品是否是垃圾
func checkIsWaste(thing string) bool {
for _, v := range wasteList {
if v == thing {
return true
}
}
return false
}
14 changes: 6 additions & 8 deletions plugin/mcfish/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,10 @@ func init() {
logrus.Warnln(err)
}
}
// 更新交易限制(商店不卖垃圾)
if newCommodity.Type != "waste" {
err := dbdata.updateCanSalesFor(uid, thingName, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
}
// 更新交易限制
err = dbdata.updateCanSalesFor(uid, thingName, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
}

ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("成功出售", thingName, ":", number, "个", ",你赚到了", pice*number, msg)))
Expand Down Expand Up @@ -651,10 +649,10 @@ func init() {
logrus.Warnln(err)
}
}
// 更新交易限制(商店不卖垃圾)
// 更新交易限制
err = dbdata.updateCanSalesFor(uid, thingName, number)
if err != nil {
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
}
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName)))
})
Expand Down

0 comments on commit 4131aa2

Please sign in to comment.