Merge pull request 'Change host lookup to be optional' (#23) from dbhost into master

Reviewed-on: #23
This commit is contained in:
Pratyush Desai 2024-10-03 18:00:59 +02:00
commit b6187e0077
2 changed files with 6 additions and 2 deletions

View File

@ -65,8 +65,12 @@ func NewWatDb() *WatDb {
func (w *WatDb) User(nick, host string, create bool) Player {
var player Player
query := "nick = ?"
if host != "" {
query = query + " or host = ?"
}
// Try and get a user
if err := w.db.First(&player, "nick = ? or host = ?", nick, host).Error; err != nil && create {
if err := w.db.First(&player, query, nick, host).Error; err != nil && create {
fmt.Printf("Creating user: %s\n", err.Error())
// No user, make another
player.Nick = nick

View File

@ -28,7 +28,7 @@ var unconscious = "wat, your hands fumble and fail you. try resting, weakling."
func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
g := WatGame{bot, db, Player{}, nil, nil, nil, nil, map[string]int{}}
g.me = g.db.User(bot.Nick, "amia8t89xfp8y.liberta.casa", true)
g.me = g.db.User(bot.Nick, "", true)
g.commands = map[string](func(*Player, []string) string){
//"wat": g.megaWat,
"steroid": g.Steroid,