From 9880afc41098c4a086bb0dba93da1135deac9260 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 13 May 2021 16:39:02 +0800 Subject: [PATCH 1/4] Fix documentation typos. --- docs/gettingstarted.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index c05b5063a..3e14ed7ee 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -280,7 +280,7 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running .. code-block:: python from discord_slash.utils.manage_commands import create_permission - from discord_slash.model import SubcommandApplicationPermissionType + from discord_slash.model import SlashCommandPermissionType @slash.slash(name="test", description="This is just a test command, nothing more.", @@ -302,8 +302,8 @@ Alternatively you can use the ``@slash.permission`` decorator to define your gui @slash.slash(name="test", description="This is just a test command, nothing more.") - @slash.permission(guild_id = 12345678, - permission = [ + @slash.permission(guild_id=12345678, + permissions=[ create_permission(99999999, SlashCommandPermissionType.ROLE, True), create_permission(88888888, SlashCommandPermissionType.USER, False) ]) From 95faa16dd4166b0a2e514161e13e6740b9d19e9c Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 13 May 2021 16:39:19 +0800 Subject: [PATCH 2/4] Default permissions to dict and not list. --- discord_slash/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord_slash/model.py b/discord_slash/model.py index a14ab17ff..cb52abc5c 100644 --- a/discord_slash/model.py +++ b/discord_slash/model.py @@ -195,7 +195,7 @@ def __init__(self, name, cmd): # Let's reuse old command formatting. super().__init__(name, cmd) self.has_subcommands = cmd["has_subcommands"] self.default_permission = cmd["default_permission"] - self.permissions = cmd["api_permissions"] or [] + self.permissions = cmd["api_permissions"] or {} class SubcommandObject(CommandObject): From e94683a7292d1a133ad671dd417ff42fa13fcad4 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 13 May 2021 16:53:20 +0800 Subject: [PATCH 3/4] Improve docs string for permissions. --- discord_slash/client.py | 10 +++++----- discord_slash/cog_ext.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/discord_slash/client.py b/discord_slash/client.py index 847578d84..2ed7eb78f 100644 --- a/discord_slash/client.py +++ b/discord_slash/client.py @@ -441,7 +441,7 @@ def add_slash_command(self, guild_ids: typing.List[int] = None, options: list = None, default_permission: bool = True, - permissions: dict = None, + permissions: typing.Dict[int, list] = None, connector: dict = None, has_subcommands: bool = False): """ @@ -463,7 +463,7 @@ def add_slash_command(self, :type options: list :param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``. :type default_permission: bool - :param permissions: Permission requirements of the slash command. Default ``None``. + :param permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``. :type permissions: dict :param connector: Kwargs connector for the command. Default ``None``. :type connector: dict @@ -510,7 +510,7 @@ def add_subcommand(self, description: str = None, base_description: str = None, base_default_permission: bool = True, - base_permissions: dict = None, + base_permissions: typing.Dict[int, list] = None, subcommand_group_description: str = None, guild_ids: typing.List[int] = None, options: list = None, @@ -532,8 +532,8 @@ def add_subcommand(self, :type base_description: str :param default_permission: Sets if users have permission to run base command by default, when no permissions are set. Default ``True``. :type default_permission: bool - :param permissions: Permission requirements of the base command. Default ``None``. - :type permissions: dict + :param base_permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``. + :type base_permissions: dict :param subcommand_group_description: Description of the subcommand_group. Default ``None``. :type subcommand_group_description: str :param guild_ids: List of guild ID of where the command will be used. Default ``None``, which will be global command. diff --git a/discord_slash/cog_ext.py b/discord_slash/cog_ext.py index f14804db5..1d5589d5c 100644 --- a/discord_slash/cog_ext.py +++ b/discord_slash/cog_ext.py @@ -10,7 +10,7 @@ def cog_slash(*, guild_ids: typing.List[int] = None, options: typing.List[dict] = None, default_permission: bool = True, - permissions: dict = None, + permissions: typing.Dict[int, list] = None, connector: dict = None): """ Decorator for Cog to add slash command.\n @@ -38,7 +38,7 @@ async def ping(self, ctx: SlashContext): :type options: List[dict] :param default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``. :type default_permission: bool - :param permissions: Permission requirements of the slash command. Default ``None``. + :param permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``. :type permissions: dict :param connector: Kwargs connector for the command. Default ``None``. :type connector: dict @@ -72,7 +72,7 @@ def cog_subcommand(*, base_description: str = None, base_desc: str = None, base_default_permission: bool = True, - base_permissions: dict = None, + base_permissions: typing.Dict[int, list] = None, subcommand_group_description: str = None, sub_group_desc: str = None, guild_ids: typing.List[int] = None, @@ -107,7 +107,7 @@ async def group_say(self, ctx: SlashContext, text: str): :param base_desc: Alias of ``base_description``. :param base_default_permission: Sets if users have permission to run slash command by default, when no permissions are set. Default ``True``. :type base_default_permission: bool - :param base_permissions: Permission requirements of the slash command. Default ``None``. + :param base_permissions: Dictionary of permissions of the slash command. Key being target guild_id and value being a list of permissions to apply. Default ``None``. :type base_permissions: dict :param subcommand_group_description: Description of the subcommand_group. Default ``None``. :type subcommand_group_description: str From 8d364a5dc675bbce437ad9e58d2ed3fb1ec5aff0 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Thu, 13 May 2021 16:59:11 +0800 Subject: [PATCH 4/4] Make some things in gettingstarted docs clearer. --- docs/gettingstarted.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/gettingstarted.rst b/docs/gettingstarted.rst index 3e14ed7ee..2f5ab68e3 100644 --- a/docs/gettingstarted.rst +++ b/docs/gettingstarted.rst @@ -269,8 +269,8 @@ This is an example of how a single permission will look when represented as a js "permission": True } -Now, let take a look simple example. The slash command decorator have a permissions parameter Where -it takes in a dictionary. The key being the guild to apply permissions on, and value being the list +Now, let take a look at an example. The slash command decorator have a permissions parameter where +it takes in a dictionary. The key being the guild id to apply permissions on, and value being the list of permissions to apply. For each permission, we can use the handy ``create_permission`` method to build the permission json explain above. @@ -293,12 +293,13 @@ role with id ``99999999`` and disallowing user with id ``88888888`` from running async def test(ctx): await ctx.send(content="Hello World!") -Alternatively you can use the ``@slash.permission`` decorator to define your guild permissions for the command. +Alternatively, you can use the ``@slash.permission`` decorator to define your guild permissions for the +command as show in the following example: .. code-block:: python from discord_slash.utils.manage_commands import create_permission - from discord_slash.model import SubcommandApplicationPermissionType + from discord_slash.model import SlashCommandPermissionType @slash.slash(name="test", description="This is just a test command, nothing more.")