Skip to content

Commit

Permalink
Fixed permission check for DM
Browse files Browse the repository at this point in the history
  • Loading branch information
get-got committed Dec 20, 2020
1 parent 154c372 commit 6015c73
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,21 @@ func isLocalAdmin(m *discordgo.Message) bool {
}

func hasPerms(channelID string, permission int) bool {
perms, err := bot.UserChannelPermissions(user.ID, channelID)
if err == nil {
return perms&permission == permission
sourceChannel, err := bot.State.Channel(channelID)
if sourceChannel != nil && err == nil {
switch sourceChannel.Type {
case discordgo.ChannelTypeDM:
return true
case discordgo.ChannelTypeGroupDM:
return true
case discordgo.ChannelTypeGuildText:
perms, err := bot.UserChannelPermissions(user.ID, channelID)
if err == nil {
return perms&permission == permission
}
log.Println(color.HiRedString("Failed to check permissions (%d) for %s:\t%s", permission, channelID, err))
}
}
log.Println(color.HiRedString("Failed to check permissions (%d) for %s:\t%s", permission, channelID, err))
return false
}

Expand Down

0 comments on commit 6015c73

Please sign in to comment.