diff options
author | Wim <wim@42.be> | 2015-10-23 22:34:37 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2015-10-23 22:34:37 +0200 |
commit | cbd01d4a552f05f36ef3d8b259c4305cd3ce06c8 (patch) | |
tree | b7088d7478c7e767113e4014aceba872475b7e1b /matterbridge.go | |
parent | 74d0d3fd5ba5e9b7e9ef90e5c2621fb28f4a8a53 (diff) | |
download | matterbridge-msglm-cbd01d4a552f05f36ef3d8b259c4305cd3ce06c8.tar.gz matterbridge-msglm-cbd01d4a552f05f36ef3d8b259c4305cd3ce06c8.tar.bz2 matterbridge-msglm-cbd01d4a552f05f36ef3d8b259c4305cd3ce06c8.zip |
Initial matterbridge commit
Diffstat (limited to 'matterbridge.go')
-rw-r--r-- | matterbridge.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/matterbridge.go b/matterbridge.go new file mode 100644 index 00000000..4ba3c00a --- /dev/null +++ b/matterbridge.go @@ -0,0 +1,56 @@ +package main + +import ( + "crypto/tls" + "github.com/42wim/matterbridge/matterhook" + "github.com/thoj/go-ircevent" + "log" + "strconv" + "time" +) + +type Bridge struct { + i *irc.Connection + m *matterhook.Client + *Config +} + +func NewBridge(name string, config *Config) *Bridge { + b := &Bridge{} + b.Config = config + b.m = matterhook.New(b.Config.Mattermost.URL, matterhook.Config{Port: b.Config.Mattermost.Port}) + b.i = b.createIRC(name) + go b.handleMatter() + return b +} + +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 + 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) + log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick) + i.Join(b.Config.IRC.Channel) + i.AddCallback("PRIVMSG", b.handlePrivMsg) + return i +} + +func (b *Bridge) handlePrivMsg(event *irc.Event) { + matterMessage := matterhook.OMessage{} + matterMessage.Text = event.Message() + matterMessage.UserName = "irc-" + event.Nick + b.m.Send(matterMessage) +} + +func (b *Bridge) handleMatter() { + for { + message := b.m.Receive() + b.i.Privmsg(b.Config.IRC.Channel, message.UserName+": "+message.Text) + } +} + +func main() { + NewBridge("matterbot", NewConfig("matterbridge.conf")) + select {} +} |