Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/nosedrum/application_command.ex
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ defmodule Nosedrum.ApplicationCommand do
"""
@callback options() :: [option]

@doc """
An optional callback that returns a bitset for the required default permissions to run this command.

Example callback that requires that the user has the permission to ban members to be able to see and execute this command

```elixir
def default_member_permissions, do:
Nostrum.Permission.to_bitset([:ban_members])
```
"""
Comment on lines +275 to +284
Copy link
Owner

Choose a reason for hiding this comment

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

Let's dedent this by two spaces so it matches the rest of the module

Suggested change
@doc """
An optional callback that returns a bitset for the required default permissions to run this command.
Example callback that requires that the user has the permission to ban members to be able to see and execute this command
```elixir
def default_member_permissions, do:
Nostrum.Permission.to_bitset([:ban_members])
```
"""
@doc """
An optional callback that returns a bitset for the required default permissions to run this command.
Example callback that requires that the user has the permission to ban members to be able to see and execute this command
```elixir
def default_member_permissions, do:
Nostrum.Permission.to_bitset([:ban_members])

"""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll need a bit more time to do your recommended changes for personal reasons, but it's noted!

Copy link
Owner

Choose a reason for hiding this comment

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

No rush 🙂 If I can help out let me know!

@callback default_member_permissions() :: integer

@doc """
Execute the command invoked by the given `t:Nostrum.Struct.Interaction.t/0`. Returns a `t:response/0`

Expand All @@ -289,5 +301,5 @@ defmodule Nosedrum.ApplicationCommand do
"""
@callback command(interaction :: Interaction.t()) :: response

@optional_callbacks [options: 0]
@optional_callbacks [options: 0, default_member_permissions: 0]
end
8 changes: 7 additions & 1 deletion lib/nosedrum/storage/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,17 @@ defmodule Nosedrum.Storage.Dispatcher do
[]
end

%{
payload = %{
type: parse_type(command.type()),
name: name
}
|> put_type_specific_fields(command, options)

if function_exported?(command, :default_member_permissions, 0) do
Map.put(payload, :default_member_permissions, command.default_member_permissions())
else
payload
end
end

# This seems like a hacky way to unwrap the outer list...
Expand Down