Skip to content
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

Change permissions field from Int to Int64 #16

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
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
Diff view
2 changes: 1 addition & 1 deletion src/types/audit_log.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/types/guild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/types/role.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions src/utils/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"""
Expand All @@ -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[]),
Expand Down