Permission checking will fail after UseApplicationCommands
bug
There is an issue where permission checking will fail for flags defined after UseApplicationCommands. This is because permission flags above 31 require left-shifting beyond 1 << 31, which is not possible for Luau's bit32 library because it uses 32-bit numbers.
**Edit:** This can be fixed by using the mathematical equivalent, `2^n`, where n is the second param passed to `bit32.lshift` when defining permission flags. Usage of `bit32.band` in the `DiscordPermission` can be fixed by splitting 64-bit numbers into two 32-bit parts (high & low) and then joining them back together.
Sample code (with appropriate typing) for bit32.band extended to 64-bit numbers:
```lua
local function band(...: number): number
local args = {...}
local high, low = (args[1] / 0x100000000), (args[1] % 0x100000000)
for i = 2, #args do
local x = args[i]
local high2, low2 = (x / 0x100000000), (x % 0x100000000)
high = bit32.band(high, high2)
low = bit32.band(low, low2)
end
high = bit32.rshift(high, 1) * 2 + bit32.band(high, 1)
low = bit32.rshift(low, 1) * 2 + bit32.band(low, 1)
return (high * 2^32) + (low % 2^32)
end
```
This concept can be extended to other bit32 functions.
You can confirm this by trying something such as `band(0xFFFFFFFF00000000, 0x0000FFFF00000000)` vs. `bit32.band(0xFFFFFFFF00000000, 0x0000FFFF00000000)`. The first result is what you will get if you compare with Lua 5.4 and run `print(0xFFFFFFFF00000000 & 0x0000FFFF00000000)`
1 条评论