mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-03 09:37:44 +00:00
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
This commit is contained in:
@ -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()
|
||||
|
Reference in New Issue
Block a user