summaryrefslogtreecommitdiffstats
path: root/bridge/discord
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-03-18 16:50:09 +0100
committerWim <wim@42.be>2017-03-18 16:50:09 +0100
commit80895deae2f20ab8844bec7b0e8b38c7d1a609f4 (patch)
tree73fd2528b93c617aa8b164311457e9a03f31fcbd /bridge/discord
parenteddc691fc9e8ced74a33d3c4cbd568c2728fe6f1 (diff)
downloadmatterbridge-msglm-80895deae2f20ab8844bec7b0e8b38c7d1a609f4.tar.gz
matterbridge-msglm-80895deae2f20ab8844bec7b0e8b38c7d1a609f4.tar.bz2
matterbridge-msglm-80895deae2f20ab8844bec7b0e8b38c7d1a609f4.zip
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)
Diffstat (limited to 'bridge/discord')
-rw-r--r--bridge/discord/discord.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 06508b84..1cf81337 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -122,6 +122,9 @@ 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"}
}
@@ -180,3 +183,15 @@ 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
+}