summaryrefslogtreecommitdiffstats
path: root/bridge/discord/discord.go
diff options
context:
space:
mode:
authorQais Patankar <qaisjp@gmail.com>2020-03-17 16:18:50 +0000
committerWim <wim@42.be>2020-03-18 23:10:47 +0100
commit79f764c7a8e6449092a2a57eafdc597409263e32 (patch)
tree748c43e7d23767f465c121934e9a5a7e94af58c5 /bridge/discord/discord.go
parentb5dc4353fbecb90b74139c1aea8ae88b24f2fd0e (diff)
downloadmatterbridge-msglm-79f764c7a8e6449092a2a57eafdc597409263e32.tar.gz
matterbridge-msglm-79f764c7a8e6449092a2a57eafdc597409263e32.tar.bz2
matterbridge-msglm-79f764c7a8e6449092a2a57eafdc597409263e32.zip
Refactor webhook permission checks
Diffstat (limited to 'bridge/discord/discord.go')
-rw-r--r--bridge/discord/discord.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go
index 7661a1da..d2871360 100644
--- a/bridge/discord/discord.go
+++ b/bridge/discord/discord.go
@@ -124,25 +124,27 @@ func (b *Bdiscord) Connect() error {
b.Log.Debugf("found channel %#v", channel)
}
} else {
- b.canEditWebhooks = true
+ manageWebhooks := discordgo.PermissionManageWebhooks
+ var channelsDenied []string
for _, info := range b.Channels {
id := b.getChannelID(info.Name) // note(qaisjp): this readlocks channelsMutex
b.Log.Debugf("Verifying PermissionManageWebhooks for %s with ID %s", info.ID, id)
- perms, permsErr := b.c.UserChannelPermissions(userinfo.ID, id)
- manageWebhooks := discordgo.PermissionManageWebhooks
+ perms, permsErr := b.c.UserChannelPermissions(userinfo.ID, id)
if permsErr != nil {
- b.Log.Warnf("Can't manage webhooks in channel \"%s\", because: %s", info.Name, permsErr.Error())
- b.canEditWebhooks = false
- } else if perms&manageWebhooks != manageWebhooks {
- b.Log.Warnf("Can't manage webhooks in channel \"%s\"", info.Name)
- b.canEditWebhooks = false
+ b.Log.Warnf("Failed to check PermissionManageWebhooks in channel \"%s\": %s", info.Name, permsErr.Error())
+ } else if perms&manageWebhooks == manageWebhooks {
+ continue
}
+ channelsDenied = append(channelsDenied, fmt.Sprintf("%#v", info.Name))
}
+
+ b.canEditWebhooks = len(channelsDenied) == 0
if b.canEditWebhooks {
b.Log.Info("Can manage webhooks; will edit channel for global webhook on send")
} else {
b.Log.Warn("Can't manage webhooks; won't edit channel for global webhook on send")
+ b.Log.Warn("Can't manage webhooks in channels: ", strings.Join(channelsDenied, ", "))
}
}
b.channelsMutex.RUnlock()