From d47bc1e7407d770d7639f435ca0dae905a63caa0 Mon Sep 17 00:00:00 2001 From: Nicholas Jones Date: Sun, 29 Mar 2020 13:51:29 -0400 Subject: [PATCH] Create Blacklist Handler --- internal/handlers/irc/handlers.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/internal/handlers/irc/handlers.go b/internal/handlers/irc/handlers.go index 3d75b871..f32da418 100644 --- a/internal/handlers/irc/handlers.go +++ b/internal/handlers/irc/handlers.go @@ -2,6 +2,7 @@ package irc import ( "fmt" + "strings" "github.com/lrstanley/girc" ) @@ -19,6 +20,19 @@ handles an IRC event */ type Handler = func(c Client) func(*girc.Client, girc.Event) +/* +checkBlacklist checks the IRC blacklist for a name, and returns whether +or not the name is in the blacklist +*/ +func checkBlacklist(c Client, toCheck string) bool { + for _, name := range c.Settings.IRCBlacklist { + if strings.EqualFold(toCheck, name) { + return true + } + } + return false +} + /* connectHandler returns a function to use as the connect handler for girc, so that the specified channel is joined after the server connection is established @@ -41,9 +55,12 @@ and channel messages. However, it only cares about channel messages func messageHandler(c Client) func(*girc.Client, girc.Event) { return func(gc *girc.Client, e girc.Event) { c.logger.LogDebug("messageHandler triggered") - formatted := c.Settings.Prefix + e.Source.Name + c.Settings.Suffix + " " + e.Params[1] - if e.IsFromChannel() { - c.sendToTg(formatted) + // Only send if user is not in blacklist + if !(checkBlacklist(c, e.Source.Name)) { + formatted := c.Settings.Prefix + e.Source.Name + c.Settings.Suffix + " " + e.Params[1] + if e.IsFromChannel() { + c.sendToTg(formatted) + } } } }