From 8342a1be9da0a49677a11f09c58e5fb2d0f9ce7e Mon Sep 17 00:00:00 2001 From: Erik Mackdanz Date: Sat, 8 Oct 2022 11:02:16 -0500 Subject: [PATCH] Allow customized NickServ and ChanServ --- README.md | 6 ++++++ config.go | 4 ++++ irc.go | 6 ++++-- reconciler.go | 10 +++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 42761e2..77a2a19 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ http_port: 8000 # Connect to this IRC host/port. # # Note: SSL is enabled by default, use "irc_use_ssl: no" to disable. +# Set "irc_verify_ssl: no" to accept invalid SSL certificates (not recommended) irc_host: irc.example.com irc_port: 7000 # Optionally set the server password @@ -75,6 +76,11 @@ nickserv_identify_patterns: - "identify via /msg NickServ identify " - "type /msg NickServ IDENTIFY password" - "authenticate yourself to services with the IDENTIFY command" + +# Rarely NickServ or ChanServ is reached at a specific hostname. Specify an +# override here +nickserv_name: NickServ +chanserv_name: ChanServ ``` Running the bot (assuming *$GOPATH* and *$PATH* are properly setup for go): diff --git a/config.go b/config.go index fa83644..3308595 100644 --- a/config.go +++ b/config.go @@ -49,7 +49,9 @@ type Config struct { UsePrivmsg bool `yaml:"use_privmsg"` AlertBufferSize int `yaml:"alert_buffer_size"` + NickservName string `yaml:"nickserv_name"` NickservIdentifyPatterns []string `yaml:"nickserv_identify_patterns"` + ChanservName string `yaml:"chanserv_name"` } func LoadConfig(configFile string) (*Config, error) { @@ -68,12 +70,14 @@ func LoadConfig(configFile string) (*Config, error) { MsgOnce: false, UsePrivmsg: false, AlertBufferSize: 2048, + NickservName: "NickServ", NickservIdentifyPatterns: []string{ "Please choose a different nickname, or identify via", "identify via /msg NickServ identify ", "type /msg NickServ IDENTIFY password", "authenticate yourself to services with the IDENTIFY command", }, + ChanservName: "ChanServ", } if configFile != "" { diff --git a/irc.go b/irc.go index addde02..daf1abf 100644 --- a/irc.go +++ b/irc.go @@ -82,6 +82,7 @@ type IRCNotifier struct { Nick string NickPassword string + NickservName string NickservIdentifyPatterns []string Client *irc.Conn @@ -121,6 +122,7 @@ func NewIRCNotifier(config *Config, alertMsgs chan AlertMsg, delayerMaker Delaye notifier := &IRCNotifier{ Nick: config.IRCNick, NickPassword: config.IRCNickPass, + NickservName: config.NickservName, NickservIdentifyPatterns: config.NickservIdentifyPatterns, Client: client, AlertMsgs: alertMsgs, @@ -187,7 +189,7 @@ func (n *IRCNotifier) HandleNickservMsg(msg string) { logging.Debug("Checking if NickServ message matches identify request '%s'", identifyPattern) if strings.Contains(cleanedMsg, identifyPattern) { logging.Info("Handling NickServ request to IDENTIFY") - n.Client.Privmsgf("NickServ", "IDENTIFY %s", n.NickPassword) + n.Client.Privmsgf(n.NickservName, "IDENTIFY %s", n.NickPassword) return } } @@ -203,7 +205,7 @@ func (n *IRCNotifier) MaybeGhostNick() { if currentNick != n.Nick { logging.Info("My nick is '%s', sending GHOST to NickServ to get '%s'", currentNick, n.Nick) - n.Client.Privmsgf("NickServ", "GHOST %s %s", n.Nick, + n.Client.Privmsgf(n.NickservName, "GHOST %s %s", n.Nick, n.NickPassword) time.Sleep(n.NickservDelayWait) diff --git a/reconciler.go b/reconciler.go index 2194204..68789fe 100644 --- a/reconciler.go +++ b/reconciler.go @@ -31,6 +31,7 @@ const ( type channelState struct { channel IRCChannel + chanservName string client *irc.Conn delayer Delayer @@ -44,7 +45,7 @@ type channelState struct { mu sync.Mutex } -func newChannelState(channel *IRCChannel, client *irc.Conn, delayerMaker DelayerMaker, timeTeller TimeTeller) *channelState { +func newChannelState(channel *IRCChannel, client *irc.Conn, delayerMaker DelayerMaker, timeTeller TimeTeller, chanservName string) *channelState { delayer := delayerMaker.NewDelayer(ircJoinMaxBackoffSecs, ircJoinBackoffResetSecs, time.Second) return &channelState{ @@ -55,6 +56,7 @@ func newChannelState(channel *IRCChannel, client *irc.Conn, delayerMaker Delayer joinDone: make(chan struct{}), joined: false, joinUnsetSignal: make(chan bool), + chanservName: chanservName, } } @@ -106,7 +108,7 @@ func (c *channelState) join(ctx context.Context) { } // Try to unban ourselves, just in case - c.client.Privmsgf("ChanServ", "UNBAN %s", c.channel.Name) + c.client.Privmsgf(c.chanservName, "UNBAN %s", c.channel.Name) c.client.Join(c.channel.Name, c.channel.Password) logging.Info("Channel %s monitor: join request sent", c.channel.Name) @@ -156,6 +158,7 @@ type ChannelReconciler struct { timeTeller TimeTeller channels map[string]*channelState + chanservName string stopCtx context.Context stopCtxCancel context.CancelFunc @@ -171,6 +174,7 @@ func NewChannelReconciler(config *Config, client *irc.Conn, delayerMaker Delayer delayerMaker: delayerMaker, timeTeller: timeTeller, channels: make(map[string]*channelState), + chanservName: config.ChanservName, } reconciler.registerHandlers() @@ -227,7 +231,7 @@ func (r *ChannelReconciler) HandleKick(nick string, channel string) { } func (r *ChannelReconciler) unsafeAddChannel(channel *IRCChannel) *channelState { - c := newChannelState(channel, r.client, r.delayerMaker, r.timeTeller) + c := newChannelState(channel, r.client, r.delayerMaker, r.timeTeller, r.chanservName) r.stopWg.Add(1) go c.Monitor(r.stopCtx, &r.stopWg)