MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / updateFishInfo

Method updateFishInfo

plugin/mcfish/main.go:233–257  ·  view source on GitHub ↗

更新上限信息

(uid int64, number int)

Source from the content-addressed store, hash-verified

231
232// 更新上限信息
233func (sql *fishdb) updateFishInfo(uid int64, number int) (residue int, err error) {
234 sql.Lock()
235 defer sql.Unlock()
236 userInfo := fishState{ID: uid}
237 err = sql.db.Create("fishState", &userInfo)
238 if err != nil {
239 return 0, err
240 }
241 _ = sql.db.Find("fishState", &userInfo, "WHERE ID = ?", uid)
242 if time.Unix(userInfo.Duration, 0).Day() != time.Now().Day() {
243 userInfo.Fish = 0
244 userInfo.Duration = time.Now().Unix()
245 }
246 if userInfo.Fish >= FishLimit {
247 return 0, nil
248 }
249 residue = number
250 if userInfo.Fish+number > FishLimit {
251 residue = FishLimit - userInfo.Fish
252 number = residue
253 }
254 userInfo.Fish += number
255 err = sql.db.Insert("fishState", &userInfo)
256 return
257}
258
259// 更新诅咒
260func (sql *fishdb) updateCurseFor(uid int64, info string, number int) (err error) {

Callers 1

initFunction · 0.80

Calls 1

DayMethod · 0.80

Tested by

no test coverage detected