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

Fix permissions on arm processors and prepare for permissions change #386

Closed
Closed
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
20 changes: 16 additions & 4 deletions libs/client/Resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function Resolver.permissions(obj)
if isInstance(obj, classes.Permissions) then
return obj.value
end
return tonumber(obj)
return int(obj)
end

function Resolver.permission(obj)
Expand All @@ -159,7 +159,11 @@ function Resolver.permission(obj)
if t == 'string' then
n = permission[obj]
elseif t == 'number' then
n = permission(obj) and obj
n = permission(uint64_t(obj)) and obj
elseif t == 'cdata' then
if istype(int64_t, obj) or istype(uint64_t, obj) then
n = permission(uint64_t(obj)) and obj
end
end
return n
end
Expand All @@ -170,7 +174,11 @@ function Resolver.gatewayIntent(obj)
if t == 'string' then
n = gatewayIntent[obj]
elseif t == 'number' then
n = gatewayIntent(obj) and obj
n = gatewayIntent(uint64_t(obj)) and obj
elseif t == 'cdata' then
if istype(int64_t, obj) or istype(uint64_t, obj) then
n = gatewayIntent(uint64_t(obj)) and obj
end
end
return n
end
Expand All @@ -192,7 +200,11 @@ function Resolver.messageFlag(obj)
if t == 'string' then
n = messageFlag[obj]
elseif t == 'number' then
n = messageFlag(obj) and obj
n = messageFlag(uint64_t(obj)) and obj
elseif t == 'cdata' then
if istype(int64_t, obj) or istype(uint64_t, obj) then
n = messageFlag(uint64_t(obj)) and obj
end
end
return n
end
Expand Down
2 changes: 1 addition & 1 deletion libs/client/Shard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function Shard:identify()
large_threshold = options.largeThreshold,
shard = {self._id, client._total_shard_count},
presence = next(client._presence) and client._presence,
intents = client._intents,
intents = tonumber(client._intents),
}, true)

end
Expand Down
4 changes: 2 additions & 2 deletions libs/containers/Message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ end
]=]
function Message:hideEmbeds()
local flags = bor(self._flags or 0, messageFlag.suppressEmbeds)
return self:_modify({flags = flags})
return self:_modify({flags = tonumber(flags)})
end

--[=[
Expand All @@ -227,7 +227,7 @@ end
]=]
function Message:showEmbeds()
local flags = band(self._flags or 0, bnot(messageFlag.suppressEmbeds))
return self:_modify({flags = flags})
return self:_modify({flags = tonumber(flags)})
end

--[=[
Expand Down
3 changes: 3 additions & 0 deletions libs/containers/PermissionOverwrite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ local function getPermissions(self)
end

local function setPermissions(self, allow, deny)
allow = string.format('%i', allow):match('^(%d+)')
deny = string.format('%i', deny):match('^(%d+)')

local data, err = self.client._api:editChannelPermissions(self._parent._id, self._id, {
allow = allow, deny = deny, type = self._type
})
Expand Down
97 changes: 59 additions & 38 deletions libs/enums.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
local ffi = require('ffi')
local istype = ffi.istype
local uint64_t = ffi.typeof('uint64_t')

local function enum(tbl)
local call = {}
for k, v in pairs(tbl) do
if istype(uint64_t, v) then
v = tonumber(v)
end

if call[v] then
return error(string.format('enum clash for %q and %q', k, call[v]))
end
call[v] = k
end
return setmetatable({}, {
__call = function(_, k)
if istype(uint64_t, k) then
k = tonumber(k)
end
if call[k] then
return call[k]
else
Expand Down Expand Up @@ -155,47 +166,57 @@ enums.premiumTier = enum {
}

local function flag(n)
return 2^n
return 2ULL^n
end

enums.permission = enum {
createInstantInvite = flag(0),
kickMembers = flag(1),
banMembers = flag(2),
administrator = flag(3),
manageChannels = flag(4),
manageGuild = flag(5),
addReactions = flag(6),
viewAuditLog = flag(7),
prioritySpeaker = flag(8),
stream = flag(9),
readMessages = flag(10),
sendMessages = flag(11),
sendTextToSpeech = flag(12),
manageMessages = flag(13),
embedLinks = flag(14),
attachFiles = flag(15),
readMessageHistory = flag(16),
mentionEveryone = flag(17),
useExternalEmojis = flag(18),
viewGuildInsights = flag(19),
connect = flag(20),
speak = flag(21),
muteMembers = flag(22),
deafenMembers = flag(23),
moveMembers = flag(24),
useVoiceActivity = flag(25),
changeNickname = flag(26),
manageNicknames = flag(27),
manageRoles = flag(28),
manageWebhooks = flag(29),
manageEmojis = flag(30),
useSlashCommands = flag(31),
requestToSpeak = flag(32),
manageEvents = flag(33),
manageThreads = flag(34),
usePublicThreads = flag(35),
usePrivateThreads = flag(36),
createInstantInvite = flag(0),
kickMembers = flag(1),
banMembers = flag(2),
administrator = flag(3),
manageChannels = flag(4),
manageGuild = flag(5),
addReactions = flag(6),
viewAuditLog = flag(7),
prioritySpeaker = flag(8),
stream = flag(9),
readMessages = flag(10),
sendMessages = flag(11),
sendTextToSpeech = flag(12),
manageMessages = flag(13),
embedLinks = flag(14),
attachFiles = flag(15),
readMessageHistory = flag(16),
mentionEveryone = flag(17),
useExternalEmojis = flag(18),
viewGuildInsights = flag(19),
connect = flag(20),
speak = flag(21),
muteMembers = flag(22),
deafenMembers = flag(23),
moveMembers = flag(24),
useVoiceActivity = flag(25),
changeNickname = flag(26),
manageNicknames = flag(27),
manageRoles = flag(28),
manageWebhooks = flag(29),
manageEmojis = flag(30),
useSlashCommands = flag(31),
requestToSpeak = flag(32),
manageEvents = flag(33),
manageThreads = flag(34),
usePublicThreads = flag(35),
usePrivateThreads = flag(36),
useExternalStickers = flag(37),
sendMessagesThreads = flag(38),
useVoiceActivities = flag(39),
moderateMembers = flag(40),
viewCreatorAnalytics = flag(41),
useSoundboard = flag(42),
-- unused = flag(43),
-- unused = flag(44),
-- unused = flag(45),
sendVoiceMessages = flag(46),
}

enums.messageFlag = enum {
Expand Down