dkforest

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

commit 33cf646126a863c48c6334030d477abe7c6f2b0b
parent 5175eb22653c51633b5dad3d2b64426405803db8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed, 24 May 2023 08:10:55 -0700

allow to create chess game with wanted color "/chess username b"

Diffstat:
Mpkg/web/handlers/api/v1/handlers.go | 2+-
Mpkg/web/handlers/api/v1/slashInterceptor.go | 6+++++-
2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -45,7 +45,7 @@ var groupRgx = regexp.MustCompile(`^/g (` + groupName + `)\s(?s:(.*))`) var pmRgx = regexp.MustCompile(`^/pm ` + optAtGUserOr0 + `(?:\s(?s:(.*)))?`) var editRgx = regexp.MustCompile(`^/e (` + chatTs + `)\s(?s:(.*))`) var hbmtRgx = regexp.MustCompile(`^/hbmt (` + chatTs + `)$`) -var chessRgx = regexp.MustCompile(`^/chess ` + optAtGUser) +var chessRgx = regexp.MustCompile(`^/chess ` + optAtGUser + `(?:\s(w|b))?`) var inboxRgx = regexp.MustCompile(`^/inbox ` + optAtGUser + `(\s-e)?\s(?s:(.*))`) var purgeRgx = regexp.MustCompile(`^/purge ` + optAtGUserOr0) var renameRgx = regexp.MustCompile(`^/rename ` + optAtGUser + ` ` + optAtGUser) diff --git a/pkg/web/handlers/api/v1/slashInterceptor.go b/pkg/web/handlers/api/v1/slashInterceptor.go @@ -1199,14 +1199,18 @@ func handleTogglePmWhitelistedUser(c *Command) (handled bool) { } func handleChessCmd(c *Command) (handled bool) { - if m := chessRgx.FindStringSubmatch(c.message); len(m) == 2 { + if m := chessRgx.FindStringSubmatch(c.message); len(m) == 3 { username := m[1] + color := m[2] player1 := *c.authUser player2, err := c.db.GetUserByUsername(username) if err != nil { c.err = errors.New("invalid username") return true } + if color == "b" { + player1, player2 = player2, player1 + } if _, err := ChessInstance.NewGame1(c.roomKey, c.room.ID, player1, player2); err != nil { c.err = err return true