Skip to content

Commit

Permalink
Create Blacklist Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Zedjones committed Mar 29, 2020
1 parent dc3e3c4 commit d47bc1e
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions internal/handlers/irc/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package irc

import (
"fmt"
"strings"

"github.com/lrstanley/girc"
)
Expand All @@ -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
Expand All @@ -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)
}
}
}
}
Expand Down

0 comments on commit d47bc1e

Please sign in to comment.