summaryrefslogtreecommitdiffstats
path: root/wat/db.go
diff options
context:
space:
mode:
authorPratyush Desai2024-10-03 18:00:59 +0200
committerPratyush Desai2024-10-03 18:00:59 +0200
commitb6187e007792836c3c29d6925a3fa97cb23791bf (patch)
treeb41954a839ea64893a00ba457a0e0c1e02e0cfdb /wat/db.go
parent394d6ca2fa34f924b1790ad66da42cf374829315 (diff)
parentaccf16c92aa8420dd12d414ab05c60358cbc23ba (diff)
downloadwatbot-b6187e007792836c3c29d6925a3fa97cb23791bf.tar.gz
watbot-b6187e007792836c3c29d6925a3fa97cb23791bf.tar.bz2
watbot-b6187e007792836c3c29d6925a3fa97cb23791bf.zip
Merge pull request 'Change host lookup to be optional' (#23) from dbhost into master
Reviewed-on: https://git.com.de/LibertaCasa/watbot/pulls/23
Diffstat (limited to 'wat/db.go')
-rw-r--r--wat/db.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/wat/db.go b/wat/db.go
index 85a598b..8971223 100644
--- a/wat/db.go
+++ b/wat/db.go
@@ -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