5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-22 12:50:27 +00:00

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)
This commit is contained in:
Wim 2017-03-18 16:50:09 +01:00
parent eddc691fc9
commit 80895deae2
2 changed files with 16 additions and 0 deletions

View File

@ -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
}

View File

@ -377,6 +377,7 @@ 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"