diff options
author | Georg Pfuetzenreuter | 2024-10-02 22:30:06 +0200 |
---|---|---|
committer | Georg Pfuetzenreuter | 2024-10-02 22:30:06 +0200 |
commit | accf16c92aa8420dd12d414ab05c60358cbc23ba (patch) | |
tree | b41954a839ea64893a00ba457a0e0c1e02e0cfdb /wat/db.go | |
parent | 394d6ca2fa34f924b1790ad66da42cf374829315 (diff) | |
download | watbot-accf16c92aa8420dd12d414ab05c60358cbc23ba.tar.gz watbot-accf16c92aa8420dd12d414ab05c60358cbc23ba.tar.bz2 watbot-accf16c92aa8420dd12d414ab05c60358cbc23ba.zip |
Change host lookup to be optional
Some parts of the logic do not make use of the host column in the
players table, allow the field to be empty and do not query for an empty
value (which might return bogus entries) if no value is passed to the
lookup function.
This additionally avoids the need for the hardcoded initial host when
configuring the bot player.
Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
Diffstat (limited to 'wat/db.go')
-rw-r--r-- | wat/db.go | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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 |