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

Permission checking will fail after UseApplicationCommands #28

Open
CleverSource opened this issue Dec 21, 2024 · 0 comments
Open

Permission checking will fail after UseApplicationCommands #28

CleverSource opened this issue Dec 21, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@CleverSource
Copy link

CleverSource commented Dec 21, 2024

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:

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)

@CompeyDev CompeyDev added the bug Something isn't working label Dec 21, 2024
@4x8Matrix 4x8Matrix self-assigned this Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants