dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 07faaddbdae57cc784ebec7b4d54523635a70db1
parent 930c5195d3a2ad432ee804c8d770440f1da3ae83
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 18 Feb 2025 16:01:04 -0800

cleanup code

Diffstat:
Mpkg/database/utils/utils.go | 4+---
Mpkg/web/handlers/interceptors/battleship.go | 4++--
Mpkg/web/handlers/interceptors/chess.go | 2+-
Mpkg/web/handlers/interceptors/werewolf.go | 3+--
Mpkg/web/handlers/signup.go | 12++++++------
5 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/pkg/database/utils/utils.go b/pkg/database/utils/utils.go @@ -13,9 +13,7 @@ import ( func GetZeroUser(db *database.DkfDB) database.User { zeroUser, err := db.GetUserByUsername(config.NullUsername) - if err != nil { - logrus.Error(err) - } + utils.LogErr(err) return zeroUser } diff --git a/pkg/web/handlers/interceptors/battleship.go b/pkg/web/handlers/interceptors/battleship.go @@ -2,8 +2,8 @@ package interceptors import ( "bytes" - "dkforest/pkg/config" "dkforest/pkg/database" + dutils "dkforest/pkg/database/utils" "dkforest/pkg/utils" "dkforest/pkg/web/handlers/interceptors/command" "encoding/base64" @@ -220,7 +220,7 @@ type Battleship struct { } func NewBattleship(db *database.DkfDB) *Battleship { - zeroUser, _ := db.GetUserByUsername(config.NullUsername) + zeroUser := dutils.GetZeroUser(db) b := &Battleship{db: db, zeroID: zeroUser.ID} b.games = make(map[string]*BSGame) diff --git a/pkg/web/handlers/interceptors/chess.go b/pkg/web/handlers/interceptors/chess.go @@ -133,7 +133,7 @@ type Chess struct { } func NewChess(db *database.DkfDB) *Chess { - zeroUser, _ := db.GetUserByUsername(config.NullUsername) + zeroUser := dutils.GetZeroUser(db) c := &Chess{db: db, zeroID: zeroUser.ID} c.games = make(map[string]*ChessGame) diff --git a/pkg/web/handlers/interceptors/werewolf.go b/pkg/web/handlers/interceptors/werewolf.go @@ -3,7 +3,6 @@ package interceptors import ( "bytes" "context" - "dkforest/pkg/config" "dkforest/pkg/database" dutils "dkforest/pkg/database/utils" "dkforest/pkg/hashset" @@ -683,7 +682,7 @@ func NewWerewolf(db *database.DkfDB) *Werewolf { logrus.Error("#werewolf room not found") return nil } - zeroUser, _ := db.GetUserByUsername(config.NullUsername) + zeroUser := dutils.GetZeroUser(db) _ = db.DeleteChatRoomGroups(room.ID) werewolfGroup, _ := db.CreateChatRoomGroup(room.ID, "werewolf", "#ffffff") werewolfGroup.Locked = true diff --git a/pkg/web/handlers/signup.go b/pkg/web/handlers/signup.go @@ -6,6 +6,7 @@ import ( "dkforest/pkg/captcha" "dkforest/pkg/config" "dkforest/pkg/database" + dutils "dkforest/pkg/database/utils" "dkforest/pkg/utils" hutils "dkforest/pkg/web/handlers/utils" "encoding/json" @@ -181,13 +182,12 @@ func signupHandler(c echo.Context) error { settings.SignupEnabled = false settings.DoSave(db) config.SignupEnabled.SetFalse() - if userNull, err := db.GetUserByUsername(config.NullUsername); err == nil { - db.NewAudit(userNull, fmt.Sprintf("auto turn off signup")) + userNull := dutils.GetZeroUser(db) + db.NewAudit(userNull, fmt.Sprintf("auto turn off signup")) - // Display message in chat - txt := fmt.Sprintf("auto turn off registrations") - utils.LogErr(db.CreateSysMsg(txt, txt, "", config.GeneralRoomID, userNull.ID)) - } + // Display message in chat + txt := fmt.Sprintf("auto turn off registrations") + utils.LogErr(db.CreateSysMsg(txt, txt, "", config.GeneralRoomID, userNull.ID)) } c.SetCookie(hutils.DeleteCookie(hutils.WaitCookieName))