mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-10-01 06:48:51 +00:00
discord: Add permission fields to Command (#326)
* api/discord: add DefaultMemberPermissions and DMPermission to commands * api/discord: invert DMPermission to match NoDefaultPermission
This commit is contained in:
parent
df0fa66c29
commit
4b6bc657dc
|
@ -26,6 +26,8 @@ type CreateCommandData struct {
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
DescriptionLocalizations discord.StringLocales `json:"description_localizations,omitempty"`
|
DescriptionLocalizations discord.StringLocales `json:"description_localizations,omitempty"`
|
||||||
Options discord.CommandOptions `json:"options,omitempty"`
|
Options discord.CommandOptions `json:"options,omitempty"`
|
||||||
|
DefaultMemberPermissions *discord.Permissions `json:"default_member_permissions,string,omitempty"`
|
||||||
|
NoDMPermission bool `json:"-"`
|
||||||
NoDefaultPermission bool `json:"-"`
|
NoDefaultPermission bool `json:"-"`
|
||||||
Type discord.CommandType `json:"type,omitempty"`
|
Type discord.CommandType `json:"type,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -34,6 +36,7 @@ func (c CreateCommandData) MarshalJSON() ([]byte, error) {
|
||||||
type RawCreateCommandData CreateCommandData
|
type RawCreateCommandData CreateCommandData
|
||||||
cmd := struct {
|
cmd := struct {
|
||||||
RawCreateCommandData
|
RawCreateCommandData
|
||||||
|
DMPermission bool `json:"dm_permission"`
|
||||||
DefaultPermission bool `json:"default_permission"`
|
DefaultPermission bool `json:"default_permission"`
|
||||||
}{RawCreateCommandData: (RawCreateCommandData)(c)}
|
}{RawCreateCommandData: (RawCreateCommandData)(c)}
|
||||||
|
|
||||||
|
@ -41,6 +44,7 @@ func (c CreateCommandData) MarshalJSON() ([]byte, error) {
|
||||||
// meaning of the field (>No<DefaultPermission) to match Go's default
|
// meaning of the field (>No<DefaultPermission) to match Go's default
|
||||||
// value, false.
|
// value, false.
|
||||||
cmd.DefaultPermission = !c.NoDefaultPermission
|
cmd.DefaultPermission = !c.NoDefaultPermission
|
||||||
|
cmd.DMPermission = !c.NoDMPermission
|
||||||
|
|
||||||
return json.Marshal(cmd)
|
return json.Marshal(cmd)
|
||||||
}
|
}
|
||||||
|
@ -49,6 +53,7 @@ func (c *CreateCommandData) UnmarshalJSON(data []byte) error {
|
||||||
type RawCreateCommandData CreateCommandData
|
type RawCreateCommandData CreateCommandData
|
||||||
cmd := struct {
|
cmd := struct {
|
||||||
*RawCreateCommandData
|
*RawCreateCommandData
|
||||||
|
DMPermission bool `json:"dm_permission"`
|
||||||
DefaultPermission bool `json:"default_permission"`
|
DefaultPermission bool `json:"default_permission"`
|
||||||
}{RawCreateCommandData: (*RawCreateCommandData)(c)}
|
}{RawCreateCommandData: (*RawCreateCommandData)(c)}
|
||||||
if err := json.Unmarshal(data, &cmd); err != nil {
|
if err := json.Unmarshal(data, &cmd); err != nil {
|
||||||
|
@ -59,6 +64,7 @@ func (c *CreateCommandData) UnmarshalJSON(data []byte) error {
|
||||||
// meaning of the field (>No<DefaultPermission) to match Go's default
|
// meaning of the field (>No<DefaultPermission) to match Go's default
|
||||||
// value, false.
|
// value, false.
|
||||||
c.NoDefaultPermission = !cmd.DefaultPermission
|
c.NoDefaultPermission = !cmd.DefaultPermission
|
||||||
|
c.NoDMPermission = !cmd.DMPermission
|
||||||
|
|
||||||
// Discord defaults type to 1 if omitted.
|
// Discord defaults type to 1 if omitted.
|
||||||
if c.Type == 0 {
|
if c.Type == 0 {
|
||||||
|
|
|
@ -52,6 +52,11 @@ type Command struct {
|
||||||
//
|
//
|
||||||
// It is only present on ChatInputCommands.
|
// It is only present on ChatInputCommands.
|
||||||
Options CommandOptions `json:"options,omitempty"`
|
Options CommandOptions `json:"options,omitempty"`
|
||||||
|
// DefaultMemberPermissions is set of permissions.
|
||||||
|
DefaultMemberPermissions *Permissions `json:"default_member_permissions,string,omitempty"`
|
||||||
|
// NoDMPermission indicates whether the command is NOT available in DMs with
|
||||||
|
// the app, only for globally-scoped commands. By default, commands are visible.
|
||||||
|
NoDMPermission bool `json:"-"`
|
||||||
// NoDefaultPermissions defines whether the command is NOT enabled by
|
// NoDefaultPermissions defines whether the command is NOT enabled by
|
||||||
// default when the app is added to a guild.
|
// default when the app is added to a guild.
|
||||||
NoDefaultPermission bool `json:"-"`
|
NoDefaultPermission bool `json:"-"`
|
||||||
|
@ -112,6 +117,7 @@ func (c *Command) MarshalJSON() ([]byte, error) {
|
||||||
type RawCommand Command
|
type RawCommand Command
|
||||||
cmd := struct {
|
cmd := struct {
|
||||||
*RawCommand
|
*RawCommand
|
||||||
|
DMPermission bool `json:"dm_permission"`
|
||||||
DefaultPermission bool `json:"default_permission"`
|
DefaultPermission bool `json:"default_permission"`
|
||||||
}{RawCommand: (*RawCommand)(c)}
|
}{RawCommand: (*RawCommand)(c)}
|
||||||
|
|
||||||
|
@ -119,6 +125,7 @@ func (c *Command) MarshalJSON() ([]byte, error) {
|
||||||
// meaning of the field (>No<DefaultPermission) to match Go's default
|
// meaning of the field (>No<DefaultPermission) to match Go's default
|
||||||
// value, false.
|
// value, false.
|
||||||
cmd.DefaultPermission = !c.NoDefaultPermission
|
cmd.DefaultPermission = !c.NoDefaultPermission
|
||||||
|
cmd.DMPermission = !c.NoDMPermission
|
||||||
|
|
||||||
return json.Marshal(cmd)
|
return json.Marshal(cmd)
|
||||||
}
|
}
|
||||||
|
@ -128,6 +135,7 @@ func (c *Command) UnmarshalJSON(data []byte) error {
|
||||||
|
|
||||||
cmd := struct {
|
cmd := struct {
|
||||||
*rawCommand
|
*rawCommand
|
||||||
|
DMPermission bool `json:"dm_permission"`
|
||||||
DefaultPermission bool `json:"default_permission"`
|
DefaultPermission bool `json:"default_permission"`
|
||||||
}{
|
}{
|
||||||
rawCommand: (*rawCommand)(c),
|
rawCommand: (*rawCommand)(c),
|
||||||
|
@ -141,6 +149,7 @@ func (c *Command) UnmarshalJSON(data []byte) error {
|
||||||
// meaning of the field (>No<DefaultPermission) to match Go's default
|
// meaning of the field (>No<DefaultPermission) to match Go's default
|
||||||
// value, false.
|
// value, false.
|
||||||
c.NoDefaultPermission = !cmd.DefaultPermission
|
c.NoDefaultPermission = !cmd.DefaultPermission
|
||||||
|
c.NoDMPermission = !cmd.DMPermission
|
||||||
|
|
||||||
// Discord defaults type to 1 if omitted.
|
// Discord defaults type to 1 if omitted.
|
||||||
if c.Type == 0 {
|
if c.Type == 0 {
|
||||||
|
|
|
@ -144,6 +144,14 @@ const (
|
||||||
PermissionManageEvents
|
PermissionManageEvents
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewPermissions(p ...Permissions) *Permissions {
|
||||||
|
var perm Permissions
|
||||||
|
for _, permission := range p {
|
||||||
|
perm |= permission
|
||||||
|
}
|
||||||
|
return &perm
|
||||||
|
}
|
||||||
|
|
||||||
func (p Permissions) Has(perm Permissions) bool {
|
func (p Permissions) Has(perm Permissions) bool {
|
||||||
return HasFlag(uint64(p), uint64(perm))
|
return HasFlag(uint64(p), uint64(perm))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue