Replace 3 AllowPingEveryone/Roles/Users bools with an array

This commit is contained in:
Reach
2021-05-05 23:10:04 +02:00
parent 42d2ad222f
commit 1ccc08cfda
3 changed files with 44 additions and 42 deletions

View File

@@ -85,9 +85,7 @@ type ChannelMember struct {
type ChannelMembers []ChannelMember type ChannelMembers []ChannelMember
type Protocol struct { type Protocol struct {
AllowPingEveryone bool // discord AllowMention []string // discord
AllowPingRoles bool // discord
AllowPingUsers bool // discord
AuthCode string // steam AuthCode string // steam
BindAddress string // mattermost, slack // DEPRECATED BindAddress string // mattermost, slack // DEPRECATED
Buffer int // api Buffer int // api

View File

@@ -10,17 +10,23 @@ import (
) )
func (b *Bdiscord) getAllowedMentions() *discordgo.MessageAllowedMentions { 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) allowedMentionTypes := make([]discordgo.AllowedMentionType, 0, 3)
if b.GetBool("AllowPingEveryone") || !b.IsKeySet("AllowPingEveryone") { for _, m := range b.GetStringSlice("AllowMention") {
switch m {
case "everyone":
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeEveryone) allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeEveryone)
} case "roles":
if b.GetBool("AllowPingRoles") || !b.IsKeySet("AllowPingRoles") {
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeRoles) allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeRoles)
} case "users":
if b.GetBool("AllowPingUsers") || !b.IsKeySet("AllowPingUsers") {
allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeUsers) allowedMentionTypes = append(allowedMentionTypes, discordgo.AllowedMentionTypeUsers)
} }
}
return &discordgo.MessageAllowedMentions{ return &discordgo.MessageAllowedMentions{
Parse: allowedMentionTypes, Parse: allowedMentionTypes,

View File

@@ -848,15 +848,13 @@ Server="yourservername"
## All settings below can be reloaded by editing the file. ## All settings below can be reloaded by editing the file.
## They are also all optional. ## They are also all optional.
# AllowPingEveryone controls if @everyone and @here mentions should send a mention/ping to users. (default true) # AllowMention controls which mentions are allowed. If not specified, all mentions are allowed.
AllowPingEveryone=true # Note that even when a mention is not allowed, it will still be displayed nicely and be clickable. It just prevents the ping/notification.
#
# AllowPingRoles controls if @role mentions should send a mention/ping to users. (default true) # "everyone" allows @everyone and @here mentions
AllowPingRoles=true # "roles" allows @role mentions
# "users" allows @user mentions
# AllowPingUsers controls if @user mentions should send a mention/ping to users. (default true) AllowMention=["everyone", "roles", "users"]
# Even if set to false, the mention will still be nicely displayed and be clickable (but will not ping the user).
AllowPingUsers=true
# ShowEmbeds shows the title, description and URL of embedded messages (sent by other bots) # ShowEmbeds shows the title, description and URL of embedded messages (sent by other bots)
ShowEmbeds=false ShowEmbeds=false