mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-11-27 05:29:44 +01:00
Allow customized NickServ and ChanServ
This commit is contained in:
parent
f7034fa2c2
commit
8342a1be9d
@ -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 <password>"
|
||||
- "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):
|
||||
|
@ -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 <password>",
|
||||
"type /msg NickServ IDENTIFY password",
|
||||
"authenticate yourself to services with the IDENTIFY command",
|
||||
},
|
||||
ChanservName: "ChanServ",
|
||||
}
|
||||
|
||||
if configFile != "" {
|
||||
|
6
irc.go
6
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)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user