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

add:封装niuniu的数据库操作 #61

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Conversation

xyy0411
Copy link

@xyy0411 xyy0411 commented Nov 2, 2024

No description provided.

Copy link
Member

@fumiama fumiama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model自己的私有函数可以是基础的接口,但是导出的公开函数必须是高层的抽象。牛牛的复杂玩法都要放进去,方便统一管理。

README.md Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
niuniu/niuniu.go Outdated Show resolved Hide resolved
Copy link
Member

@fumiama fumiama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

搬太多了,实际上就是一股脑全搬过来罢了,这完全不是我想要的效果。这样写不如不搬。AnimeAPI是和ZeroBot和zbpuitls解耦的,禁止增加这两个依赖。如果你能在没有这两个依赖的情况下完成这个包,那我会再仔细看你的实现。

go.mod Outdated Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
Copy link
Member

@fumiama fumiama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有些问题之前就提过这次又出现,希望能举一反三。暂时这些吧,有点看不下去了。

)

require (
github.com/FloatTech/gg v1.1.3 // indirect
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪来的这么多indirect


// SetWordNiuNiu length > 0 就增加 , length < 0 就减小
func SetWordNiuNiu(gid, uid int64, length float64) error {
niu, err := db.getWordNiuNiu(gid, uid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加锁防并发,其它get/set的地方一样。

}

func GetWordNiuNiu(gid, uid int64) (float64, error) {
niu, err := db.getWordNiuNiu(gid, uid)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接

return niu.Length, err

niu.Length默认值即为0

niuOfGroup, err := db.getAllNiuNiuOfGroup(gid)
if err != nil {
if t {
err = errors.New("暂时没有男孩子哦")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err定义为全局变量,如

var (
    ErrNoBoys = errors.New(...)
    ErrNoGirls = errors.New(...)
)

f := make(BaseInfos, len(niuOfGroup))
if t {
list = niuOfGroup.positive()
niuOfGroup.sort(t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

抽象,直接

list = niuOfGroup.select(t)
niuOfGroup.sort(true)

func Redeem(gid, uid int64, lastLength float64) error {
money := wallet.GetWalletOf(uid)
if money < 150 {
return fmt.Errorf("赎牛牛需要150ATRI币,快去赚钱吧,目前仅有:%d个%s", money, wallet.GetWalletName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

禁止使用Errorf

}
money, t, message := profit(niu.Length)
if !t {
return message, errors.New(``)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

禁止使用空error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants