5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-11-09 23:40:27 +00:00

Fix #1040: spotty webhook permission verification

This commit is contained in:
Qais Patankar 2020-03-17 16:04:38 +00:00 committed by Wim
parent 2fbac73c29
commit b5dc4353fb

View File

@ -114,10 +114,10 @@ func (b *Bdiscord) Connect() error {
b.Log.Infof("Server=\"%s\" # Server ID", guild.ID) b.Log.Infof("Server=\"%s\" # Server ID", guild.ID)
} }
} }
if err != nil { if err != nil {
return err return err
} }
b.channelsMutex.RLock() b.channelsMutex.RLock()
if b.GetString("WebhookURL") == "" { if b.GetString("WebhookURL") == "" {
for _, channel := range b.channels { for _, channel := range b.channels {
@ -128,9 +128,13 @@ func (b *Bdiscord) Connect() error {
for _, info := range b.Channels { for _, info := range b.Channels {
id := b.getChannelID(info.Name) // note(qaisjp): this readlocks channelsMutex id := b.getChannelID(info.Name) // note(qaisjp): this readlocks channelsMutex
b.Log.Debugf("Verifying PermissionManageWebhooks for %s with ID %s", info.ID, id) b.Log.Debugf("Verifying PermissionManageWebhooks for %s with ID %s", info.ID, id)
perms, permsErr := b.c.State.UserChannelPermissions(userinfo.ID, id) perms, permsErr := b.c.UserChannelPermissions(userinfo.ID, id)
manageWebhooks := discordgo.PermissionManageWebhooks manageWebhooks := discordgo.PermissionManageWebhooks
if permsErr != nil || perms&manageWebhooks != manageWebhooks { 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.Log.Warnf("Can't manage webhooks in channel \"%s\"", info.Name)
b.canEditWebhooks = false b.canEditWebhooks = false
} }