Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payload type consistency fixes #198

Merged
merged 6 commits into from Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 15 additions & 15 deletions discord/application_command_create.go
Expand Up @@ -10,13 +10,13 @@ type ApplicationCommandCreate interface {
}

type SlashCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions,omitempty"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations,omitempty"`
Options []ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"` // different behavior for 0 and null, optional
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c SlashCommandCreate) MarshalJSON() ([]byte, error) {
Expand All @@ -41,10 +41,10 @@ func (c SlashCommandCreate) CommandName() string {
func (SlashCommandCreate) applicationCommandCreate() {}

type UserCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c UserCommandCreate) MarshalJSON() ([]byte, error) {
Expand All @@ -69,10 +69,10 @@ func (c UserCommandCreate) CommandName() string {
func (UserCommandCreate) applicationCommandCreate() {}

type MessageCommandCreate struct {
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions Permissions `json:"default_member_permissions"`
DMPermission bool `json:"dm_permission"`
Name string `json:"name"`
CommandNameLocalizations map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c MessageCommandCreate) MarshalJSON() ([]byte, error) {
Expand Down
18 changes: 9 additions & 9 deletions discord/application_command_update.go
Expand Up @@ -15,7 +15,7 @@ type SlashCommandUpdate struct {
Description *string `json:"description,omitempty"`
DescriptionLocalizations *map[Locale]string `json:"description_localizations,omitempty"`
Options *[]ApplicationCommandOption `json:"options,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

Expand All @@ -41,10 +41,10 @@ func (c SlashCommandUpdate) CommandName() *string {
func (SlashCommandUpdate) applicationCommandUpdate() {}

type UserCommandUpdate struct {
Name *string `json:"name"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
Name *string `json:"name,omitempty"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c UserCommandUpdate) MarshalJSON() ([]byte, error) {
Expand All @@ -69,10 +69,10 @@ func (c UserCommandUpdate) CommandName() *string {
func (UserCommandUpdate) applicationCommandUpdate() {}

type MessageCommandUpdate struct {
Name *string `json:"name"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *Permissions `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
Name *string `json:"name,omitempty"`
CommandNameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultMemberPermissions *json.Nullable[Permissions] `json:"default_member_permissions,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
}

func (c MessageCommandUpdate) MarshalJSON() ([]byte, error) {
Expand Down
2 changes: 1 addition & 1 deletion discord/auto_moderation.go
Expand Up @@ -79,7 +79,7 @@ type AutoModerationRuleCreate struct {
TriggerType AutoModerationTriggerType `json:"trigger_type"`
TriggerMetadata *AutoModerationTriggerMetadata `json:"trigger_metadata,omitempty"`
Actions []AutoModerationAction `json:"actions"`
Enabled bool `json:"enabled,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
ExemptRoles []snowflake.ID `json:"exempt_roles,omitempty"`
ExemptChannels []snowflake.ID `json:"exempt_channels,omitempty"`
}
Expand Down
18 changes: 9 additions & 9 deletions discord/channel_update.go
Expand Up @@ -37,8 +37,8 @@ type GuildVoiceChannelUpdate struct {
UserLimit *int `json:"user_limit,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RTCRegion *string `json:"rtc_region"`
VideoQualityMode *VideoQualityMode `json:"video_quality_mode"`
RTCRegion *string `json:"rtc_region,omitempty"`
VideoQualityMode *VideoQualityMode `json:"video_quality_mode,omitempty"`
}

func (GuildVoiceChannelUpdate) channelUpdate() {}
Expand All @@ -61,7 +61,7 @@ type GuildNewsChannelUpdate struct {
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
DefaultAutoArchiveDuration *int `json:"default_auto_archive_duration"`
DefaultAutoArchiveDuration *int `json:"default_auto_archive_duration,omitempty"`
}

func (GuildNewsChannelUpdate) channelUpdate() {}
Expand All @@ -87,7 +87,7 @@ type GuildStageVoiceChannelUpdate struct {
UserLimit *int `json:"user_limit,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RTCRegion *string `json:"rtc_region"`
RTCRegion *string `json:"rtc_region,omitempty"`
}

func (GuildStageVoiceChannelUpdate) channelUpdate() {}
Expand All @@ -99,15 +99,15 @@ type GuildForumChannelUpdate struct {
Topic *string `json:"topic,omitempty"`
PermissionOverwrites *[]PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
}

func (GuildForumChannelUpdate) channelUpdate() {}
func (GuildForumChannelUpdate) guildChannelUpdate() {}

type GuildChannelPositionUpdate struct {
ID snowflake.ID `json:"id"`
Position *json.Nullable[int] `json:"position"`
LockPermissions *json.Nullable[bool] `json:"lock_permissions,omitempty"`
ParentID *json.Nullable[snowflake.ID] `json:"parent_id,omitempty"`
ID snowflake.ID `json:"id"`
Position *json.Nullable[int] `json:"position"`
LockPermissions *json.Nullable[bool] `json:"lock_permissions,omitempty"`
ParentID *snowflake.ID `json:"parent_id,omitempty"`
}
4 changes: 2 additions & 2 deletions discord/emoji.go
Expand Up @@ -51,8 +51,8 @@ type EmojiCreate struct {
}

type EmojiUpdate struct {
Name string `json:"name,omitempty"`
Roles []snowflake.ID `json:"roles,omitempty"`
Name *string `json:"name,omitempty"`
Roles *[]snowflake.ID `json:"roles,omitempty"`
}

type ReactionEmoji struct {
Expand Down
38 changes: 19 additions & 19 deletions discord/guild.go
Expand Up @@ -275,25 +275,25 @@ type GuildCreate struct {

// GuildUpdate is the payload used to update a Guild
type GuildUpdate struct {
Name string `json:"name,omitempty"`
VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
DefaultMessageNotificationLevel *MessageNotificationsLevel `json:"default_message_notification_level,omitempty"`
ExplicitContentFilterLevel *ExplicitContentFilterLevel `json:"explicit_content_filter_level,omitempty"`
AFKChannelID *snowflake.ID `json:"afk_channel_id,omitempty"`
AFKTimeout *int `json:"afk_timeout,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
OwnerID *snowflake.ID `json:"owner_id,omitempty"`
Splash *json.Nullable[Icon] `json:"splash,omitempty"`
DiscoverySplash *json.Nullable[Icon] `json:"discovery_splash,omitempty"`
Banner *json.Nullable[Icon] `json:"banner,omitempty"`
SystemChannelID *snowflake.ID `json:"system_channel_id,omitempty"`
SystemChannelFlags *SystemChannelFlags `json:"system_channel_flags,omitempty"`
RulesChannelID *snowflake.ID `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id,omitempty"`
PreferredLocale *string `json:"preferred_locale,omitempty"`
Features []GuildFeature `json:"features,omitempty"`
Description *string `json:"description,omitempty"`
BoostProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
Name *string `json:"name,omitempty"`
VerificationLevel *json.Nullable[VerificationLevel] `json:"verification_level,omitempty"`
DefaultMessageNotificationLevel *json.Nullable[MessageNotificationsLevel] `json:"default_message_notification_level,omitempty"`
ExplicitContentFilterLevel *json.Nullable[ExplicitContentFilterLevel] `json:"explicit_content_filter_level,omitempty"`
AFKChannelID *snowflake.ID `json:"afk_channel_id,omitempty"`
AFKTimeout *int `json:"afk_timeout,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
OwnerID *snowflake.ID `json:"owner_id,omitempty"`
Splash *json.Nullable[Icon] `json:"splash,omitempty"`
DiscoverySplash *json.Nullable[Icon] `json:"discovery_splash,omitempty"`
Banner *json.Nullable[Icon] `json:"banner,omitempty"`
SystemChannelID *snowflake.ID `json:"system_channel_id,omitempty"`
SystemChannelFlags *SystemChannelFlags `json:"system_channel_flags,omitempty"`
RulesChannelID *snowflake.ID `json:"rules_channel_id,omitempty"`
PublicUpdatesChannelID *snowflake.ID `json:"public_updates_channel_id,omitempty"`
PreferredLocale *string `json:"preferred_locale,omitempty"`
Features *[]GuildFeature `json:"features,omitempty"`
Description *string `json:"description,omitempty"`
BoostProgressBarEnabled *bool `json:"premium_progress_bar_enabled,omitempty"`
}

type NSFWLevel int
Expand Down
3 changes: 2 additions & 1 deletion discord/guild_scheduled_event.go
Expand Up @@ -35,9 +35,10 @@ type GuildScheduledEventCreate struct {
Name string `json:"name"`
PrivacyLevel ScheduledEventPrivacyLevel `json:"privacy_level"`
ScheduledStartTime time.Time `json:"scheduled_start_time"`
ScheduledEndTime time.Time `json:"scheduled_end_time,omitempty"`
ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"`
Description string `json:"description,omitempty"`
EntityType ScheduledEventEntityType `json:"entity_type"`
Image *Icon `json:"image,omitempty"`
}

type GuildScheduledEventUpdate struct {
Expand Down
4 changes: 2 additions & 2 deletions discord/invite.go
Expand Up @@ -74,8 +74,8 @@ type InviteGuild struct {
}

type InviteCreate struct {
MaxAge int `json:"max_age,omitempty"`
MaxUses int `json:"max_uses,omitempty"`
MaxAge *int `json:"max_age,omitempty"`
MaxUses *int `json:"max_uses,omitempty"`
Temporary bool `json:"temporary,omitempty"`
Unique bool `json:"unique,omitempty"`
TargetType InviteTargetType `json:"target_type,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions discord/permission_overwrite.go
Expand Up @@ -143,8 +143,8 @@ type PermissionOverwriteUpdate interface {
}

type RolePermissionOverwriteUpdate struct {
Allow Permissions `json:"allow"`
Deny Permissions `json:"deny"`
Allow *Permissions `json:"allow,omitempty"`
Deny *Permissions `json:"deny,omitempty"`
}

func (u RolePermissionOverwriteUpdate) MarshalJSON() ([]byte, error) {
Expand All @@ -163,8 +163,8 @@ func (RolePermissionOverwriteUpdate) Type() PermissionOverwriteType {
}

type MemberPermissionOverwriteUpdate struct {
Allow Permissions `json:"allow"`
Deny Permissions `json:"deny"`
Allow *Permissions `json:"allow,omitempty"`
Deny *Permissions `json:"deny,omitempty"`
}

func (u MemberPermissionOverwriteUpdate) MarshalJSON() ([]byte, error) {
Expand Down
26 changes: 13 additions & 13 deletions discord/role.go
Expand Up @@ -53,30 +53,30 @@ type RoleTag struct {

// RoleCreate is the payload to create a Role
type RoleCreate struct {
Name string `json:"name,omitempty"`
Permissions Permissions `json:"permissions,omitempty"`
Color int `json:"color,omitempty"`
Hoist bool `json:"hoist,omitempty"`
Icon *Icon `json:"icon,omitempty"`
Emoji *string `json:"unicode_emoji,omitempty"`
Mentionable bool `json:"mentionable,omitempty"`
Name string `json:"name,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
Color int `json:"color,omitempty"`
Hoist bool `json:"hoist,omitempty"`
Icon *Icon `json:"icon,omitempty"`
Emoji string `json:"unicode_emoji,omitempty"`
Mentionable bool `json:"mentionable,omitempty"`
}

// RoleUpdate is the payload to update a Role
type RoleUpdate struct {
Name *string `json:"name"`
Permissions *Permissions `json:"permissions"`
Color *int `json:"color"`
Hoist *bool `json:"hoist"`
Name *string `json:"name,omitempty"`
Permissions *Permissions `json:"permissions,omitempty"`
Color *int `json:"color,omitempty"`
Hoist *bool `json:"hoist,omitempty"`
Icon *json.Nullable[Icon] `json:"icon,omitempty"`
Emoji *string `json:"unicode_emoji,omitempty"`
Mentionable *bool `json:"mentionable"`
Mentionable *bool `json:"mentionable,omitempty"`
}

// RolePositionUpdate is the payload to update a Role(s) position
type RolePositionUpdate struct {
ID snowflake.ID `json:"id"`
Position *int `json:"position"`
Position *int `json:"position,omitempty"`
}

// PartialRole holds basic info about a Role
Expand Down
2 changes: 1 addition & 1 deletion discord/stage_instance.go
Expand Up @@ -30,7 +30,7 @@ type StageInstanceCreate struct {
ChannelID snowflake.ID `json:"channel_id"`
Topic string `json:"topic,omitempty"`
PrivacyLevel StagePrivacyLevel `json:"privacy_level,omitempty"`
SendStartNotification bool `json:"send_start_notification"`
SendStartNotification bool `json:"send_start_notification,omitempty"`
}

type StageInstanceUpdate struct {
Expand Down
3 changes: 2 additions & 1 deletion discord/thread.go
Expand Up @@ -5,6 +5,7 @@ import "github.com/disgoorg/disgo/json"
type ThreadCreateFromMessage struct {
Name string `json:"name"`
AutoArchiveDuration AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
}

type ForumThreadCreate struct {
Expand Down Expand Up @@ -75,7 +76,7 @@ func (GuildPublicThreadCreate) Type() ChannelType {
type GuildPrivateThreadCreate struct {
Name string `json:"name"`
AutoArchiveDuration AutoArchiveDuration `json:"auto_archive_duration,omitempty"`
Invitable bool `json:"invitable"`
Invitable bool `json:"invitable,omitempty"`
}

func (c GuildPrivateThreadCreate) MarshalJSON() ([]byte, error) {
Expand Down
4 changes: 2 additions & 2 deletions discord/user.go
Expand Up @@ -127,6 +127,6 @@ const (

// SelfUserUpdate is the payload used to update the OAuth2User
type SelfUserUpdate struct {
Username string `json:"username"`
Avatar *json.Nullable[Icon] `json:"avatar"`
Username string `json:"username,omitempty"`
Avatar *json.Nullable[Icon] `json:"avatar,omitempty"`
}
9 changes: 7 additions & 2 deletions discord/voice_state.go
Expand Up @@ -23,8 +23,13 @@ type VoiceState struct {
RequestToSpeakTimestamp *time.Time `json:"request_to_speak_timestamp"`
}

type UserVoiceStateUpdate struct {
ChannelID snowflake.ID `json:"channel_id"`
type CurrentUserVoiceStateUpdate struct {
ChannelID *snowflake.ID `json:"channel_id,omitempty"`
Suppress *bool `json:"suppress,omitempty"`
RequestToSpeakTimestamp *json.Nullable[time.Time] `json:"request_to_speak_timestamp,omitempty"`
}

type UserVoiceStateUpdate struct {
ChannelID *snowflake.ID `json:"channel_id,omitempty"`
Suppress *bool `json:"suppress,omitempty"`
}
6 changes: 3 additions & 3 deletions discord/webhook.go
Expand Up @@ -351,11 +351,11 @@ type WebhookCreate struct {
type WebhookUpdate struct {
Name *string `json:"name,omitempty"`
Avatar *json.Nullable[Icon] `json:"avatar,omitempty"`
ChannelID *snowflake.ID `json:"channel_id"`
ChannelID *snowflake.ID `json:"channel_id,omitempty"`
}

// WebhookUpdateWithToken is used to update a Webhook with the token
type WebhookUpdateWithToken struct {
Name *string `json:"name,omitempty"`
Avatar *string `json:"avatar,omitempty"`
Name *string `json:"name,omitempty"`
Avatar *json.Nullable[Icon] `json:"avatar,omitempty"`
}