mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
parent
b777b34126
commit
f13342350d
@ -812,15 +812,15 @@ func checkIsFish(thing string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测买卖鱼上限
|
// 查询能交易鱼类的数量
|
||||||
func (sql *fishdb) checkCanSalesFishFor(uid int64, sales int) (int, error) {
|
func (sql *fishdb) selectCanSalesFishFor(uid int64, sales int) int {
|
||||||
residue := 0
|
residue := 0
|
||||||
sql.Lock()
|
sql.Lock()
|
||||||
defer sql.Unlock()
|
defer sql.Unlock()
|
||||||
userInfo := buffInfo{ID: uid}
|
userInfo := buffInfo{ID: uid}
|
||||||
err := sql.db.Create("buff", &userInfo)
|
err := sql.db.Create("buff", &userInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return residue, err
|
return residue
|
||||||
}
|
}
|
||||||
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||||
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
|
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
|
||||||
@ -834,6 +834,19 @@ func (sql *fishdb) checkCanSalesFishFor(uid int64, sales int) (int, error) {
|
|||||||
if sales > maxSales {
|
if sales > maxSales {
|
||||||
sales = maxSales
|
sales = maxSales
|
||||||
}
|
}
|
||||||
userInfo.SalesFish += sales
|
return sales
|
||||||
return sales, sql.db.Insert("buff", &userInfo)
|
}
|
||||||
|
|
||||||
|
// 更新买卖鱼上限,假定sales变量已经在 selectCanSalesFishFor 进行了防护
|
||||||
|
func (sql *fishdb) updateCanSalesFishFor(uid int64, sales int) error {
|
||||||
|
sql.Lock()
|
||||||
|
defer sql.Unlock()
|
||||||
|
userInfo := buffInfo{ID: uid}
|
||||||
|
err := sql.db.Create("buff", &userInfo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||||
|
userInfo.SalesFish += sales
|
||||||
|
return sql.db.Insert("buff", &userInfo)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,13 +86,9 @@ func init() {
|
|||||||
number = 1
|
number = 1
|
||||||
}
|
}
|
||||||
if checkIsFish(thingName) {
|
if checkIsFish(thingName) {
|
||||||
residue, err := dbdata.checkCanSalesFishFor(uid, number)
|
residue := dbdata.selectCanSalesFishFor(uid, number)
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("[ERROR]:", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if residue <= 0 {
|
if residue <= 0 {
|
||||||
ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧"))
|
ctx.SendChain(message.Text("一天只能交易100条鱼,明天再来卖鱼吧"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
number = residue
|
number = residue
|
||||||
@ -198,6 +194,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新交易鱼类数量
|
||||||
|
if checkIsFish(thingName) {
|
||||||
|
err := dbdata.updateCanSalesFishFor(uid, number)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
records, err := dbdata.getUserThingInfo(uid, "唱片")
|
records, err := dbdata.getUserThingInfo(uid, "唱片")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("[ERROR at store.go.9.1]:", err))
|
ctx.SendChain(message.Text("[ERROR at store.go.9.1]:", err))
|
||||||
@ -318,7 +321,7 @@ func init() {
|
|||||||
logrus.Warnln(err)
|
logrus.Warnln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, msg)))
|
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("成功出售", thingName, ":", number, "个", ",你赚到了", pice*number, msg)))
|
||||||
})
|
})
|
||||||
engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
@ -422,13 +425,9 @@ func init() {
|
|||||||
number = 1
|
number = 1
|
||||||
}
|
}
|
||||||
if checkIsFish(thingName) {
|
if checkIsFish(thingName) {
|
||||||
residue, err := dbdata.checkCanSalesFishFor(uid, number)
|
residue := dbdata.selectCanSalesFishFor(uid, number)
|
||||||
if err != nil {
|
|
||||||
ctx.SendChain(message.Text("[ERROR]:", err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if residue <= 0 {
|
if residue <= 0 {
|
||||||
ctx.SendChain(message.Text("今天你已经超出了鱼交易数量上限,明天再来买鱼吧"))
|
ctx.SendChain(message.Text("一天只能交易100条鱼,明天再来买鱼吧"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
number = residue
|
number = residue
|
||||||
@ -533,6 +532,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新交易鱼类数量
|
||||||
|
if checkIsFish(thingName) {
|
||||||
|
err := dbdata.updateCanSalesFishFor(uid, number)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
|
||||||
|
}
|
||||||
|
}
|
||||||
thing := thingInfos[index]
|
thing := thingInfos[index]
|
||||||
if thing.Number < number {
|
if thing.Number < number {
|
||||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足")))
|
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足")))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user