mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-01-07 04:27:18 +00:00
Discord/API: implement changes to permission, allow and deny fields (#141)
This commit is contained in:
parent
af7f413cea
commit
a7e9439109
|
@ -167,13 +167,14 @@ func (c *Client) DeleteChannel(channelID discord.ChannelID) error {
|
||||||
return c.FastRequest("DELETE", EndpointChannels+channelID.String())
|
return c.FastRequest("DELETE", EndpointChannels+channelID.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params
|
||||||
type EditChannelPermissionData struct {
|
type EditChannelPermissionData struct {
|
||||||
// Type is either "role" or "member".
|
// Type is either "role" or "member".
|
||||||
Type discord.OverwriteType `json:"type"`
|
Type discord.OverwriteType `json:"type"`
|
||||||
// Allow is a permission bit set for granted permissions.
|
// Allow is a permission bit set for granted permissions.
|
||||||
Allow discord.Permissions `json:"allow"`
|
Allow discord.Permissions `json:"allow,string"`
|
||||||
// Deny is a permission bit set for denied permissions.
|
// Deny is a permission bit set for denied permissions.
|
||||||
Deny discord.Permissions `json:"deny"`
|
Deny discord.Permissions `json:"deny,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditChannelPermission edits the channel's permission overwrites for a user
|
// EditChannelPermission edits the channel's permission overwrites for a user
|
||||||
|
|
|
@ -42,7 +42,7 @@ type CreateRoleData struct {
|
||||||
// Permissions is the bitwise value of the enabled/disabled permissions.
|
// Permissions is the bitwise value of the enabled/disabled permissions.
|
||||||
//
|
//
|
||||||
// Default: @everyone permissions in guild
|
// Default: @everyone permissions in guild
|
||||||
Permissions discord.Permissions `json:"permissions,omitempty"`
|
Permissions discord.Permissions `json:"permissions,omitempty,string"`
|
||||||
// Color is the RGB color value of the role.
|
// Color is the RGB color value of the role.
|
||||||
//
|
//
|
||||||
// Default: 0
|
// Default: 0
|
||||||
|
@ -98,7 +98,7 @@ type ModifyRoleData struct {
|
||||||
// Name is the name of the role.
|
// Name is the name of the role.
|
||||||
Name option.NullableString `json:"name,omitempty"`
|
Name option.NullableString `json:"name,omitempty"`
|
||||||
// Permissions is the bitwise value of the enabled/disabled permissions.
|
// Permissions is the bitwise value of the enabled/disabled permissions.
|
||||||
Permissions *discord.Permissions `json:"permissions,omitempty"`
|
Permissions *discord.Permissions `json:"permissions,omitempty,string"`
|
||||||
// Permissions is the bitwise value of the enabled/disabled permissions.
|
// Permissions is the bitwise value of the enabled/disabled permissions.
|
||||||
Color option.NullableColor `json:"color,omitempty"`
|
Color option.NullableColor `json:"color,omitempty"`
|
||||||
// Hoist specifies whether the role should be displayed separately in the
|
// Hoist specifies whether the role should be displayed separately in the
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package discord
|
package discord
|
||||||
|
|
||||||
|
import "github.com/diamondburned/arikawa/utils/json"
|
||||||
|
|
||||||
// https://discord.com/developers/docs/resources/channel#channel-object
|
// https://discord.com/developers/docs/resources/channel#channel-object
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
// ID is the id of this channel.
|
// ID is the id of this channel.
|
||||||
|
@ -103,13 +105,37 @@ var (
|
||||||
// https://discord.com/developers/docs/resources/channel#overwrite-object
|
// https://discord.com/developers/docs/resources/channel#overwrite-object
|
||||||
type Overwrite struct {
|
type Overwrite struct {
|
||||||
// ID is the role or user id.
|
// ID is the role or user id.
|
||||||
ID Snowflake `json:"id,string"`
|
ID Snowflake `json:"id"`
|
||||||
// Type is either "role" or "member".
|
// Type is either "role" or "member".
|
||||||
Type OverwriteType `json:"type"`
|
Type OverwriteType `json:"type"`
|
||||||
// Allow is a permission bit set for granted permissions.
|
// Allow is a permission bit set for granted permissions.
|
||||||
Allow Permissions `json:"allow"`
|
Allow Permissions `json:"allow,string"`
|
||||||
// Deny is a permission bit set for denied permissions.
|
// Deny is a permission bit set for denied permissions.
|
||||||
Deny Permissions `json:"deny"`
|
Deny Permissions `json:"deny,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals the passed json data into the Overwrite.
|
||||||
|
// This is necessary because Discord has different names for fields when
|
||||||
|
// sending than receiving.
|
||||||
|
func (o *Overwrite) UnmarshalJSON(data []byte) (err error) {
|
||||||
|
var recv struct {
|
||||||
|
ID Snowflake `json:"id"`
|
||||||
|
Type OverwriteType `json:"type"`
|
||||||
|
Allow Permissions `json:"allow_new,string"`
|
||||||
|
Deny Permissions `json:"deny_new,string"`
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &recv)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
o.ID = recv.ID
|
||||||
|
o.Type = recv.Type
|
||||||
|
o.Allow = recv.Allow
|
||||||
|
o.Deny = recv.Deny
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type OverwriteType string
|
type OverwriteType string
|
||||||
|
|
|
@ -23,7 +23,7 @@ type Guild struct {
|
||||||
|
|
||||||
// Permissions are the total permissions for the user in the guild
|
// Permissions are the total permissions for the user in the guild
|
||||||
// (excludes overrides).
|
// (excludes overrides).
|
||||||
Permissions Permissions `json:"permissions,omitempty"`
|
Permissions Permissions `json:"permissions_new,omitempty,string"`
|
||||||
|
|
||||||
// VoiceRegion is the voice region id for the guild.
|
// VoiceRegion is the voice region id for the guild.
|
||||||
VoiceRegion string `json:"region"`
|
VoiceRegion string `json:"region"`
|
||||||
|
@ -297,7 +297,7 @@ type Role struct {
|
||||||
Position int `json:"position"`
|
Position int `json:"position"`
|
||||||
|
|
||||||
// Permissions is the permission bit set.
|
// Permissions is the permission bit set.
|
||||||
Permissions Permissions `json:"permissions"`
|
Permissions Permissions `json:"permissions_new,string"`
|
||||||
|
|
||||||
// Manages specifies whether this role is managed by an integration.
|
// Manages specifies whether this role is managed by an integration.
|
||||||
Managed bool `json:"managed"`
|
Managed bool `json:"managed"`
|
||||||
|
|
Loading…
Reference in a new issue