Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复niuniu的已知问题,添加新玩法牛牛商店 #974

Merged
merged 32 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a29bbec
Update main.go
xyy0411 Aug 31, 2024
c22079e
Update model.go
xyy0411 Aug 31, 2024
78e9d1a
Update utils.go
xyy0411 Aug 31, 2024
4f9c58f
Update README.md
xyy0411 Aug 31, 2024
66afee9
Update main.go
xyy0411 Aug 31, 2024
be5ec00
Update main.go
xyy0411 Sep 1, 2024
22e2447
Update model.go
xyy0411 Sep 1, 2024
05a28c9
Update main.go
xyy0411 Sep 2, 2024
fa0c9d8
Update main.go
xyy0411 Sep 2, 2024
83ee8b6
Update main.go
xyy0411 Sep 2, 2024
dd676ad
Update main.go
xyy0411 Sep 3, 2024
85ca08a
Update main.go
xyy0411 Sep 3, 2024
52d5e87
Merge branch 'FloatTech:master' into master
xyy0411 Sep 8, 2024
2cde59d
Update main.go
xyy0411 Sep 8, 2024
e06ece6
Update utils.go
xyy0411 Sep 8, 2024
8b862fa
Update model.go
xyy0411 Sep 8, 2024
d2f4a29
Update README.md
xyy0411 Sep 8, 2024
4e222f4
Update main.go
xyy0411 Sep 10, 2024
acc2fc4
修改了一些问题
xyy0411 Sep 13, 2024
a74efd7
修改了一些问题
xyy0411 Sep 13, 2024
75c77f1
修改了一些问题
xyy0411 Sep 13, 2024
09a24f7
修改了一些问题
xyy0411 Sep 14, 2024
9bac2a7
Merge remote-tracking branch 'origin/master'
xyy0411 Sep 14, 2024
da37ca6
修改了一些问题
xyy0411 Sep 14, 2024
40e77d8
牛牛商店改面向对象形式,加入NiuNiuPlugin接口
xyy0411 Sep 15, 2024
704f2e8
修改了一些问题
xyy0411 Sep 15, 2024
ffcede5
修改了一些问题
xyy0411 Sep 17, 2024
0c817c9
修改了一些问题
xyy0411 Sep 21, 2024
2b4d380
修复lint
xyy0411 Sep 21, 2024
531da5a
修复一些逻辑问题
xyy0411 Sep 25, 2024
7f4adce
修lint
xyy0411 Sep 25, 2024
6ab034d
Merge branch 'master' into master
fumiama Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 赎牛牛

- [x] 牛牛商店

- [x] 注册牛牛

- [x] 注销牛牛
Expand Down
145 changes: 126 additions & 19 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,99 @@ type lastLength struct {
Length float64
}

type propsCount struct {
Count int
TimeLimit time.Time
}

var (
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "牛牛大作战",
Help: "- 打胶\n" +
"- 赎牛牛 (cd:30分钟)\n" +
"- jj@xxx\n" +
"- 注册牛牛\n" +
"- 赎牛牛(cd:45分钟)\n" +
"- 牛牛商店\n" +
"- 注销牛牛\n" +
"- 查看我的牛牛\n" +
"- jj@xxx\n" +
"- 牛子长度排行\n" +
"- 牛子深度排行\n",
PrivateDataFolder: "niuniu",
})
dajiaoLimiter = rate.NewManager[string](time.Second*90, 1)
jjLimiter = rate.NewManager[string](time.Second*150, 1)
jjCount = syncx.Map[string, *lastLength]{}
prop = syncx.Map[string, *propsCount]{}
)

func init() {
en.OnFullMatch("牛牛商店", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.GroupID
var messages message.Message
messages = append(messages, message.Text("牛牛商店当前售卖的物品如下"))
messages = append(messages,
ctxext.FakeSenderForwardNode(ctx,
message.Text("商品1\n商品名:伟哥\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都增长,有效5次")))
messages = append(messages,
ctxext.FakeSenderForwardNode(ctx,
message.Text("商品2\n商品名:媚药\n商品价格:300ATRI币\n商品描述:可以让你打胶每次都减少,有效5次")))
messages = append(messages,
ctxext.FakeSenderForwardNode(ctx,
message.Text("商品3\n商品名:击剑神器\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都立于不败之地,有效2次")))
messages = append(messages,
ctxext.FakeSenderForwardNode(ctx,
message.Text("商品4\n商品名:击剑神稽\n商品价格:500ATRI币\n商品描述:可以让你每次击剑都失败,有效2次")))
if id := ctx.Send(messages).ID(); id == 0 {
ctx.Send(message.Text("发送商店失败"))
}
ctx.SendChain(message.Text("输入对应序号进行购买商品"))
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.CheckUser(uid), zero.CheckGroup(gid), zero.RegexRule(`(/d+)`)).Repeat()
defer cancel()
timer := time.NewTimer(120 * time.Second)
fumiama marked this conversation as resolved.
Show resolved Hide resolved
defer timer.Stop()
for {
select {
case <-timer.C:
ctx.SendChain(message.At(uid), message.Text("超时,已自动取消"))
return
case r := <-recv:
answer := r.Event.Message.String()
n, err := strconv.Atoi(answer)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
info, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
u, money, err := purchaseItem(n, info, uid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
if wallet.GetWalletOf(uid) < money {
ctx.SendChain(message.Text("你还没有足够的ATRI币呢,不能购买"))
return
}
err = wallet.InsertWalletOf(uid, -money)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
err = db.insertniuniu(u, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}

ctx.SendChain(message.Text("购买成功!"))
}
}
})
en.OnFullMatch("赎牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
Expand All @@ -52,7 +125,7 @@ func init() {
ctx.SendChain(message.Text("你还没有被厥呢"))
return
}
if time.Since(last.TimeLimit) > time.Minute*30 {
if time.Since(last.TimeLimit) > time.Minute*45 {
ctx.SendChain(message.Text("时间已经过期了,牛牛已被收回!"))
jjCount.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
Expand All @@ -62,11 +135,11 @@ func init() {
return
}
money := wallet.GetWalletOf(uid)
if money < 100 {
ctx.SendChain(message.Text("赎牛牛需要100ATRI币,快去赚钱吧"))
if money < 150 {
ctx.SendChain(message.Text("赎牛牛需要150ATRI币,快去赚钱吧"))
fumiama marked this conversation as resolved.
Show resolved Hide resolved
return
}
err := wallet.InsertWalletOf(uid, -100)
err := wallet.InsertWalletOf(uid, -150)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand Down Expand Up @@ -133,11 +206,12 @@ func init() {
en.OnFullMatch("查看我的牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
gid := ctx.Event.GroupID
niuniu, err := db.findniuniu(gid, uid)
i, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("你还没有牛牛呢不能查看!"))
return
}
niuniu := i.Length
var result strings.Builder
sexLong := "长"
sex := "♂️"
Expand Down Expand Up @@ -172,17 +246,15 @@ func init() {
// 获取群号和用户ID
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
t := fmt.Sprintf("%d_%d", gid, uid)
updateMap(t, false)
niuniu, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("请先注册牛牛!"))
dajiaoLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
}
messages, f := generateRandomStingTwo(niuniu)
u := userInfo{
UID: uid,
Length: f,
}
messages, u := processNiuniuAction(t, &niuniu, ctx, uid)
ctx.SendChain(message.Text(messages))
if err = db.insertniuniu(&u, gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
Expand Down Expand Up @@ -243,30 +315,32 @@ func init() {
}
uid := ctx.Event.UserID
gid := ctx.Event.GroupID
t := fmt.Sprintf("%d_%d", gid, uid)
updateMap(t, false)
myniuniu, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!"))
jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
jjLimiter.Delete(t)
return
}
adduserniuniu, err := db.findniuniu(gid, adduser)
if err != nil {
ctx.SendChain(message.At(uid), message.Text("对方还没有牛牛呢,不能🤺"))
jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
jjLimiter.Delete(t)
return
}
if uid == adduser {
ctx.SendChain(message.Text("你要和谁🤺?你自己吗?"))
jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
jjLimiter.Delete(t)
return
}
fencingResult, f, f1 := fencing(myniuniu, adduserniuniu)
err = db.insertniuniu(&userInfo{UID: uid, Length: f, UserCount: 0}, gid)
fencingResult, f1, u := processJJuAction(&myniuniu, &adduserniuniu, t, ctx)
err = db.insertniuniu(&u, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1, UserCount: 0}, gid)
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
Expand All @@ -279,15 +353,23 @@ func init() {
c = lastLength{
TimeLimit: time.Now(),
Count: 1,
Length: adduserniuniu,
Length: adduserniuniu.Length,
}
} else {
c = lastLength{
TimeLimit: c.TimeLimit,
Count: count.Count + 1,
Length: count.Length,
}
if time.Since(c.TimeLimit) > time.Minute*45 {
c = lastLength{
TimeLimit: time.Now(),
Count: 1,
Length: adduserniuniu.Length,
}
}
}

jjCount.Store(j, &c)
if c.Count > 5 {
ctx.SendChain(message.Text(randomChoice([]string{fmt.Sprintf("你们太厉害了,对方已经被你们打了%d次了,你们可以继续找他🤺", c.Count),
Expand All @@ -300,6 +382,7 @@ func init() {
}
}
}

})
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
Expand All @@ -321,3 +404,27 @@ func init() {
func randomChoice(options []string) string {
return options[rand.Intn(len(options))]
}

func updateMap(t string, d bool) {
value, ok := prop.Load(t)
if !d {
if time.Since(value.TimeLimit) > time.Minute*8 {
prop.Delete(t)
}
return
}
if ok {
prop.Store(t, &propsCount{
Count: value.Count + 1,
TimeLimit: value.TimeLimit,
})
} else {
prop.Store(t, &propsCount{
Count: 1,
TimeLimit: time.Now(),
})
}
if time.Since(value.TimeLimit) > time.Minute*8 {
prop.Delete(t)
}
}
8 changes: 6 additions & 2 deletions plugin/niuniu/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ type userInfo struct {
UID int64
Length float64
UserCount int
WeiGe int // 伟哥
Philter int // 媚药
Artifact int // 击剑神器
ShenJi int // 击剑神稽
}

type users []*userInfo
Expand Down Expand Up @@ -93,12 +97,12 @@ func (db *model) createGIDTable(gid int64) error {
return db.sql.Create(strconv.FormatInt(gid, 10), &userInfo{})
}

func (db *model) findniuniu(gid, uid int64) (float64, error) {
func (db *model) findniuniu(gid, uid int64) (userInfo, error) {
db.RLock()
defer db.RUnlock()
u := userInfo{}
err := db.sql.Find(strconv.FormatInt(gid, 10), &u, "where UID = "+strconv.FormatInt(uid, 10))
return u.Length, err
return u, err
}

func (db *model) insertniuniu(u *userInfo, gid int64) error {
Expand Down
Loading
Loading