From 1ccc08cfda2b3e59427be8d9876cdd1778648b04 Mon Sep 17 00:00:00 2001 From: Reach Date: Wed, 5 May 2021 23:10:04 +0200 Subject: [PATCH] Replace 3 AllowPingEveryone/Roles/Users bools with an array --- bridge/config/config.go | 46 +++++++++++++++++++-------------------- bridge/discord/helpers.go | 24 ++++++++++++-------- matterbridge.toml.sample | 16 ++++++-------- 3 files changed, 44 insertions(+), 42 deletions(-) diff --git a/bridge/config/config.go b/bridge/config/config.go index 382dbbfe..b5e03fcf 100644 --- a/bridge/config/config.go +++ b/bridge/config/config.go @@ -85,30 +85,28 @@ type ChannelMember struct { type ChannelMembers []ChannelMember type Protocol struct { - AllowPingEveryone bool // discord - AllowPingRoles bool // discord - AllowPingUsers bool // discord - AuthCode string // steam - BindAddress string // mattermost, slack // DEPRECATED - Buffer int // api - Charset string // irc - ClientID string // msteams - ColorNicks bool // only irc for now - Debug bool // general - DebugLevel int // only for irc now - DisableWebPagePreview bool // telegram - EditSuffix string // mattermost, slack, discord, telegram, gitter - EditDisable bool // mattermost, slack, discord, telegram, gitter - HTMLDisable bool // matrix - IconURL string // mattermost, slack - IgnoreFailureOnStart bool // general - IgnoreNicks string // all protocols - IgnoreMessages string // all protocols - Jid string // xmpp - JoinDelay string // all protocols - Label string // all protocols - Login string // mattermost, matrix - LogFile string // general + AllowMention []string // discord + AuthCode string // steam + BindAddress string // mattermost, slack // DEPRECATED + Buffer int // api + Charset string // irc + ClientID string // msteams + ColorNicks bool // only irc for now + Debug bool // general + DebugLevel int // only for irc now + DisableWebPagePreview bool // telegram + EditSuffix string // mattermost, slack, discord, telegram, gitter + EditDisable bool // mattermost, slack, discord, telegram, gitter + HTMLDisable bool // matrix + IconURL string // mattermost, slack + IgnoreFailureOnStart bool // general + IgnoreNicks string // all protocols + IgnoreMessages string // all protocols + Jid string // xmpp + JoinDelay string // all protocols + Label string // all protocols + Login string // mattermost, matrix + LogFile string // general MediaDownloadBlackList []string MediaDownloadPath string // Basically MediaServerUpload, but instead of uploading it, just write it to a file on the same server. MediaDownloadSize int // all protocols diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go index 57d46c8f..c8cdb58c 100644 --- a/bridge/discord/helpers.go +++ b/bridge/discord/helpers.go @@ -10,16 +10,22 @@ import ( ) func (b *Bdiscord) getAllowedMentions() *discordgo.MessageAllowedMentions { - // Allow only the mention types that are not disabled by the config (default is all allowed) + // If AllowMention is not specified, then allow all mentions (defautl Discord behavior) + if !b.IsKeySet("AllowMention") { + return nil + } + + // Otherwise, allow only the mentions that are specified allowedMentionTypes := make([]discordgo.AllowedMentionType, 0, 3) - if b.GetBool("AllowPingEveryone") || !b.IsKeySet("AllowPingEveryone") { - allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeEveryone) - } - if b.GetBool("AllowPingRoles") || !b.IsKeySet("AllowPingRoles") { - allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeRoles) - } - if b.GetBool("AllowPingUsers") || !b.IsKeySet("AllowPingUsers") { - allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeUsers) + 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{ diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 72115baa..6a5d406f 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -848,15 +848,13 @@ Server="yourservername" ## All settings below can be reloaded by editing the file. ## They are also all optional. -# AllowPingEveryone controls if @everyone and @here mentions should send a mention/ping to users. (default true) -AllowPingEveryone=true - -# AllowPingRoles controls if @role mentions should send a mention/ping to users. (default true) -AllowPingRoles=true - -# AllowPingUsers controls if @user mentions should send a mention/ping to users. (default true) -# Even if set to false, the mention will still be nicely displayed and be clickable (but will not ping the user). -AllowPingUsers=true +# AllowMention controls which mentions are allowed. If not specified, all mentions are allowed. +# Note that even when a mention is not allowed, it will still be displayed nicely and be clickable. It just prevents the ping/notification. +# +# "everyone" allows @everyone and @here mentions +# "roles" allows @role mentions +# "users" allows @user mentions +AllowMention=["everyone", "roles", "users"] # ShowEmbeds shows the title, description and URL of embedded messages (sent by other bots) ShowEmbeds=false