diff --git a/config.go b/config.go index ecdf65fa..84a46ebc 100644 --- a/config.go +++ b/config.go @@ -13,7 +13,9 @@ type Config struct { Server string Port int Nick string + Password string Channel string + SendMUserName bool } Mattermost struct { URL string @@ -22,6 +24,7 @@ type Config struct { Token string IconURL string SkipTLSVerify bool + IrcNickPrefix string } General struct { GiphyAPIKey string diff --git a/matterbridge.conf.sample b/matterbridge.conf.sample index f910e019..59b04907 100644 --- a/matterbridge.conf.sample +++ b/matterbridge.conf.sample @@ -5,6 +5,8 @@ UseTLS=false SkipTLSVerify=true nick="matterbot" channel="#matterbridge" +password="" +SendMUserName=true [mattermost] url="http://yourdomain/hooks/yourhookkey" @@ -13,6 +15,7 @@ showjoinpart=true #token=yourtokenfrommattermost IconURL="http://youricon.png" #SkipTLSVerify=true +IrcNickPrefix="irc-" [general] GiphyAPIKey=dc6zaTOxFJmzC diff --git a/matterbridge.go b/matterbridge.go index 8e669c54..18bb472c 100644 --- a/matterbridge.go +++ b/matterbridge.go @@ -31,6 +31,7 @@ func NewBridge(name string, config *Config) *Bridge { func (b *Bridge) createIRC(name string) *irc.Connection { i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick) i.UseTLS = b.Config.IRC.UseTLS + if b.Config.IRC.Password != "" { i.Password = b.Config.IRC.Password } i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify} i.Connect(b.Config.IRC.Server + ":" + strconv.Itoa(b.Config.IRC.Port)) time.Sleep(time.Second) @@ -52,11 +53,11 @@ func (b *Bridge) handlePrivMsg(event *irc.Event) { msg = event.Nick + " " } msg += event.Message() - b.Send("irc-"+event.Nick, msg) + b.Send(b.Config.Mattermost.IrcNickPrefix+event.Nick, "PRIV: "+msg) } func (b *Bridge) handleJoinPart(event *irc.Event) { - b.Send(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message()) + b.Send(b.Config.IRC.Nick, b.Config.Mattermost.IrcNickPrefix+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message()) } func (b *Bridge) handleOther(event *irc.Event) { @@ -89,10 +90,19 @@ func (b *Bridge) handleMatter() { case "!gif": message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1))) b.Send(b.Config.IRC.Nick, message.Text) + case "!priv": + who := strings.Fields(message.Text)[1] + msg := strings.Fields(message.Text)[2:] + b.i.Privmsg(who, strings.Join(msg, " ")) + continue } texts := strings.Split(message.Text, "\n") for _, text := range texts { - b.i.Privmsg(b.Config.IRC.Channel, message.UserName+": "+text) + if (b.Config.IRC.SendMUserName) { + b.i.Privmsg(b.Config.IRC.Channel, message.UserName+": "+text) + } else { + b.i.Privmsg(b.Config.IRC.Channel, text) + } } } }