Skip to content

Commit

Permalink
fix admin detection for reacting user
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtakingiteasy committed May 30, 2023
1 parent 15b45f9 commit 34704e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
31 changes: 23 additions & 8 deletions discordbot/bot/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,24 +89,39 @@ func (conf *Configuration) HasPermission(
permissions int,
roleIDs, roleNames []string,
) bool {
guild, _ := conf.Discord.Guild(msg.GuildID)
if guild != nil && guild.OwnerID == msg.Author.ID {
return conf.HasPermissionUserID(msg.Member, msg.GuildID, msg.Author.ID, permissions, roleIDs, roleNames)
}

func (conf *Configuration) HasPermissionUserID(
member *discordgo.Member,
guildID, userID string,
permissions int,
roleIDs, roleNames []string,
) bool {
guild, _ := conf.Discord.Guild(guildID)
if guild != nil && guild.OwnerID == userID {
return true
}

admrole, _ := conf.Repository.ConfigGet(msg.GuildID, "auth", "admin.role")
admrole, _ := conf.Repository.ConfigGet(guildID, "auth", "admin.role")

member, err := conf.ensureMember(msg)
if err != nil {
return false
var err error

if member == nil {
member, err = conf.Discord.GuildMember(guildID, userID)
if err != nil {
conf.Log.WithError(err).Error("Loading member", guildID, userID)

return false
}
}

for _, r := range member.Roles {
var role *discordgo.Role

role, err = conf.Discord.State.Role(msg.GuildID, r)
role, err = conf.Discord.State.Role(guildID, r)
if err != nil {
conf.Log.WithError(err).Error("Loading role", msg.GuildID, r)
conf.Log.WithError(err).Error("Loading role", guildID, r)
continue
}

Expand Down
9 changes: 8 additions & 1 deletion discordbot/modules/nico/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,14 @@ func (mod *module) handleStopDownload(
}

if task.UserID != userID &&
!mod.config.HasPermission(msg, discordgo.PermissionAdministrator, nil, nil) {
!mod.config.HasPermissionUserID(
nil,
msg.GuildID,
userID,
discordgo.PermissionAdministrator,
nil,
nil,
) {
return
}

Expand Down

0 comments on commit 34704e8

Please sign in to comment.