diff options
author | Alexandre GV <contact@alexandregv.fr> | 2021-05-13 22:39:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-13 22:39:25 +0200 |
commit | ac4aee39e3256f9061d2057bb377862def4dd9d9 (patch) | |
tree | 4593f9938dfb355afc02a1f2b3795ba0ae19e538 /bridge/discord/helpers.go | |
parent | a0bca42a7ad98a37f4bdc4d7adc419471163edfb (diff) | |
download | matterbridge-msglm-ac4aee39e3256f9061d2057bb377862def4dd9d9.tar.gz matterbridge-msglm-ac4aee39e3256f9061d2057bb377862def4dd9d9.tar.bz2 matterbridge-msglm-ac4aee39e3256f9061d2057bb377862def4dd9d9.zip |
discord: Add AllowMention to restrict allowed mentions (#1462)
* Add DisablePingEveryoneHere/DisablePingRoles/DisablePingUsers keys to config
* Add basic AllowedMentions behavior to discord webhooks
* Initialize b.AllowedMentions on Discord Bridger init
* Call b.getAllowedMentions on each webhook to allow config hot reloading
* Add AllowedMentions on all Discord webhooks/messages
* Add DisablePingEveryoneHere/DisablePingRoles/DisablePingUsers to matterbridge.toml.sample
* Change 'Disable' for 'Allow' and revert logic in Discord AllowedMentions
* Update Discord AllowedMentions in matterbridge.toml.sample
* Fix typo in DisableWebPagePreview
* Replace 'AllowPingEveryoneHere' with 'AllowPingEveryone'
* Replace 3 AllowPingEveryone/Roles/Users bools with an array
* Fix typo
Diffstat (limited to 'bridge/discord/helpers.go')
-rw-r--r-- | bridge/discord/helpers.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go index 9545a3ae..4e453ad7 100644 --- a/bridge/discord/helpers.go +++ b/bridge/discord/helpers.go @@ -9,6 +9,30 @@ import ( "github.com/matterbridge/discordgo" ) +func (b *Bdiscord) getAllowedMentions() *discordgo.MessageAllowedMentions { + // If AllowMention is not specified, then allow all mentions (default Discord behavior) + if !b.IsKeySet("AllowMention") { + return nil + } + + // Otherwise, allow only the mentions that are specified + allowedMentionTypes := make([]discordgo.AllowedMentionType, 0, 3) + for _, m := range b.GetStringSlice("AllowMention") { + switch m { + case "everyone": + allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeEveryone) + case "roles": + allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeRoles) + case "users": + allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeUsers) + } + } + + return &discordgo.MessageAllowedMentions{ + Parse: allowedMentionTypes, + } +} + func (b *Bdiscord) getNick(user *discordgo.User, guildID string) string { b.membersMutex.RLock() defer b.membersMutex.RUnlock() |