dkforest

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

commit 78544966ad6a31dd1e48bf913f51501b63ebea0d
parent a0150f09cfd4a2d1ee363d11b1c2b95a68b9253b
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sat, 17 Dec 2022 23:41:10 -0800

add hbmt command

Diffstat:
Mpkg/web/handlers/api/v1/handlers.go | 1+
Mpkg/web/handlers/api/v1/slashInterceptor.go | 21+++++++++++++++++++++
Mpkg/web/public/views/pages/chat-help.gohtml | 7+++++++
3 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/pkg/web/handlers/api/v1/handlers.go b/pkg/web/handlers/api/v1/handlers.go @@ -41,6 +41,7 @@ var unIgnoreRgx = regexp.MustCompile(`^/(?:unignore|ui) ` + optAtGUser) 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 inboxRgx = regexp.MustCompile(`^/inbox ` + optAtGUser + `(\s-e)?\s(?s:(.*))`) var profileRgx = regexp.MustCompile(`^/p ` + optAtGUserOr0) diff --git a/pkg/web/handlers/api/v1/slashInterceptor.go b/pkg/web/handlers/api/v1/slashInterceptor.go @@ -68,6 +68,7 @@ func handleUserCmd(c *Command) (handled bool) { handleInboxCmd(c) || handleChessCmd(c) || handleHbmCmd(c) || + handleHbmtCmd(c) || handleTokenCmd(c) || handleMd5Cmd(c) || handleSha1Cmd(c) || @@ -354,6 +355,26 @@ func handleHbmCmd(c *Command) (handled bool) { return } +func handleHbmtCmd(c *Command) (handled bool) { + if !c.authUser.CanSeeHB() { + return + } + if m := hbmtRgx.FindStringSubmatch(c.message); len(m) == 2 { + date := m[1] + if dt, err := utils.ParsePrevDatetimeAt(date, clockwork.NewRealClock()); err == nil { + if time.Since(dt) <= config.EditMessageTimeLimit { + if msg, err := database.GetRoomChatMessageByDate(c.room.ID, c.authUser.ID, dt.UTC()); err == nil { + msg.IsHellbanned = !msg.IsHellbanned + msg.DoSave() + } + } + } + c.err = ErrRedirect + return true + } + return +} + func handleDiceCmd(c *Command) (handled bool) { if strings.HasPrefix(c.message, "/dice") { dice := utils.RandInt(1, 6) diff --git a/pkg/web/public/views/pages/chat-help.gohtml b/pkg/web/public/views/pages/chat-help.gohtml @@ -225,6 +225,13 @@ <div> <div> + <code>/hbmt HH:MM:SS</code> + </div> + <p>Will toggle the message at HH:MM:SS between hellban or not</p> + </div> + + <div> + <div> <code>/m some message here</code> </div> <p>Send a message that only moderators users can see.</p>