mirror of
https://github.com/google/alertmanager-irc-relay.git
synced 2024-11-16 16:19:21 +01:00
Merge pull request #16 from erikmack/custom-nickserv
Allow customized NickServ and ChanServ
This commit is contained in:
commit
075b84a810
@ -23,6 +23,7 @@ http_port: 8000
|
|||||||
# Connect to this IRC host/port.
|
# Connect to this IRC host/port.
|
||||||
#
|
#
|
||||||
# Note: SSL is enabled by default, use "irc_use_ssl: no" to disable.
|
# 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_host: irc.example.com
|
||||||
irc_port: 7000
|
irc_port: 7000
|
||||||
# Optionally set the server password
|
# Optionally set the server password
|
||||||
@ -75,6 +76,11 @@ nickserv_identify_patterns:
|
|||||||
- "identify via /msg NickServ identify <password>"
|
- "identify via /msg NickServ identify <password>"
|
||||||
- "type /msg NickServ IDENTIFY password"
|
- "type /msg NickServ IDENTIFY password"
|
||||||
- "authenticate yourself to services with the IDENTIFY command"
|
- "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):
|
Running the bot (assuming *$GOPATH* and *$PATH* are properly setup for go):
|
||||||
|
@ -49,7 +49,9 @@ type Config struct {
|
|||||||
UsePrivmsg bool `yaml:"use_privmsg"`
|
UsePrivmsg bool `yaml:"use_privmsg"`
|
||||||
AlertBufferSize int `yaml:"alert_buffer_size"`
|
AlertBufferSize int `yaml:"alert_buffer_size"`
|
||||||
|
|
||||||
|
NickservName string `yaml:"nickserv_name"`
|
||||||
NickservIdentifyPatterns []string `yaml:"nickserv_identify_patterns"`
|
NickservIdentifyPatterns []string `yaml:"nickserv_identify_patterns"`
|
||||||
|
ChanservName string `yaml:"chanserv_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(configFile string) (*Config, error) {
|
func LoadConfig(configFile string) (*Config, error) {
|
||||||
@ -68,12 +70,14 @@ func LoadConfig(configFile string) (*Config, error) {
|
|||||||
MsgOnce: false,
|
MsgOnce: false,
|
||||||
UsePrivmsg: false,
|
UsePrivmsg: false,
|
||||||
AlertBufferSize: 2048,
|
AlertBufferSize: 2048,
|
||||||
|
NickservName: "NickServ",
|
||||||
NickservIdentifyPatterns: []string{
|
NickservIdentifyPatterns: []string{
|
||||||
"Please choose a different nickname, or identify via",
|
"Please choose a different nickname, or identify via",
|
||||||
"identify via /msg NickServ identify <password>",
|
"identify via /msg NickServ identify <password>",
|
||||||
"type /msg NickServ IDENTIFY password",
|
"type /msg NickServ IDENTIFY password",
|
||||||
"authenticate yourself to services with the IDENTIFY command",
|
"authenticate yourself to services with the IDENTIFY command",
|
||||||
},
|
},
|
||||||
|
ChanservName: "ChanServ",
|
||||||
}
|
}
|
||||||
|
|
||||||
if configFile != "" {
|
if configFile != "" {
|
||||||
|
6
irc.go
6
irc.go
@ -82,6 +82,7 @@ type IRCNotifier struct {
|
|||||||
Nick string
|
Nick string
|
||||||
NickPassword string
|
NickPassword string
|
||||||
|
|
||||||
|
NickservName string
|
||||||
NickservIdentifyPatterns []string
|
NickservIdentifyPatterns []string
|
||||||
|
|
||||||
Client *irc.Conn
|
Client *irc.Conn
|
||||||
@ -121,6 +122,7 @@ func NewIRCNotifier(config *Config, alertMsgs chan AlertMsg, delayerMaker Delaye
|
|||||||
notifier := &IRCNotifier{
|
notifier := &IRCNotifier{
|
||||||
Nick: config.IRCNick,
|
Nick: config.IRCNick,
|
||||||
NickPassword: config.IRCNickPass,
|
NickPassword: config.IRCNickPass,
|
||||||
|
NickservName: config.NickservName,
|
||||||
NickservIdentifyPatterns: config.NickservIdentifyPatterns,
|
NickservIdentifyPatterns: config.NickservIdentifyPatterns,
|
||||||
Client: client,
|
Client: client,
|
||||||
AlertMsgs: alertMsgs,
|
AlertMsgs: alertMsgs,
|
||||||
@ -187,7 +189,7 @@ func (n *IRCNotifier) HandleNickservMsg(msg string) {
|
|||||||
logging.Debug("Checking if NickServ message matches identify request '%s'", identifyPattern)
|
logging.Debug("Checking if NickServ message matches identify request '%s'", identifyPattern)
|
||||||
if strings.Contains(cleanedMsg, identifyPattern) {
|
if strings.Contains(cleanedMsg, identifyPattern) {
|
||||||
logging.Info("Handling NickServ request to IDENTIFY")
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -203,7 +205,7 @@ func (n *IRCNotifier) MaybeGhostNick() {
|
|||||||
if currentNick != n.Nick {
|
if currentNick != n.Nick {
|
||||||
logging.Info("My nick is '%s', sending GHOST to NickServ to get '%s'",
|
logging.Info("My nick is '%s', sending GHOST to NickServ to get '%s'",
|
||||||
currentNick, n.Nick)
|
currentNick, n.Nick)
|
||||||
n.Client.Privmsgf("NickServ", "GHOST %s %s", n.Nick,
|
n.Client.Privmsgf(n.NickservName, "GHOST %s %s", n.Nick,
|
||||||
n.NickPassword)
|
n.NickPassword)
|
||||||
time.Sleep(n.NickservDelayWait)
|
time.Sleep(n.NickservDelayWait)
|
||||||
|
|
||||||
|
@ -42,6 +42,8 @@ func makeTestIRCConfig(IRCPort int) *Config {
|
|||||||
NickservIdentifyPatterns: []string{
|
NickservIdentifyPatterns: []string{
|
||||||
"identify yourself ktnxbye",
|
"identify yourself ktnxbye",
|
||||||
},
|
},
|
||||||
|
NickservName: "NickServ",
|
||||||
|
ChanservName: "ChanServ",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ const (
|
|||||||
|
|
||||||
type channelState struct {
|
type channelState struct {
|
||||||
channel IRCChannel
|
channel IRCChannel
|
||||||
|
chanservName string
|
||||||
client *irc.Conn
|
client *irc.Conn
|
||||||
|
|
||||||
delayer Delayer
|
delayer Delayer
|
||||||
@ -44,7 +45,7 @@ type channelState struct {
|
|||||||
mu sync.Mutex
|
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)
|
delayer := delayerMaker.NewDelayer(ircJoinMaxBackoffSecs, ircJoinBackoffResetSecs, time.Second)
|
||||||
|
|
||||||
return &channelState{
|
return &channelState{
|
||||||
@ -55,6 +56,7 @@ func newChannelState(channel *IRCChannel, client *irc.Conn, delayerMaker Delayer
|
|||||||
joinDone: make(chan struct{}),
|
joinDone: make(chan struct{}),
|
||||||
joined: false,
|
joined: false,
|
||||||
joinUnsetSignal: make(chan bool),
|
joinUnsetSignal: make(chan bool),
|
||||||
|
chanservName: chanservName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +108,7 @@ func (c *channelState) join(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to unban ourselves, just in case
|
// 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)
|
c.client.Join(c.channel.Name, c.channel.Password)
|
||||||
logging.Info("Channel %s monitor: join request sent", c.channel.Name)
|
logging.Info("Channel %s monitor: join request sent", c.channel.Name)
|
||||||
@ -156,6 +158,7 @@ type ChannelReconciler struct {
|
|||||||
timeTeller TimeTeller
|
timeTeller TimeTeller
|
||||||
|
|
||||||
channels map[string]*channelState
|
channels map[string]*channelState
|
||||||
|
chanservName string
|
||||||
|
|
||||||
stopCtx context.Context
|
stopCtx context.Context
|
||||||
stopCtxCancel context.CancelFunc
|
stopCtxCancel context.CancelFunc
|
||||||
@ -171,6 +174,7 @@ func NewChannelReconciler(config *Config, client *irc.Conn, delayerMaker Delayer
|
|||||||
delayerMaker: delayerMaker,
|
delayerMaker: delayerMaker,
|
||||||
timeTeller: timeTeller,
|
timeTeller: timeTeller,
|
||||||
channels: make(map[string]*channelState),
|
channels: make(map[string]*channelState),
|
||||||
|
chanservName: config.ChanservName,
|
||||||
}
|
}
|
||||||
|
|
||||||
reconciler.registerHandlers()
|
reconciler.registerHandlers()
|
||||||
@ -227,7 +231,7 @@ func (r *ChannelReconciler) HandleKick(nick string, channel string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *ChannelReconciler) unsafeAddChannel(channel *IRCChannel) *channelState {
|
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)
|
r.stopWg.Add(1)
|
||||||
go c.Monitor(r.stopCtx, &r.stopWg)
|
go c.Monitor(r.stopCtx, &r.stopWg)
|
||||||
|
Loading…
Reference in New Issue
Block a user