Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit 71432eb187171a4eb1ac304e47a6c0ae7d9b2d91 Author: Wim <wim@42.be> Date: Sat Mar 18 16:50:09 2017 +0000 Replace role ids in mentions to role names (discord). Closes #133 * The bot needs to have the "Manage Roles" permission for this to work. (see Server settings - Roles - General Permissions) diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 06508b8..1cf8133 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -1226 +1229 @@ func (b *bdiscord) messageCreate(s *discordgo.Session, m *discordgo.MessageCreat   channelName = "ID:" + m.ChannelID   }   username := b.getNick(m.Author) + if len(m.MentionRoles) > 0 { + m.Message.Content = b.replaceRoleMentions(m.Message.Content) + }   b.Remote <- config.Message{Username: username, Text: m.ContentWithMentionsReplaced(), Channel: channelName,   Account: b.Account, Avatar: "https://cdn.discordapp.com/avatars/" + m.Author.ID + "/" + m.Author.Avatar + ".jpg"}  } @@ -1803 +18315 @@ func (b *bdiscord) getChannelName(id string) string {   }   return ""  } + +func (b *bdiscord) replaceRoleMentions(text string) string { + roles, err := b.c.GuildRoles(b.guildID) + if err != nil { + flog.Debugf("%#v", string(err.(*discordgo.RESTError).ResponseBody)) + return text + } + for _, role := range roles { + text = strings.Replace(text, "<@&"+role.ID+">", "@"+role.Name, -1) + } + return text +} diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 002acd1..52438ff 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -3776 +3777 @@ ShowJoinPart=false  #Token to connect with Discord API  #You can get your token by following the instructions on  #https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token +#If you want roles/groups mentions to be shown with names instead of ID, you'll need to give your bot the "Manage Roles" permission.  #REQUIRED  Token="Yourtokenhere"