dkforest

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

commit a33280069588ea007845c8c9592aeb4091a1045e
parent 7560b94776a1b4ea2407cbcd8d898dffceaa18be
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Wed,  6 Dec 2023 06:38:52 -0500

set chips

Diffstat:
Mpkg/web/handlers/interceptors/msgInterceptor.go | 1+
Mpkg/web/handlers/interceptors/slashInterceptor.go | 28++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/interceptors/msgInterceptor.go b/pkg/web/handlers/interceptors/msgInterceptor.go @@ -78,6 +78,7 @@ var memeRenameRgx = regexp.MustCompile(`^/meme ([a-zA-Z0-9_-]{3,50}) ([a-zA-Z0-9 var memeRemoveRgx = regexp.MustCompile(`^/memerm ([a-zA-Z0-9_-]{3,50})$`) var memesRgx = regexp.MustCompile(`^/memes$`) var locateRgx = regexp.MustCompile(`^/locate ` + optAtGUser) +var chipsRgx = regexp.MustCompile(`^/chips ` + optAtGUser + ` (\d+)`) type MsgInterceptor struct{} diff --git a/pkg/web/handlers/interceptors/slashInterceptor.go b/pkg/web/handlers/interceptors/slashInterceptor.go @@ -83,6 +83,7 @@ var userCmdsMap = map[string]CmdHandler{ "/code": handleCodeCmd, "/locate": handleLocateCmd, "/error": handleErrorCmd, + "/chips": handleChipsBalanceCmd, } var privateRoomCmdsMap = map[string]CmdHandler{ @@ -136,6 +137,7 @@ var adminCmdsMap = map[string]CmdHandler{ "/meme": handleNewMeme, "/memerm": handleRemoveMeme, "/refresh": handleRefreshCmd, + "/chips": handleChipsCmd, } func (i SlashInterceptor) InterceptMsg(c *command.Command) { @@ -1294,6 +1296,15 @@ func handleProfileCmd(c *command.Command) (handled bool) { return } +func handleChipsBalanceCmd(c *command.Command) (handled bool) { + if c.Message == "/chips" { + c.ZeroMsg(fmt.Sprintf(`Balance: %d`, c.AuthUser.ChipsTest)) + c.Err = command.ErrRedirect + return true + } + return +} + func handleTutorialCmd(c *command.Command) (handled bool) { if c.Message == "/tuto" && false { name := "tuto_" + utils.GenerateToken10() @@ -1727,6 +1738,23 @@ func handleRefreshCmd(c *command.Command) (handled bool) { return } +func handleChipsCmd(c *command.Command) (handled bool) { + if m := chipsRgx.FindStringSubmatch(c.Message); len(m) == 3 { + username := database.Username(m[1]) + chips := utils.DoParseInt64(m[2]) + user, err := c.DB.GetUserByUsername(username) + if err != nil { + c.Err = errors.New("username does not exists") + return true + } + user.ChipsTest = int(chips) + user.DoSave(c.DB) + c.Err = command.NewErrSuccess("chips set") + return true + } + return +} + func handleLocateCmd(c *command.Command) (handled bool) { if m := locateRgx.FindStringSubmatch(c.Message); len(m) == 2 { username := database.Username(m[1])