summaryrefslogtreecommitdiffstats
path: root/bridge/slack/slack.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2016-11-06 00:46:32 +0100
committerWim <wim@42.be>2016-11-06 00:46:32 +0100
commita3dd0f1345fae3d7828ed0c82d6a7c4b610d0983 (patch)
tree7db0a8d15e4390b9c2bb0581cad8d2e551a29b23 /bridge/slack/slack.go
parent37873acfcd328e7c9eaf2e69148de05b8d00a428 (diff)
downloadmatterbridge-msglm-a3dd0f1345fae3d7828ed0c82d6a7c4b610d0983.tar.gz
matterbridge-msglm-a3dd0f1345fae3d7828ed0c82d6a7c4b610d0983.tar.bz2
matterbridge-msglm-a3dd0f1345fae3d7828ed0c82d6a7c4b610d0983.zip
Add support for using avatars from discord,slack and gitter in slack
Diffstat (limited to 'bridge/slack/slack.go')
-rw-r--r--bridge/slack/slack.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index 412c925b..f700aee8 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -24,6 +24,7 @@ type Bslack struct {
rtm *slack.RTM
Plus bool
Remote chan config.Message
+ Users []slack.User
protocol string
origin string
si *slack.Info
@@ -126,6 +127,9 @@ func (b *Bslack) Send(msg config.Message) error {
}
np.Username = nick
np.IconURL = config.GetIconURL(&msg, b.Config)
+ if msg.Avatar != "" {
+ np.IconURL = msg.Avatar
+ }
b.sc.PostMessage(schannel.ID, message, np)
/*
@@ -136,6 +140,18 @@ func (b *Bslack) Send(msg config.Message) error {
return nil
}
+func (b *Bslack) getAvatar(user string) string {
+ var avatar string
+ if b.Users != nil {
+ for _, u := range b.Users {
+ if user == u.Name {
+ return u.Profile.Image48
+ }
+ }
+ }
+ return avatar
+}
+
func (b *Bslack) getChannelByName(name string) (*slack.Channel, error) {
if b.channels == nil {
return nil, fmt.Errorf("%s: channel %s not found (no channels found)", b.FullOrigin(), name)
@@ -166,7 +182,7 @@ func (b *Bslack) handleSlack() {
texts := strings.Split(message.Text, "\n")
for _, text := range texts {
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.FullOrigin())
- b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin()}
+ b.Remote <- config.Message{Text: text, Username: message.Username, Channel: message.Channel, Origin: b.origin, Protocol: b.protocol, FullOrigin: b.FullOrigin(), Avatar: b.getAvatar(message.Username)}
}
}
}
@@ -201,6 +217,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
case *slack.ConnectedEvent:
b.channels = ev.Info.Channels
b.si = ev.Info
+ b.Users, _ = b.sc.GetUsers()
case *slack.InvalidAuthEvent:
flog.Fatalf("Invalid Token %#v", ev)
default: