mirror of
https://github.com/42wim/matterbridge.git
synced 2024-11-24 19:52:03 -08:00
Add usergroup support (slack). Closes #379
This commit is contained in:
parent
594d2155e3
commit
0bc9c70c66
@ -20,6 +20,7 @@ type Bslack struct {
|
|||||||
sc *slack.Client
|
sc *slack.Client
|
||||||
rtm *slack.RTM
|
rtm *slack.RTM
|
||||||
Users []slack.User
|
Users []slack.User
|
||||||
|
Usergroups []slack.UserGroup
|
||||||
si *slack.Info
|
si *slack.Info
|
||||||
channels []slack.Channel
|
channels []slack.Channel
|
||||||
*config.BridgeConfig
|
*config.BridgeConfig
|
||||||
@ -283,10 +284,12 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
|
|||||||
b.Log.Debugf("%#v", ev.Error())
|
b.Log.Debugf("%#v", ev.Error())
|
||||||
case *slack.ChannelJoinedEvent:
|
case *slack.ChannelJoinedEvent:
|
||||||
b.Users, _ = b.sc.GetUsers()
|
b.Users, _ = b.sc.GetUsers()
|
||||||
|
b.Usergroups, _ = b.sc.GetUserGroups()
|
||||||
case *slack.ConnectedEvent:
|
case *slack.ConnectedEvent:
|
||||||
b.channels = ev.Info.Channels
|
b.channels = ev.Info.Channels
|
||||||
b.si = ev.Info
|
b.si = ev.Info
|
||||||
b.Users, _ = b.sc.GetUsers()
|
b.Users, _ = b.sc.GetUsers()
|
||||||
|
b.Usergroups, _ = b.sc.GetUserGroups()
|
||||||
// add private channels
|
// add private channels
|
||||||
groups, _ := b.sc.GetGroups(true)
|
groups, _ := b.sc.GetGroups(true)
|
||||||
for _, g := range groups {
|
for _, g := range groups {
|
||||||
@ -327,12 +330,24 @@ func (b *Bslack) userName(id string) string {
|
|||||||
return ""
|
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
|
// @see https://api.slack.com/docs/message-formatting#linking_to_channels_and_users
|
||||||
func (b *Bslack) replaceMention(text string) string {
|
func (b *Bslack) replaceMention(text string) string {
|
||||||
results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(text, -1)
|
results := regexp.MustCompile(`<@([a-zA-z0-9]+)>`).FindAllStringSubmatch(text, -1)
|
||||||
for _, r := range results {
|
for _, r := range results {
|
||||||
text = strings.Replace(text, "<@"+r[1]+">", "@"+b.userName(r[1]), -1)
|
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
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user