diff options
author | Wim <wim@42.be> | 2018-02-28 22:54:47 +0100 |
---|---|---|
committer | Wim <wim@42.be> | 2018-02-28 22:54:47 +0100 |
commit | 0bc9c70c66c26b5dff0d92de76ff712d9a75eecb (patch) | |
tree | 685b358edae5d6c0c575da849f6977ac20b2466e /bridge | |
parent | 594d2155e3cbf06f307d076c95984906b53cb40a (diff) | |
download | matterbridge-msglm-0bc9c70c66c26b5dff0d92de76ff712d9a75eecb.tar.gz matterbridge-msglm-0bc9c70c66c26b5dff0d92de76ff712d9a75eecb.tar.bz2 matterbridge-msglm-0bc9c70c66c26b5dff0d92de76ff712d9a75eecb.zip |
Add usergroup support (slack). Closes #379
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/slack/slack.go | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index 009a33a4..e89954e2 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -16,12 +16,13 @@ import ( ) type Bslack struct { - mh *matterhook.Client - sc *slack.Client - rtm *slack.RTM - Users []slack.User - si *slack.Info - channels []slack.Channel + mh *matterhook.Client + sc *slack.Client + rtm *slack.RTM + Users []slack.User + Usergroups []slack.UserGroup + si *slack.Info + channels []slack.Channel *config.BridgeConfig } @@ -283,10 +284,12 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) { b.Log.Debugf("%#v", ev.Error()) case *slack.ChannelJoinedEvent: b.Users, _ = b.sc.GetUsers() + b.Usergroups, _ = b.sc.GetUserGroups() case *slack.ConnectedEvent: b.channels = ev.Info.Channels b.si = ev.Info b.Users, _ = b.sc.GetUsers() + b.Usergroups, _ = b.sc.GetUserGroups() // add private channels groups, _ := b.sc.GetGroups(true) for _, g := range groups { @@ -327,12 +330,24 @@ func (b *Bslack) userName(id string) string { return "" } +func (b *Bslack) userGroupName(id string) string { + for _, u := range b.Usergroups { + if u.ID == id { + return u.Name + } + } + return "" +} + // @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users func (b *Bslack) replaceMention(text string) string { results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(text, -1) for _, r := range results { text = strings.Replace(text, "<@"+r[1]+">", "@"+b.userName(r[1]), -1) } + for _, r := range results { + text = strings.Replace(text, "<@"+r[1]+">", "@"+b.userGroupName(r[1]), -1) + } return text } |