diff options
author | Fredrik de Vibe <fredrik.devibe@theqtcompany.com> | 2016-03-21 19:28:16 +0100 |
---|---|---|
committer | Fredrik de Vibe <fredrik.devibe@theqtcompany.com> | 2016-03-21 23:52:10 +0100 |
commit | 69b534ee99972316f0cb14135599dcd1d4682499 (patch) | |
tree | 01d276567a44a3f22234af9b239bb67b3d29b00b | |
parent | 71a504945bac791391d11c022ebc4849e4110a3b (diff) | |
download | matterbridge-msglm-69b534ee99972316f0cb14135599dcd1d4682499.tar.gz matterbridge-msglm-69b534ee99972316f0cb14135599dcd1d4682499.tar.bz2 matterbridge-msglm-69b534ee99972316f0cb14135599dcd1d4682499.zip |
Add Freenode style NickServ-based authentication.
If the server sends a NOTICE requesting identification, identify.
-rw-r--r-- | config.go | 2 | ||||
-rw-r--r-- | matterbridge.go | 37 |
2 files changed, 26 insertions, 13 deletions
@@ -16,6 +16,8 @@ type Config struct { Password string Channel string UseSlackCircumfix bool + NickServNick string + NickServPassword string } Mattermost struct { URL string diff --git a/matterbridge.go b/matterbridge.go index 89c1eb7b..9570c21a 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -12,18 +12,19 @@ import ( ) type Bridge struct { - i *irc.Connection - m *matterhook.Client - cmap map[string]string + i *irc.Connection + m *matterhook.Client + cmap map[string]string + ircNick string + ircNickPass string *Config - ircnick string } func NewBridge(name string, config *Config) *Bridge { b := &Bridge{} b.Config = config b.cmap = make(map[string]string) - b.ircnick = b.Config.IRC.Nick + b.ircNick = b.Config.IRC.Nick if len(b.Config.Token) > 0 { for _, val := range b.Config.Token { b.cmap[val.IRCChannel] = val.MMChannel @@ -51,16 +52,16 @@ func (b *Bridge) createIRC(name string) *irc.Connection { } func (b *Bridge) handleNewConnection(event *irc.Event) { - b.ircnick = event.Arguments[0] + b.ircNick = event.Arguments[0] b.setupChannels() } func (b *Bridge) setupChannels() { i := b.i - log.Println("Joining", b.Config.IRC.Channel, "as", b.ircnick) + log.Println("Joining", b.Config.IRC.Channel, "as", b.ircNick) i.Join(b.Config.IRC.Channel) for _, val := range b.Config.Token { - log.Println("Joining", val.IRCChannel, "as", b.ircnick) + log.Println("Joining", val.IRCChannel, "as", b.ircNick) i.Join(val.IRCChannel) } i.AddCallback("PRIVMSG", b.handlePrivMsg) @@ -81,8 +82,14 @@ func (b *Bridge) handlePrivMsg(event *irc.Event) { } func (b *Bridge) handleJoinPart(event *irc.Event) { - b.Send(b.ircnick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0])) - //b.SendType(b.ircnick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]), "join_leave") + b.Send(b.ircNick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0])) + //b.SendType(b.ircNick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]), "join_leave") +} + +func (b *Bridge) handleNotice(event *irc.Event) { + if (strings.Contains(event.Message(), "This nickname is registered")) { + b.i.Privmsg(b.Config.IRC.NickServNick, "IDENTIFY " + b.Config.IRC.NickServPassword) + } } func tableformatter (nicks_s string, nicksPerRow int) string { @@ -131,10 +138,14 @@ func (b *Bridge) handleOther(event *irc.Event) { b.handleNewConnection(event) case "353": log.Println("handleOther", b.getMMChannel(event.Arguments[0])) - b.Send(b.ircnick, b.formatnicks(event.Message()), b.getMMChannel(event.Arguments[0])) + b.Send(b.ircNick, b.formatnicks(event.Message()), b.getMMChannel(event.Arguments[0])) + case "NOTICE": + b.handleNotice(event) default: - log.Printf("got unknown event: %+v\n", event); + log.Printf("UNKNOWN EVENT: %+v\n", event); + return } + log.Printf("%+v\n", event); } func (b *Bridge) Send(nick string, message string, channel string) error { @@ -194,7 +205,7 @@ func (b *Bridge) handleMatter() { return case "!gif": message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1))) - b.Send(b.ircnick, message.Text, b.getIRCChannel(message.Token)) + b.Send(b.ircNick, message.Text, b.getIRCChannel(message.Token)) return } texts := strings.Split(message.Text, "\n") |