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

提交新插件牛牛大作战 #944

Merged
merged 64 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
910b6a2
Add files via upload
xyy0411 Aug 3, 2024
68356a0
Delete plugin/main.go
xyy0411 Aug 3, 2024
a48c9f5
Delete plugin/go.sum
xyy0411 Aug 3, 2024
c2bf903
Delete plugin/go.mod
xyy0411 Aug 3, 2024
02500b8
Update main.go
xyy0411 Aug 4, 2024
667f9e1
Update model.go
xyy0411 Aug 4, 2024
97be553
Update main.go
xyy0411 Aug 4, 2024
a7d3fc9
Update main.go
xyy0411 Aug 4, 2024
e048296
Update main.go
xyy0411 Aug 4, 2024
699b80c
Update result.go
xyy0411 Aug 4, 2024
9da476f
Update main.go
xyy0411 Aug 4, 2024
2a913e0
Update main.go
xyy0411 Aug 11, 2024
25ebd17
Update model.go
xyy0411 Aug 11, 2024
b1ce060
Update result.go
xyy0411 Aug 11, 2024
7637a52
Update main.go
xyy0411 Aug 11, 2024
32d3a1b
Update main.go
xyy0411 Aug 11, 2024
a80fd77
Update main.go
xyy0411 Aug 12, 2024
d708204
Update model.go
xyy0411 Aug 12, 2024
c229063
Update result.go
xyy0411 Aug 12, 2024
88e059b
Update main.go
xyy0411 Aug 17, 2024
ce5cc5c
Update result.go
xyy0411 Aug 17, 2024
17cdf28
Update result.go
xyy0411 Aug 17, 2024
b5d51f0
Update result.go
xyy0411 Aug 18, 2024
634a866
Merge branch 'FloatTech:master' into master
xyy0411 Aug 19, 2024
2fef3b6
Update main.go
xyy0411 Aug 19, 2024
f4b2da2
Update main.go
xyy0411 Aug 19, 2024
5b7ad7c
Merge branch 'master' into master
fumiama Aug 19, 2024
83c6624
Merge branch 'master' into master
fumiama Aug 19, 2024
e5da406
Update and rename result.go to untils.go
xyy0411 Aug 20, 2024
11396a7
Update model.go
xyy0411 Aug 20, 2024
1110a99
Update main.go
xyy0411 Aug 20, 2024
79b84cb
Update main.go
xyy0411 Aug 20, 2024
37b3f48
Update main.go
xyy0411 Aug 20, 2024
804b724
Update main.go
xyy0411 Aug 20, 2024
d7a08f4
Merge branch 'master' into master
fumiama Aug 21, 2024
46f9131
Rename untils.go to utils.go
xyy0411 Aug 21, 2024
b46cd4d
Update main.go
xyy0411 Aug 22, 2024
ef21807
Update model.go
xyy0411 Aug 22, 2024
4d00448
Update utils.go
xyy0411 Aug 22, 2024
992f9a8
Update main.go
xyy0411 Aug 22, 2024
d9255df
Update model.go
xyy0411 Aug 22, 2024
11ec958
Update utils.go
xyy0411 Aug 22, 2024
d929941
Update utils.go
xyy0411 Aug 22, 2024
e83e2dc
Update main.go
xyy0411 Aug 22, 2024
bc63eb0
Merge branch 'FloatTech:master' into master
xyy0411 Aug 25, 2024
117d56b
Update model.go
xyy0411 Aug 25, 2024
1c3fbea
Update main.go
xyy0411 Aug 25, 2024
0ffe2d4
Update main.go
xyy0411 Aug 25, 2024
a9c9234
Update main.go
xyy0411 Aug 25, 2024
e70f473
Update main.go
xyy0411 Aug 25, 2024
bbeaf04
Update model.go
xyy0411 Aug 25, 2024
0344d41
Update main.go
xyy0411 Aug 25, 2024
35a2d11
Update README.md
xyy0411 Aug 25, 2024
a0a28a2
Update main.go
xyy0411 Aug 25, 2024
df6e95d
Update README.md
xyy0411 Aug 25, 2024
92721a5
Update README.md
xyy0411 Aug 26, 2024
903392c
Update README.md
fumiama Aug 27, 2024
15a1837
Update main.go
xyy0411 Aug 28, 2024
c3f6406
Update main.go
xyy0411 Aug 29, 2024
1e96eca
Update main.go
xyy0411 Aug 29, 2024
e65f816
Update model.go
xyy0411 Aug 29, 2024
78669d5
Update utils.go
xyy0411 Aug 29, 2024
f198271
Update main.go
xyy0411 Aug 29, 2024
95d0c69
Merge branch 'master' into master
fumiama Aug 30, 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
52 changes: 36 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1009,22 +1009,6 @@ print("run[CQ:image,file="+j["img"]+"]")

- 注:刷新文件夹较慢,请耐心等待刷新完成,会提示“成功”。

</details>
<details>
<summary>抽wife</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife"`

- [x] 抽wife[@xxx]

- [x] 添加wife[名字][图片]

- [x] 删除wife[名字]

- [x] [让 | 不让]所有人均可添加wife

- 注:不同群添加后不会重叠

</details>
<details>
<summary>拼音首字母释义工具</summary>
Expand Down Expand Up @@ -1067,6 +1051,42 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 当图片属于非 neutral 类别时自动发送评价(默认禁用,启用输入 /启用 nsfwauto)

</details>
<details>
<summary>抽wife</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife"`

- [x] 抽wife[@xxx]

- [x] 添加wife[名字][图片]

- [x] 删除wife[名字]

- [x] [让 | 不让]所有人均可添加wife

- 注:不同群添加后不会重叠

</details>
<details>
<summary>牛牛大作战</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/niuniu" `

- [x] 打胶

- [x] jj[@xxx]

- [x] 注册牛牛

- [x] 注销牛牛

- [x] 牛子长度排行

- [x] 牛子深度排行

- [x] 查看我的牛牛

</details>
<details>
<summary>浅草寺求签</summary>
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife" // 本地老婆
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/niuniu" // 牛牛大作战
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker" // 抽扑克
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
Expand Down
244 changes: 244 additions & 0 deletions plugin/niuniu/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
// Package niuniu 牛牛大作战
package niuniu

import (
"fmt"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
"github.com/FloatTech/zbputils/ctxext"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
"math/rand"
"strconv"
"strings"
"time"
)

var (
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Brief: "牛牛大作战",
Help: "- 打胶\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)
)

func init() {
en.OnFullMatch("牛子长度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
niuniuList, err := db.readAllTable(gid)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
m := niuniuList.positive()
if m == nil {
ctx.SendChain(message.Text("暂时没有男孩子哦"))
fumiama marked this conversation as resolved.
Show resolved Hide resolved
return
}
var messages strings.Builder
messages.WriteString("牛子长度排行\n")
for i, user := range niuniuList.sort(true) {
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
ctx.CardOrNickName(user.UID), user.Length))
}
msg := ctxext.FakeSenderForwardNode(ctx, message.Text(&messages))
if id := ctx.Send(message.Message{msg}).ID(); id == 0 {
ctx.Send(message.Text("发送排行失败"))
}
})
en.OnFullMatch("牛子深度排行", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
niuniuList, err := db.readAllTable(gid)
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
return
}
m := niuniuList.negative()
if m == nil {
ctx.SendChain(message.Text("暂时没有女孩子哦"))
fumiama marked this conversation as resolved.
Show resolved Hide resolved
return
}
var messages strings.Builder
messages.WriteString("牛牛深度排行榜\n")
for i, user := range niuniuList.sort(false) {
messages.WriteString(fmt.Sprintf("第%d名 id:%s 长度:%.2fcm\n", i+1,
ctx.CardOrNickName(user.UID), user.Length))
}
msg := ctxext.FakeSenderForwardNode(ctx, message.Text(&messages))
if id := ctx.Send(message.Message{msg}).ID(); id == 0 {
ctx.Send(message.Text("发送排行失败"))
}
})
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)
if err != nil {
ctx.SendChain(message.Text("你还没有牛牛呢不能查看!"))
return
}
var result strings.Builder
sexLong := "长"
sex := "♂️"
if niuniu < 0 {
sexLong = "深"
sex = "♀️"
}
niuniuList, err := db.readAllTable(gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ",
ctx.CardOrNickName(uid), strconv.FormatInt(uid, 10),
sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu)))
ctx.SendChain(message.At(uid), message.Text(&result))
})
en.OnFullMatchGroup([]string{"dj", "打胶"}, zero.OnlyGroup,
getdb).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter {
lt := dajiaoLimiter.Load(fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID))
ctx.State["dajiao_last_touch"] = lt.LastTouch()
return lt
}, func(ctx *zero.Ctx) {
timePass := int(time.Since(time.Unix(ctx.State["dajiao_last_touch"].(int64), 0)).Seconds())
ctx.SendChain(message.Text(randomChoice([]string{
fmt.Sprintf("才过去了%ds时间,你就又要打🦶了,身体受得住吗", timePass),
fmt.Sprintf("不行不行,你的身体会受不了的,歇%ds再来吧", 90-timePass),
fmt.Sprintf("休息一下吧,会炸膛的!%ds后再来吧", 90-timePass),
fmt.Sprintf("打咩哟,你的牛牛会爆炸的,休息%ds再来吧", 90-timePass),
})))
}).Handle(func(ctx *zero.Ctx) {
// 获取群号和用户ID
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
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,
}
ctx.SendChain(message.Text(messages))
if err = db.insertniuniu(&u, gid); err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
})
en.OnFullMatch("注册牛牛", zero.OnlyGroup, getdb).SetBlock(true).Handle(func(ctx *zero.Ctx) {
gid := ctx.Event.GroupID
uid := ctx.Event.UserID
if _, err := db.findniuniu(gid, uid); err == nil {
ctx.SendChain(message.Text("你已经注册过了"))
return
}
//获取初始长度
long := db.randLength()
u := userInfo{
UID: uid,
Length: long,
UserCount: 0,
}
//添加数据进入表
err := db.insertniuniu(&u, gid)
if err != nil {
err = db.createGIDTable(gid)
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.Reply(ctx.Event.GroupID),
message.Text("注册成功,你的牛牛现在有", u.Length, "cm"))
})
en.OnRegex(`jj\[CQ:at,qq=(\d+),name=[\s\S]*\]$`, getdb,
zero.OnlyGroup).SetBlock(true).Limit(func(ctx *zero.Ctx) *rate.Limiter {
lt := jjLimiter.Load(fmt.Sprintf("%d_%d", ctx.Event.GroupID, ctx.Event.UserID))
ctx.State["jj_last_touch"] = lt.LastTouch()
return lt
}, func(ctx *zero.Ctx) {
timePass := int(time.Since(time.Unix(ctx.State["jj_last_touch"].(int64), 0)).Seconds())
ctx.SendChain(message.Text(randomChoice([]string{
fmt.Sprintf("才过去了%ds时间,你就又要击剑了,真是饥渴难耐啊", timePass),
fmt.Sprintf("不行不行,你的身体会受不了的,歇%ds再来吧", 150-timePass),
fmt.Sprintf("你这种男同就应该被送去集中营!等待%ds再来吧", 150-timePass),
fmt.Sprintf("打咩哟!你的牛牛会炸的,休息%ds再来吧", 150-timePass),
})))
},
).Handle(func(ctx *zero.Ctx) {
adduser, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
uid := ctx.Event.UserID
gid := ctx.Event.GroupID
myniuniu, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("你还没有牛牛快去注册一个吧!"))
jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
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))
return
}
if uid == adduser {
ctx.SendChain(message.Text("你要和谁🤺?你自己吗?"))
jjLimiter.Delete(fmt.Sprintf("%d_%d", gid, uid))
return
}
fencingResult, f, f1 := fencing(myniuniu, adduserniuniu)
err = db.insertniuniu(&userInfo{UID: uid, Length: f}, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
err = db.insertniuniu(&userInfo{UID: adduser, Length: f1}, gid)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.At(uid), message.Text(fencingResult))
})
en.OnFullMatch("注销牛牛", getdb, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
gid := ctx.Event.GroupID
_, err := db.findniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("你还没有牛牛呢,咋的你想凭空造一个啊"))
return
}
err = db.deleteniuniu(gid, uid)
if err != nil {
ctx.SendChain(message.Text("注销失败"))
return
}
ctx.SendChain(message.Text("注销成功,你已经没有牛牛了"))
})
}

func randomChoice(options []string) string {
return options[rand.Intn(len(options))]
}

Loading
Loading