-
Notifications
You must be signed in to change notification settings - Fork 28
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
model自己的私有函数可以是基础的接口,但是导出的公开函数必须是高层的抽象。牛牛的复杂玩法都要放进去,方便统一管理。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
搬太多了,实际上就是一股脑全搬过来罢了,这完全不是我想要的效果。这样写不如不搬。AnimeAPI是和ZeroBot和zbpuitls解耦的,禁止增加这两个依赖。如果你能在没有这两个依赖的情况下完成这个包,那我会再仔细看你的实现。
There was a problem hiding this 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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("暂时没有男孩子哦") |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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(``) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
禁止使用空error
No description provided.