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>
This commit is contained in:
soup 2024-09-02 13:00:30 +02:00 committed by GitHub
parent 46b3ae8a0f
commit f48b103a52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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