-
Notifications
You must be signed in to change notification settings - Fork 31
add:封装niuniu的数据库操作 #61
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ae6386f
add:封装niuniu的数据库操作
xyy0411 41713cc
修改了一些readme
xyy0411 611a675
Delete niuniu directory
xyy0411 661e39d
Merge branch 'FloatTech:main' into pr
xyy0411 12c9bbf
Add files via upload
xyy0411 c17c672
Merge pull request #1 from xyy0411/xyy0411-patch-1
xyy0411 2807d39
Update README.md
xyy0411 928d366
Update main.go
xyy0411 8f652a3
Update models.go
xyy0411 67ee52b
Create go.yml
xyy0411 bbf8867
fix
xyy0411 e884c0b
fix:部分函数名
xyy0411 8576a84
fix
xyy0411 1aed663
fix
xyy0411 2b3b507
fix:修复一些问题
xyy0411 3829811
fix
xyy0411 3aaf8f8
delete getGold()
xyy0411 04f5c88
fix:要求更改的地方
xyy0411 eedb4f2
Merge remote-tracking branch 'origin/pr' into pr
xyy0411 3f7a731
fix:将错误设置为全局变量
xyy0411 665c33e
加锁,还原go.mod
xyy0411 8451406
Update go.sum
xyy0411 c4f8ed8
Update go.mod
xyy0411 2c67a28
fix:函数名:createUserInfoByProps -> applyProp
xyy0411 f83540c
Merge remote-tracking branch 'origin/pr' into pr
xyy0411 739fa17
fix:变量名 lock -> globalLock
xyy0411 4ff909d
修lint
xyy0411 72ce32b
fix
xyy0411 b41584f
修lint
xyy0411 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ huggingface API | |
| 二次元 AI tag 作画 | ||
| ## nsfw | ||
| 图片合规性审查 | ||
| ## niu | ||
| niu | ||
| ## pixiv | ||
| P站解析与图片下载 | ||
| ## qzone | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| package niu | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "github.com/FloatTech/AnimeAPI/wallet" | ||
| "github.com/FloatTech/floatbox/file" | ||
| zero "github.com/wdvxdr1123/ZeroBot" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| var ( | ||
| db = &model{} | ||
| ) | ||
|
|
||
| func init() { | ||
| if file.IsNotExist("data/niuniu") { | ||
| err := os.MkdirAll("data/niuniu", 0755) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
| err := db.sql.Open(time.Hour * 24) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| // SetWordNiuNiu length > 0 就增加 , length < 0 就减小 | ||
| func SetWordNiuNiu(gid, uid int64, length float64) error { | ||
| niu, err := db.getWordNiuNiu(gid, uid) | ||
fumiama marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return err | ||
| } | ||
| niu.Length += length | ||
| return db.setWordNiuNiu(gid, niu) | ||
| } | ||
|
|
||
| func GetWordNiuNiu(gid, uid int64) (float64, error) { | ||
| niu, err := db.getWordNiuNiu(gid, uid) | ||
fumiama marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return 0, err | ||
| } | ||
| return niu.Length, nil | ||
| } | ||
|
|
||
| func DeleteWordNiuNiu(gid, uid int64) error { | ||
| return db.deleteWordNiuNiu(gid, uid) | ||
| } | ||
|
|
||
| func GetAllLengthOfGroup(gid int64) ([]float64, error) { | ||
| niuOfGroup, err := db.getAllNiuNiuOfGroup(gid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| f := make([]float64, len(niuOfGroup)) | ||
| for k, v := range niuOfGroup { | ||
| f[k] = v.Length | ||
| } | ||
| return f, nil | ||
| } | ||
|
|
||
| func LengthRanking(gid int64, ctx *zero.Ctx) ([]byte, error) { | ||
| niuniuList, err := db.getAllNiuNiuOfGroup(gid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| m := niuniuList.negative() | ||
| if m == nil { | ||
| return nil, errors.New("暂时没有男孩子哦") | ||
| } | ||
| m.sort(true) | ||
| buf, err := m.setupDrawList(ctx, true) | ||
| return buf, err | ||
| } | ||
|
|
||
| func DepthRanking(gid int64, ctx *zero.Ctx) ([]byte, error) { | ||
| niuniuList, err := db.getAllNiuNiuOfGroup(gid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| m := niuniuList.positive() | ||
| if m == nil { | ||
| return nil, errors.New("暂时没有女孩子哦") | ||
| } | ||
| m.sort(false) | ||
| buf, err := m.setupDrawList(ctx, false) | ||
| return buf, err | ||
| } | ||
|
|
||
| func View(gid, uid int64, name string) (*strings.Builder, error) { | ||
| i, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return nil, errors.New("你还没有牛牛呢不能查看") | ||
| } | ||
| niuniu := i.Length | ||
| var result strings.Builder | ||
| sexLong := "长" | ||
| sex := "♂️" | ||
| if niuniu < 0 { | ||
| sexLong = "深" | ||
| sex = "♀️" | ||
| } | ||
| niuniuList, err := db.getAllNiuNiuOfGroup(gid) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| result.WriteString(fmt.Sprintf("\n📛%s<%s>的牛牛信息\n⭕性别:%s\n⭕%s度:%.2fcm\n⭕排行:%d\n⭕%s ", | ||
| name, strconv.FormatInt(uid, 10), | ||
| sex, sexLong, niuniu, niuniuList.ranking(niuniu, uid), generateRandomString(niuniu))) | ||
| return &result, nil | ||
| } | ||
|
|
||
| func ProcessHitGlue(gid, uid int64, prop string) (string, error) { | ||
| niuniu, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return "", errors.New("请先注册牛牛!") | ||
| } | ||
|
|
||
| messages, err := niuniu.processNiuNiuAction(prop) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| if err = db.setWordNiuNiu(gid, niuniu); err != nil { | ||
| return "", err | ||
| } | ||
| return messages, nil | ||
| } | ||
|
|
||
| func Register(gid, uid int64) (string, error) { | ||
| if _, err := db.getWordNiuNiu(gid, uid); err == nil { | ||
| return "", errors.New("你已经注册过了") | ||
| } | ||
| // 获取初始长度 | ||
| length := db.newLength() | ||
| u := userInfo{ | ||
| UID: uid, | ||
| Length: length, | ||
| } | ||
| if err := db.setWordNiuNiu(gid, &u); err != nil { | ||
| return "", err | ||
| } | ||
| return fmt.Sprintf("注册成功,你的牛牛现在有%.2fcm", u.Length), nil | ||
| } | ||
|
|
||
| func JJ(gid, uid, adduser int64, prop string) (message string, err error) { | ||
| myniuniu, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return "", errors.New("你还没有牛牛快去注册一个吧!") | ||
| } | ||
| adduserniuniu, err := db.getWordNiuNiu(gid, adduser) | ||
| if err != nil { | ||
| return "", errors.New("对方还没有牛牛呢,不能🤺") | ||
| } | ||
|
|
||
| if uid == adduser { | ||
| return "", errors.New("你要和谁🤺?你自己吗?") | ||
| } | ||
|
|
||
| message, err = myniuniu.processJJuAction(adduserniuniu, prop) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if err = db.setWordNiuNiu(gid, myniuniu); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| if err = db.setWordNiuNiu(gid, adduserniuniu); err != nil { | ||
| return "", err | ||
| } | ||
| return | ||
| } | ||
|
|
||
| func Cancel(gid, uid int64) (string, error) { | ||
| _, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return "", errors.New("你还没有牛牛呢,咋的你想凭空造一个啊") | ||
| } | ||
| err = db.deleteWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| err = errors.New("遇到不可抗力因素,注销失败!") | ||
| } | ||
| return "注销成功,你已经没有牛牛了", err | ||
| } | ||
|
|
||
| func Redeem(gid, uid int64, lastLength float64) error { | ||
| niu, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| niu.Length = lastLength | ||
| return db.setWordNiuNiu(gid, niu) | ||
| } | ||
|
|
||
| func Store(gid, uid int64, n int) error { | ||
| info, err := db.getWordNiuNiu(gid, uid) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| money, err := info.purchaseItem(n) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if wallet.GetWalletOf(uid) < money { | ||
| return errors.New("你还没有足够的ATRI币呢,不能购买") | ||
| } | ||
|
|
||
| if err = wallet.InsertWalletOf(uid, -money); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return db.setWordNiuNiu(uid, info) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.