mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-06 15:20:22 +00:00
Add files via upload (#774)
This commit is contained in:
@@ -14,17 +14,18 @@ import (
|
||||
"github.com/FloatTech/gg"
|
||||
"github.com/FloatTech/imgfactory"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
var (
|
||||
refresh = false
|
||||
timeNow = 0
|
||||
refreshFish = func(ctx *zero.Ctx) bool {
|
||||
storeLimiter = rate.NewManager[int64](time.Second*3, 1)
|
||||
refresh = false
|
||||
timeNow = 0
|
||||
refreshFish = func(ctx *zero.Ctx) bool {
|
||||
if refresh && timeNow == time.Now().Day() {
|
||||
return true
|
||||
}
|
||||
@@ -38,8 +39,12 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func limitSet(ctx *zero.Ctx) *rate.Limiter {
|
||||
return storeLimiter.Load(ctx.Event.UserID)
|
||||
}
|
||||
|
||||
func init() {
|
||||
engine.OnFullMatchGroup([]string{"钓鱼看板", "钓鱼商店"}, getdb, refreshFish).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
engine.OnFullMatchGroup([]string{"钓鱼看板", "钓鱼商店"}, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
||||
infos, err := dbdata.getStoreInfo()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.2]:", err))
|
||||
@@ -62,9 +67,20 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.ImageBytes(pic))
|
||||
})
|
||||
engine.OnRegex(`^出售(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
engine.OnRegex(`^出售(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
if strings.Contains(thingName, "竿") {
|
||||
times, err := dbdata.checkCanSalesFor(uid, true)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.75]:", err))
|
||||
return
|
||||
}
|
||||
if times <= 0 {
|
||||
ctx.SendChain(message.Text("出售次数已达到上限,明天再来售卖吧"))
|
||||
return
|
||||
}
|
||||
}
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 || strings.Contains(thingName, "竿") {
|
||||
number = 1
|
||||
@@ -131,8 +147,7 @@ func init() {
|
||||
|
||||
thing = articles[index]
|
||||
if thing.Number < number {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("背包数量不足")))
|
||||
return
|
||||
number = thing.Number
|
||||
}
|
||||
|
||||
var pice int
|
||||
@@ -178,7 +193,7 @@ func init() {
|
||||
recordInfo := records[0]
|
||||
numberOfRecord := recordInfo.Number
|
||||
if thingName == "唱片" {
|
||||
numberOfRecord--
|
||||
numberOfRecord -= number
|
||||
}
|
||||
if numberOfRecord > 0 {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否使用唱片让价格翻倍?\n回答\"是\"或\"否\"")))
|
||||
@@ -204,6 +219,9 @@ func init() {
|
||||
}
|
||||
if use {
|
||||
pice *= 2
|
||||
if thingName == "唱片" {
|
||||
thing.Number--
|
||||
}
|
||||
recordInfo.Number--
|
||||
err = dbdata.updateUserThingInfo(uid, recordInfo)
|
||||
if err != nil {
|
||||
@@ -280,13 +298,15 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.10]:", err))
|
||||
return
|
||||
}
|
||||
err = dbdata.updateCurseFor(uid, "sell", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
if strings.Contains(thingName, "竿") {
|
||||
err = dbdata.updateCurseFor(uid, "sell", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, msg)))
|
||||
})
|
||||
engine.OnRegex(`^购买(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
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, "竿")
|
||||
if err != nil {
|
||||
@@ -297,6 +317,15 @@ func init() {
|
||||
ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于50支的玩家不允许购买东西"))
|
||||
return
|
||||
}
|
||||
buytimes, err := dbdata.checkCanSalesFor(uid, false)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.75]:", err))
|
||||
return
|
||||
}
|
||||
if buytimes <= 0 {
|
||||
ctx.SendChain(message.Text("出售次数已达到上限,明天再来购买吧"))
|
||||
return
|
||||
}
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 {
|
||||
@@ -407,14 +436,28 @@ func init() {
|
||||
}
|
||||
price := pice[index] * number
|
||||
|
||||
msg := ""
|
||||
times := math.Min(3, number)
|
||||
coupon, err := dbdata.useCouponAt(uid, times)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
if coupon != -1 {
|
||||
msg += "\n(半价福利还有" + strconv.Itoa(3-coupon) + "次)"
|
||||
price = pice[index]*(number-coupon) + (pice[index]/2)*coupon
|
||||
} else {
|
||||
err = dbdata.updateBuyTimeFor(uid, 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
|
||||
return
|
||||
}
|
||||
msg := ""
|
||||
if curse != 0 {
|
||||
msg = "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)"
|
||||
msg += "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)"
|
||||
price = price * (100 + 10*curse) / 100
|
||||
}
|
||||
|
||||
@@ -497,11 +540,13 @@ func init() {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.14]:", err))
|
||||
return
|
||||
}
|
||||
err = dbdata.updateCurseFor(uid, "buy", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
if strings.Contains(thingName, "竿") {
|
||||
err = dbdata.updateCurseFor(uid, "buy", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("购买成功")))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName)))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user