summaryrefslogtreecommitdiffstats
path: root/matterbridge.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2015-12-19 16:55:49 +0100
committerWim <wim@42.be>2015-12-19 16:55:49 +0100
commit9f07a2cfd5d76e2acbd984e351097559279443b8 (patch)
treed9d991e15d3e433f47b5cf5fc8444c1d9f0fc08b /matterbridge.go
parent0dc5e042d2aafd4f9e06422c959898ed7dbb08c8 (diff)
downloadmatterbridge-msglm-9f07a2cfd5d76e2acbd984e351097559279443b8.tar.gz
matterbridge-msglm-9f07a2cfd5d76e2acbd984e351097559279443b8.tar.bz2
matterbridge-msglm-9f07a2cfd5d76e2acbd984e351097559279443b8.zip
Add support for multiple channels
Diffstat (limited to 'matterbridge.go')
-rw-r--r--matterbridge.go49
1 files changed, 39 insertions, 10 deletions
diff --git a/matterbridge.go b/matterbridge.go
index b301a94f..59165dfa 100644
--- a/matterbridge.go
+++ b/matterbridge.go
@@ -13,14 +13,21 @@ import (
)
type Bridge struct {
- i *irc.Connection
- m *matterhook.Client
+ i *irc.Connection
+ m *matterhook.Client
+ cmap map[string]string
*Config
}
func NewBridge(name string, config *Config) *Bridge {
b := &Bridge{}
b.Config = config
+ b.cmap = make(map[string]string)
+ if len(b.Config.Token) > 0 {
+ for _, val := range b.Config.Token {
+ b.cmap[val.IRCChannel] = val.MMChannel
+ }
+ }
b.m = matterhook.New(b.Config.Mattermost.URL,
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
@@ -38,13 +45,17 @@ func (b *Bridge) createIRC(name string) *irc.Connection {
time.Sleep(time.Second)
log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick)
i.Join(b.Config.IRC.Channel)
+ for _, val := range b.Config.Token {
+ log.Println("Joining", val.IRCChannel, "as", b.Config.IRC.Nick)
+ i.Join(val.IRCChannel)
+ }
i.AddCallback("PRIVMSG", b.handlePrivMsg)
i.AddCallback("CTCP_ACTION", b.handlePrivMsg)
if b.Config.Mattermost.ShowJoinPart {
i.AddCallback("JOIN", b.handleJoinPart)
i.AddCallback("PART", b.handleJoinPart)
}
- i.AddCallback("353", b.handleOther)
+ //i.AddCallback("353", b.handleOther)
return i
}
@@ -54,18 +65,19 @@ func (b *Bridge) handlePrivMsg(event *irc.Event) {
msg = event.Nick + " "
}
msg += event.Message()
- b.Send("irc-"+event.Nick, msg, b.Config.Mattermost.Channel)
+ b.Send("irc-"+event.Nick, msg, b.getMMChannel(event.Arguments[0]))
}
func (b *Bridge) handleJoinPart(event *irc.Event) {
- b.SendType(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(),
- b.Config.Mattermost.Channel, "join_leave")
+ b.Send(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]))
+ //b.SendType(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]), "join_leave")
}
func (b *Bridge) handleOther(event *irc.Event) {
switch event.Code {
case "353":
- b.Send(b.Config.IRC.Nick, event.Message()+" currently on IRC", b.Config.Mattermost.Channel)
+ log.Println("handleOther", b.getMMChannel(event.Arguments[0]))
+ b.Send(b.Config.IRC.Nick, event.Message()+" currently on IRC", b.getMMChannel(event.Arguments[0]))
}
}
@@ -94,14 +106,14 @@ func (b *Bridge) handleMatter() {
switch cmd {
case "!users":
log.Println("received !users from", message.UserName)
- b.i.SendRaw("NAMES " + b.Config.IRC.Channel)
+ b.i.SendRaw("NAMES " + b.getIRCChannel(message.Token))
case "!gif":
message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1)))
- b.Send(b.Config.IRC.Nick, message.Text, b.Config.Mattermost.Channel)
+ b.Send(b.Config.IRC.Nick, message.Text, b.getIRCChannel(message.Token))
}
texts := strings.Split(message.Text, "\n")
for _, text := range texts {
- b.i.Privmsg(b.Config.IRC.Channel, message.UserName+": "+text)
+ b.i.Privmsg(b.getIRCChannel(message.Token), message.UserName+": "+text)
}
}
}
@@ -118,6 +130,23 @@ func (b *Bridge) giphyRandom(query []string) string {
return res.Data.FixedHeightDownsampledURL
}
+func (b *Bridge) getMMChannel(ircChannel string) string {
+ mmchannel, ok := b.cmap[ircChannel]
+ if !ok {
+ mmchannel = b.Config.Mattermost.Channel
+ }
+ return mmchannel
+}
+
+func (b *Bridge) getIRCChannel(token string) string {
+ ircchannel := b.Config.IRC.Channel
+ _, ok := b.Config.Token[token]
+ if ok {
+ ircchannel = b.Config.Token[token].IRCChannel
+ }
+ return ircchannel
+}
+
func main() {
flagConfig := flag.String("conf", "matterbridge.conf", "config file")
flag.Parse()