mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-02-10 21:43:16 +00:00
Discord: Minor changes in Overwrite for v2
This commit changes the Overwrite type to omit the old "_new" API and use the new field names, which are striings-serialized. The OverwriteType is now also a strings-serialized number.
This commit is contained in:
parent
8aa60ebf8e
commit
7a757209c2
|
@ -170,7 +170,7 @@ func (c *Client) DeleteChannel(channelID discord.ChannelID) error {
|
||||||
// https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params
|
// 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,string"`
|
||||||
// Allow is a permission bit set for granted permissions.
|
// Allow is a permission bit set for granted permissions.
|
||||||
Allow discord.Permissions `json:"allow,string"`
|
Allow discord.Permissions `json:"allow,string"`
|
||||||
// Deny is a permission bit set for denied permissions.
|
// Deny is a permission bit set for denied permissions.
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
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.
|
||||||
|
@ -107,42 +105,18 @@ type Overwrite struct {
|
||||||
// ID is the role or user id.
|
// ID is the role or user id.
|
||||||
ID Snowflake `json:"id"`
|
ID Snowflake `json:"id"`
|
||||||
// Type is either "role" or "member".
|
// Type is either "role" or "member".
|
||||||
Type OverwriteType `json:"type"`
|
Type OverwriteType `json:"type,string"`
|
||||||
// Allow is a permission bit set for granted permissions.
|
// Allow is a permission bit set for granted permissions.
|
||||||
Allow Permissions `json:"allow,string"`
|
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,string"`
|
Deny Permissions `json:"deny,string"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals the passed json data into the Overwrite.
|
type OverwriteType uint8
|
||||||
// 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
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// OverwriteRole is an overwrite for a role.
|
// OverwriteRole is an overwrite for a role.
|
||||||
OverwriteRole OverwriteType = "role"
|
OverwriteRole OverwriteType = iota
|
||||||
// OverwriteMember is an overwrite for a member.
|
// OverwriteMember is an overwrite for a member.
|
||||||
OverwriteMember OverwriteType = "member"
|
OverwriteMember
|
||||||
)
|
)
|
||||||
|
|
|
@ -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_new,omitempty,string"`
|
Permissions Permissions `json:"permissions,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_new,string"`
|
Permissions Permissions `json:"permissions,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