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

feat: command permissions #212

Merged
merged 2 commits into from
Jan 29, 2025
Merged

Conversation

thewilloftheshadow
Copy link
Member

@thewilloftheshadow thewilloftheshadow commented Jan 22, 2025

Closes #155

CleanShot 2025-01-22 at 03 32 14@2x

@thewilloftheshadow thewilloftheshadow requested a review from a team as a code owner January 22, 2025 09:34
Copy link

changeset-bot bot commented Jan 22, 2025

🦋 Changeset detected

Latest commit: fe259e4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@buape/carbon Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the p:carbon The carbon package label Jan 22, 2025
@thewilloftheshadow thewilloftheshadow force-pushed the shadow/command-permissions branch from b2d91e9 to 268b88d Compare January 22, 2025 09:54
* The default permission that a user needs to have to use this command.
* This can be overridden by server admins.
*/
permission?: (typeof Permission)[keyof typeof Permission]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type resolves to just bigint anyway (so can use bit manipulation), but is any reason this isn't an array that can later be resolved to a bigint?

Copy link
Member Author

@thewilloftheshadow thewilloftheshadow Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still not sure how I feel about this but I think it's the best way.

Permission reexports the enum PermissionFlagBits from discord-api-types, which is the only spot all permissions are defined.
The alternative that we could do is maintain our own list, separate from discord-api-types.

I was trying at one point to type it as keyof typeof Permission so that users would just pass "ManageGuild", etc, but it was being typed as a string and not const so that wasn't working cleanly

Copy link
Member

@apteryxxyz apteryxxyz Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While keyof typeof Permission seems to work as expected for me, I was more referring to just

permissions?: ((typeof Permission)[keyof typeof Permission])[]

and then later use reduce in the serialize method to combine those bits

this.permissions ? this.permissions.reduce((a, p) => a | p, 0n).toString() : null

Copy link
Member

@apteryxxyz apteryxxyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a plural for the property name to match the docs but if you prefer as is that is fine

@thewilloftheshadow thewilloftheshadow merged commit 29c323c into main Jan 29, 2025
7 checks passed
@thewilloftheshadow thewilloftheshadow deleted the shadow/command-permissions branch January 29, 2025 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p:carbon The carbon package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command Permissions
2 participants