8000 fix permission check by ikafly144 · Pull Request #146 · sabafly/gobot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix permission check #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
13 changes: 13 additions & 0 deletions bot/components/generic/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func noPermissionMessage(event interface {

func PermissionCheck(ctx context.Context, c *components.Components, g *ent.Guild, client bot.Client, m discord.ResolvedMember, guildID snowflake.ID, perms []Permission) bool {

if len(perms) == 0 {
return true
}

if m := c.DB().Guild.Query().
Where(guild.ID(guildID)).
FirstX(ctx).
Expand Down Expand Up @@ -77,6 +81,10 @@ func PermissionCheck(ctx context.Context, c *components.Components, g *ent.Guild

func RolePermissionCheck(g *ent.Guild, guildID snowflake.ID, client bot.Client, roleIds []snowflake.ID, perms []Permission) bool {

if len(perms) == 0 {
return true
}

var roles []discord.Role
client.Caches().RolesForEach(guildID, func(role discord.Role) {
roles = append(roles, role)
Expand Down Expand Up @@ -114,6 +122,11 @@ func permissionCheck(event interface {
User() discord.User
Client() bot.Client
}, c *components.Components, perms []Permission, dPerm discord.Permissions) bool {

if len(perms) == 0 {
return true
}

if slices.Contains(c.Config().Debug.DebugUsers, event.User().ID) {
return true
}
Expand Down
0