Add support for JOIN, PART and CTCP_ACTION

This commit is contained in:
Wim 2015-10-24 16:39:01 +02:00
parent d0cda03478
commit b346ac868b
4 changed files with 22 additions and 3 deletions

View File

@ -56,6 +56,7 @@ channel="#matterbridge"
url="http://mattermost.yourdomain.com/hooks/incomingwebhookkey" url="http://mattermost.yourdomain.com/hooks/incomingwebhookkey"
#port the bridge webserver will listen on #port the bridge webserver will listen on
port=9999 port=9999
showjoinpart=true #show irc users joining and parting
``` ```
### mattermost ### mattermost

View File

@ -16,8 +16,9 @@ type Config struct {
Channel string Channel string
} }
Mattermost struct { Mattermost struct {
URL string URL string
Port int Port int
ShowJoinPart bool
} }
} }

View File

@ -9,3 +9,4 @@ channel="#matterbridge"
[mattermost] [mattermost]
url="http://yourdomain/hooks/yourhookkey" url="http://yourdomain/hooks/yourhookkey"
port=9999 port=9999
showjoinpart=true

View File

@ -6,6 +6,7 @@ import (
"github.com/thoj/go-ircevent" "github.com/thoj/go-ircevent"
"log" "log"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -33,16 +34,31 @@ func (b *Bridge) createIRC(name string) *irc.Connection {
log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick) log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick)
i.Join(b.Config.IRC.Channel) i.Join(b.Config.IRC.Channel)
i.AddCallback("PRIVMSG", b.handlePrivMsg) 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)
}
return i return i
} }
func (b *Bridge) handlePrivMsg(event *irc.Event) { func (b *Bridge) handlePrivMsg(event *irc.Event) {
matterMessage := matterhook.OMessage{} matterMessage := matterhook.OMessage{}
matterMessage.Text = event.Message() if event.Code == "CTCP_ACTION" {
matterMessage.Text = event.Nick + " "
}
matterMessage.Text += event.Message()
matterMessage.UserName = "irc-" + event.Nick matterMessage.UserName = "irc-" + event.Nick
b.m.Send(matterMessage) b.m.Send(matterMessage)
} }
func (b *Bridge) handleJoinPart(event *irc.Event) {
matterMessage := matterhook.OMessage{}
matterMessage.Text = "irc-" + event.Nick + " " + strings.ToLower(event.Code) + "s " + event.Message()
matterMessage.UserName = b.Config.IRC.Nick
b.m.Send(matterMessage)
}
func (b *Bridge) handleMatter() { func (b *Bridge) handleMatter() {
for { for {
message := b.m.Receive() message := b.m.Receive()