diff options
author | Wim <wim@42.be> | 2016-11-05 01:11:28 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2016-11-05 01:11:51 +0100 |
commit | 2dbe0eb55729620ffdfdb7e4f10003564d79c7e1 (patch) | |
tree | 65e5309a42c1cee478b5b0c8448c36d819c9d41a /bridge | |
parent | 50a0df427927b60724d8e6e00ba06822e0aa7308 (diff) | |
download | matterbridge-msglm-2dbe0eb55729620ffdfdb7e4f10003564d79c7e1.tar.gz matterbridge-msglm-2dbe0eb55729620ffdfdb7e4f10003564d79c7e1.tar.bz2 matterbridge-msglm-2dbe0eb55729620ffdfdb7e4f10003564d79c7e1.zip |
Add support for dynamic IconURL (slack). Closes #43
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/config/config.go | 16 | ||||
-rw-r--r-- | bridge/discord/discord.go | 3 | ||||
-rw-r--r-- | bridge/gitter/gitter.go | 3 | ||||
-rw-r--r-- | bridge/irc/irc.go | 3 | ||||
-rw-r--r-- | bridge/mattermost/mattermost.go | 8 | ||||
-rw-r--r-- | bridge/slack/slack.go | 28 | ||||
-rw-r--r-- | bridge/xmpp/xmpp.go | 3 |
7 files changed, 47 insertions, 17 deletions
diff --git a/bridge/config/config.go b/bridge/config/config.go index 89222894..32c8c74f 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -122,3 +122,19 @@ func OverrideCfgFromEnv(cfg *Config, protocol string, account string) { } } } + +func GetIconURL(msg *Message, cfg *Protocol) string { + iconURL := cfg.IconURL + iconURL = strings.Replace(iconURL, "{NICK}", msg.Username, -1) + iconURL = strings.Replace(iconURL, "{BRIDGE}", msg.Origin, -1) + iconURL = strings.Replace(iconURL, "{PROTOCOL}", msg.Protocol, -1) + return iconURL +} + +func GetNick(msg *Message, cfg *Protocol) string { + nick := cfg.RemoteNickFormat + nick = strings.Replace(nick, "{NICK}", msg.Username, -1) + nick = strings.Replace(nick, "{BRIDGE}", msg.Origin, -1) + nick = strings.Replace(nick, "{PROTOCOL}", msg.Protocol, -1) + return nick +} diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 446977ad..7995a06d 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -103,7 +103,8 @@ func (b *bdiscord) Send(msg config.Message) error { flog.Errorf("Could not find channelID for %v", msg.Channel) return nil } - b.c.ChannelMessageSend(channelID, msg.Username+msg.Text) + nick := config.GetNick(&msg, b.Config) + b.c.ChannelMessageSend(channelID, nick+msg.Text) return nil } diff --git a/bridge/gitter/gitter.go b/bridge/gitter/gitter.go index 95c41af4..5daf7773 100644 --- a/bridge/gitter/gitter.go +++ b/bridge/gitter/gitter.go @@ -105,8 +105,9 @@ func (b *Bgitter) Send(msg config.Message) error { flog.Errorf("Could not find roomID for %v", msg.Channel) return nil } + nick := config.GetNick(&msg, b.Config) // add ZWSP because gitter echoes our own messages - return b.c.SendMessage(roomID, msg.Username+msg.Text+" ") + return b.c.SendMessage(roomID, nick+msg.Text+" ") } func (b *Bgitter) getRoomID(channel string) string { diff --git a/bridge/irc/irc.go b/bridge/irc/irc.go index 30f27724..61b55dab 100644 --- a/bridge/irc/irc.go +++ b/bridge/irc/irc.go @@ -123,12 +123,13 @@ func (b *Birc) Send(msg config.Message) error { b.Command(&msg) return nil } + nick := config.GetNick(&msg, b.Config) for _, text := range strings.Split(msg.Text, "\n") { if len(b.Local) < b.Config.MessageQueue { if len(b.Local) == b.Config.MessageQueue-1 { text = text + " <message clipped>" } - b.Local <- config.Message{Text: text, Username: msg.Username, Channel: msg.Channel} + b.Local <- config.Message{Text: text, Username: nick, Channel: msg.Channel} } else { flog.Debugf("flooding, dropping message (queue at %d)", len(b.Local)) } diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 62365792..7f7340b6 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -106,10 +106,10 @@ func (b *Bmattermost) Protocol() string { func (b *Bmattermost) Send(msg config.Message) error { flog.Debugf("Receiving %#v", msg) - return b.SendType(msg.Username, msg.Text, msg.Channel, "") -} + nick := config.GetNick(&msg, b.Config) + message := msg.Text + channel := msg.Channel -func (b *Bmattermost) SendType(nick string, message string, channel string, mtype string) error { if b.Config.PrefixMessagesWithNick { /*if IsMarkup(message) { message = nick + "\n\n" + message @@ -122,7 +122,7 @@ func (b *Bmattermost) SendType(nick string, message string, channel string, mtyp matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL} matterMessage.Channel = channel matterMessage.UserName = nick - matterMessage.Type = mtype + matterMessage.Type = "" matterMessage.Text = message err := b.mh.Send(matterMessage) if err != nil { diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 3b0a6c85..412c925b 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -94,13 +94,12 @@ func (b *Bslack) Origin() string { func (b *Bslack) Send(msg config.Message) error { flog.Debugf("Receiving %#v", msg) - if msg.FullOrigin != b.FullOrigin() { - return b.SendType(msg.Username, msg.Text, msg.Channel, "") + if msg.FullOrigin == b.FullOrigin() { + return nil } - return nil -} - -func (b *Bslack) SendType(nick string, message string, channel string, mtype string) error { + nick := config.GetNick(&msg, b.Config) + message := msg.Text + channel := msg.Channel if b.Config.PrefixMessagesWithNick { message = nick + " " + message } @@ -108,7 +107,7 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str matterMessage := matterhook.OMessage{IconURL: b.Config.IconURL} matterMessage.Channel = channel matterMessage.UserName = nick - matterMessage.Type = mtype + matterMessage.Type = "" matterMessage.Text = message err := b.mh.Send(matterMessage) if err != nil { @@ -121,8 +120,19 @@ func (b *Bslack) SendType(nick string, message string, channel string, mtype str if err != nil { return err } - newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID) - b.rtm.SendMessage(newmsg) + np := slack.NewPostMessageParameters() + if b.Config.PrefixMessagesWithNick == true { + np.AsUser = true + } + np.Username = nick + np.IconURL = config.GetIconURL(&msg, b.Config) + b.sc.PostMessage(schannel.ID, message, np) + + /* + newmsg := b.rtm.NewOutgoingMessage(message, schannel.ID) + b.rtm.SendMessage(newmsg) + */ + return nil } diff --git a/bridge/xmpp/xmpp.go b/bridge/xmpp/xmpp.go index 164284e5..51237a08 100644 --- a/bridge/xmpp/xmpp.go +++ b/bridge/xmpp/xmpp.go @@ -71,7 +71,8 @@ func (b *Bxmpp) Origin() string { func (b *Bxmpp) Send(msg config.Message) error { flog.Debugf("Receiving %#v", msg) - b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Config.Muc, Text: msg.Username + msg.Text}) + nick := config.GetNick(&msg, b.Config) + b.xc.Send(xmpp.Chat{Type: "groupchat", Remote: msg.Channel + "@" + b.Config.Muc, Text: nick + msg.Text}) return nil } |