From acd6ab5750b3ec120d358b912bf3b7f9aeeb1086 Mon Sep 17 00:00:00 2001 From: DavidLoftus <43099493+DavidLoftus@users.noreply.github.com> Date: Mon, 30 Sep 2019 21:17:29 +0100 Subject: [PATCH] Change permissions field from Int to Int64 --- src/types/audit_log.jl | 2 +- src/types/guild.jl | 2 +- src/types/role.jl | 2 +- src/utils/helpers.jl | 14 ++++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/types/audit_log.jl b/src/types/audit_log.jl index daccd27..5d2524b 100644 --- a/src/types/audit_log.jl +++ b/src/types/audit_log.jl @@ -24,7 +24,7 @@ const AUDIT_LOG_CHANGE_TYPES = Dict( "permission_overwrites" => (Vector{Overwrite}, DiscordChannel), "nsfw" => (Bool, DiscordChannel), "application_id" => (Snowflake, DiscordChannel), - "permissions" => (Int, Role), + "permissions" => (Int64, Role), "color" => (Int, Role), "hoist" => (Bool, Role), "mentionable" => (Bool, Role), diff --git a/src/types/guild.jl b/src/types/guild.jl index d4140ca..c981d77 100644 --- a/src/types/guild.jl +++ b/src/types/guild.jl @@ -64,7 +64,7 @@ struct Guild <: AbstractGuild splash::OptionalNullable{String} owner::Optional{Bool} owner_id::Optional{Snowflake} # Missing in Invite. - permissions::Optional{Int} + permissions::Optional{Int64} region::Optional{String} # Invite afk_channel_id::OptionalNullable{Snowflake} # Invite afk_timeout::Optional{Int} # Invite diff --git a/src/types/role.jl b/src/types/role.jl index 10ed0c9..330c6b2 100644 --- a/src/types/role.jl +++ b/src/types/role.jl @@ -10,7 +10,7 @@ struct Role color::Optional{Int} # These fields are missing in audit log entries. hoist::Optional{Bool} position::Optional{Int} - permissions::Optional{Int} + permissions::Optional{Int64} managed::Optional{Bool} mentionable::Optional{Bool} end diff --git a/src/utils/helpers.jl b/src/utils/helpers.jl index 15f5fea..ec4152e 100644 --- a/src/utils/helpers.jl +++ b/src/utils/helpers.jl @@ -79,13 +79,13 @@ true ``` """ function has_permission(perms::Integer, perm::Permission) - admin = perms & Int(PERM_ADMINISTRATOR) == Int(PERM_ADMINISTRATOR) - has = perms & Int(perm) == Int(perm) + admin = perms & Int64(PERM_ADMINISTRATOR) == Int64(PERM_ADMINISTRATOR) + has = perms & Int64(perm) == Int64(perm) return admin || has end """ - permissions_in(m::Member, g::Guild, ch::DiscordChannel) -> Int + permissions_in(m::Member, g::Guild, ch::DiscordChannel) -> Int64 Compute a [`Member`](@ref)'s [`Permission`](@ref)s in a [`DiscordChannel`](@ref). """ @@ -95,11 +95,13 @@ function permissions_in(m::Member, g::Guild, ch::DiscordChannel) # Get permissions for @everyone. idx = findfirst(r -> r.name == "@everyone", g.roles) everyone = idx === nothing ? nothing : g.roles[idx] - perms = idx === nothing ? 0 : everyone.permissions - perms & Int(PERM_ADMINISTRATOR) == Int(PERM_ADMINISTRATOR) && return PERM_ALL + perms = idx === nothing ? Int64(0) : everyone.permissions + perms & Int64(PERM_ADMINISTRATOR) == Int64(PERM_ADMINISTRATOR) && return PERM_ALL + + roles = idx === nothing ? m.roles : [everyone.id; m.roles] # Apply role overwrites. - for role in [everyone.id; m.roles] + for role in roles idx = findfirst( o -> o.type === OT_ROLE && o.id == role, coalesce(ch.permission_overwrites, Overwrite[]),