diff options
author | alex | 2018-11-08 10:40:08 +0000 |
---|---|---|
committer | alex | 2018-11-08 10:40:08 +0000 |
commit | 237d91de163b1c20e6e5aaf49ee802dbde2397d6 (patch) | |
tree | 6fafac1b557da75a671adbf03db324cd689e53de /wat/db.go | |
parent | ecb988a3d916bf9e1b3a33fec4d19cc82b1acfdc (diff) | |
download | watbot-237d91de163b1c20e6e5aaf49ee802dbde2397d6.tar.gz watbot-237d91de163b1c20e6e5aaf49ee802dbde2397d6.tar.bz2 watbot-237d91de163b1c20e6e5aaf49ee802dbde2397d6.zip |
formatting changes from goimport
added a link to source, healing
parse ints through one function and return helpful errors that can be used as return values
added more error checking
improved some output
made some more joke methods
lazily added more if conditions for people i'm sick of
Diffstat (limited to 'wat/db.go')
-rw-r--r-- | wat/db.go | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -2,23 +2,24 @@ package wat import ( "time" + "github.com/jinzhu/gorm" - _"github.com/jinzhu/gorm/dialects/sqlite" + _ "github.com/jinzhu/gorm/dialects/sqlite" ) import "fmt" type Player struct { gorm.Model - Nick string - Host string - Watting int64 - Anarchy int64 - Trickery int64 - Coins int64 `gorm:"default:'100'"` - Health int64 - LastMined int64 + Nick string + Host string + Watting int64 + Anarchy int64 + Trickery int64 + Coins int64 `gorm:"default:'100'"` + Health int64 + LastMined int64 LastRested int64 - CoinsLost int64 + CoinsLost int64 } func (p *Player) LoseCoins(coins int64) { @@ -32,9 +33,9 @@ func (p *Player) Conscious() bool { func (p *Player) Level(xp int64) int64 { if xp < 100 { - return xp/10 + return xp / 10 } else if xp < 900 { - return 10 + (xp/100) + return 10 + (xp / 100) } else { return 99 } @@ -42,21 +43,21 @@ func (p *Player) Level(xp int64) int64 { type Ledger struct { PlayerId uint `gorm:"primary_key"` - Time int64 - Balance int64 - Log string + Time int64 + Balance int64 + Log string } type Item struct { PlayerId uint - Name string `gorm:"primary_key"` - Price int64 + Name string `gorm:"primary_key"` + Price int64 } type PlayerItem struct { PlayerId uint - ItemId int - Count int + ItemId int + Count int } type WatDb struct { @@ -89,8 +90,11 @@ func (w *WatDb) User(nick, host string, create bool) Player { return player } -func (w *WatDb) Update(upd interface{}) { - w.db.Save(upd) +func (w *WatDb) Update(upd ...interface{}) { + for _, u := range upd { + fmt.Printf("Updating %+v\n", u) + w.db.Save(u) + } } func (w *WatDb) TopTen() []Player { |