-
Notifications
You must be signed in to change notification settings - Fork 186
Add Application Permissions Support #156
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start to implementing this!
I've outlined a couple of things that I noticed, but there are a few things with the overall implementation that I would like to see.
permissions
to be structured by guild id on the command object
ie
{
guildid: [ list of guild permission objects],
guild2id: [list of guild permissions obects],
}
This is because I don't think the current list of dicts that contain a list of guild ids represents how permissions work on the api, it's set per guild, not in a group of guilds and can differ between guilds.
The current approach could also lead to some setting one role id for a list of objects, which best case will fail silently, worst case discord errors because the role doesn't exist on that guild.
To reflect this I think that:
- The
permissions
parameter of@slash
(etc) changed to accept a dict of guild ids to permissons - Also create a decorator that can be repeated for each guild ie
@permission(guild_id = 1, permissions [...])
Also functions should be added to utils.manage_commands
that make requests to the api for the three permission related endpoints, as this is the case for command creation
Sorry, I meant if id's are both allowed and disabled for the same id |
I dont think there is a need to check for that in code, the false (i.e. disallow) permission just will take precedence. Also from my testing, this is the behaviour of permission. Let say we have 2 roles called
|
I meant if they are the same id. Just wondering what will happen then 🙃 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, there seems to be no more problems.
Co-authored-by: Sam <anothercat1259@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @slash.permission
decorator doesn't seem to work.
I tested it (code here) and map_permissions
in sync_all_commands
logged as {}
Using it with the permissions
parameter for @slash.slash
seems to be working fine.
Decorator order actually matters, the permission decorator must come after, If I am not wrong it's the same case for d.py checks decorators. |
Co-authored-by: Sam <anothercat1259@gmail.com>
Co-authored-by: Sam <anothercat1259@gmail.com>
Apologies, it's been a while, makes sense when i think about it :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Merging this pull request. Thank you for contributing! |
About this pull request
Adds support for the slash command permissions. I wanted it for my own bot, got it into a workable state, so I figure I can open a PR to add its feature for everyone if accepted. Feel free to review and test. Let me know of any feedback, happy to accept critics and improve the code 😄.
Changes
default_permission
andpermissions
option for slash command.get_all_command_permissions
andput_command_permissions
method to http module.CommandObject
.create_guild_permissions
andcreate_permission
utils method to facility defining permissions.PermissionsData
class used for checking for any permission updates since last sync, similar to howCommandData
works.sync_all_commands
method.SlashCommandPermissionsType
enum class to match discord api's ApplicationCommandPermissionType.Example decorator with subcommand:
Checklist
Python 3.6.X
.