From f48b103a529d3b2f234b5d65eceb79e6e05c3b9f Mon Sep 17 00:00:00 2001 From: soup Date: Mon, 2 Sep 2024 13:00:30 +0200 Subject: [PATCH] feat(irc): allow lazy announcer nicks (#1322) * feat(irc): allow lazy announcer nicks * fix web * fix: indents * fix: add missing entries * feat: extend announcer validation with digit suffix support this reverts the previous commits * feat(irc): allow lazy announcer match * fix(irc): imports --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com> --- internal/irc/handler.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/irc/handler.go b/internal/irc/handler.go index f554c2b..96bdf90 100644 --- a/internal/irc/handler.go +++ b/internal/irc/handler.go @@ -6,7 +6,6 @@ package irc import ( "crypto/tls" "fmt" - "golang.org/x/net/proxy" "net/url" "slices" "strings" @@ -26,6 +25,7 @@ import ( "github.com/r3labs/sse/v2" "github.com/rs/zerolog" "github.com/sasha-s/go-deadlock" + "golang.org/x/net/proxy" ) var ( @@ -1019,8 +1019,24 @@ func (h *Handler) isValidAnnouncer(nick string) bool { h.m.RLock() defer h.m.RUnlock() - _, ok := h.validAnnouncers[strings.ToLower(nick)] - return ok + nick = strings.ToLower(nick) + for announcer := range h.validAnnouncers { + if nick == announcer { + return true + } + + // Confirm if the nickname starts with the announcer and comprises one additional character + if strings.HasPrefix(nick, announcer) && len(nick) == len(announcer)+1 { + return true + } + + // Verify if the nickname concludes with an asterisk and holds the correct prefix + if strings.HasSuffix(announcer, "*") && strings.HasPrefix(nick, announcer) { + return true + } + } + + return false } // check if channel is one from the list in the definition