From 23b0abdfec035cbb34cfbda0e0e4bbd63e81f8b2 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Fri, 8 May 2020 14:25:07 -0700 Subject: [PATCH] Adopted several packages to use NullSnowflake and NullSeconds --- api/guild.go | 10 +++++----- api/invite.go | 8 ++------ api/member.go | 8 +++----- api/role.go | 4 +--- gateway/commands.go | 8 ++++---- voice/session.go | 6 +++--- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/api/guild.go b/api/guild.go index 42a1c7c..66b69c0 100644 --- a/api/guild.go +++ b/api/guild.go @@ -127,8 +127,8 @@ type ModifyGuildData struct { Notification *discord.Notification `json:"default_message_notifications,omitempty"` ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"` - AFKChannelID *discord.Snowflake `json:"afk_channel_id,string,omitempty"` - AFKTimeout *discord.Seconds `json:"afk_timeout,omitempty"` + AFKChannelID discord.Snowflake `json:"afk_channel_id,string,omitempty"` + AFKTimeout discord.Seconds `json:"afk_timeout,omitempty"` OwnerID discord.Snowflake `json:"owner_id,omitempty"` @@ -136,9 +136,9 @@ type ModifyGuildData struct { Splash *Image `json:"splash,omitempty"` Banner *Image `json:"banner,omitempty"` - SystemChannelID *discord.Snowflake `json:"system_channel_id,omitempty"` - RulesChannelID *discord.Snowflake `json:"rules_channel_id,omitempty"` - PublicUpdatesChannelID *discord.Snowflake `json:"public_updates_channel_id,omitempty"` + SystemChannelID discord.Snowflake `json:"system_channel_id,omitempty"` + RulesChannelID discord.Snowflake `json:"rules_channel_id,omitempty"` + PublicUpdatesChannelID discord.Snowflake `json:"public_updates_channel_id,omitempty"` PreferredLocale json.OptionString `json:"preferred_locale,omitempty"` } diff --git a/api/invite.go b/api/invite.go index 553a143..93cd5c7 100644 --- a/api/invite.go +++ b/api/invite.go @@ -24,18 +24,14 @@ func (c *Client) Invite(code string) (*discord.Invite, error) { } // ChannelInvites is only for guild channels. GuildInvites is for guilds. -func (c *Client) ChannelInvites( - channelID discord.Snowflake) ([]discord.Invite, error) { - +func (c *Client) ChannelInvites(channelID discord.Snowflake) ([]discord.Invite, error) { var invs []discord.Invite return invs, c.RequestJSON(&invs, "GET", EndpointChannels+channelID.String()+"/invites") } // GuildInvites is for guilds. -func (c *Client) GuildInvites( - guildID discord.Snowflake) ([]discord.Invite, error) { - +func (c *Client) GuildInvites(guildID discord.Snowflake) ([]discord.Invite, error) { var invs []discord.Invite return invs, c.RequestJSON(&invs, "GET", EndpointGuilds+guildID.String()+"/invites") diff --git a/api/member.go b/api/member.go index 79aea47..52b3d95 100644 --- a/api/member.go +++ b/api/member.go @@ -6,9 +6,7 @@ import ( "github.com/diamondburned/arikawa/utils/json" ) -func (c *Client) Member( - guildID, userID discord.Snowflake) (*discord.Member, error) { - +func (c *Client) Member(guildID, userID discord.Snowflake) (*discord.Member, error) { var m *discord.Member return m, c.RequestJSON(&m, "GET", EndpointGuilds+guildID.String()+"/members/"+userID.String()) @@ -89,7 +87,7 @@ type AnyMemberData struct { Roles *[]discord.Snowflake `json:"roles,omitempty"` // Only for ModifyMember, requires MOVE_MEMBER - VoiceChannel *discord.Snowflake `json:"channel_id,omitempty"` + VoiceChannel discord.Snowflake `json:"channel_id,omitempty"` } // AddMember requires access(Token). @@ -98,7 +96,7 @@ func (c *Client) AddMember( data AnyMemberData) (*discord.Member, error) { // VoiceChannel doesn't belong here. - data.VoiceChannel = nil + data.VoiceChannel = -1 var param struct { Token string `json:"access_token"` diff --git a/api/role.go b/api/role.go index 8d5a068..92383a3 100644 --- a/api/role.go +++ b/api/role.go @@ -32,9 +32,7 @@ type AnyRoleData struct { Permissions discord.Permissions `json:"permissions,omitempty"` // @everyone } -func (c *Client) CreateRole( - guildID discord.Snowflake, data AnyRoleData) (*discord.Role, error) { - +func (c *Client) CreateRole(guildID discord.Snowflake, data AnyRoleData) (*discord.Role, error) { var role *discord.Role return role, c.RequestJSON( &role, "POST", diff --git a/gateway/commands.go b/gateway/commands.go index 0aafbde..8a77946 100644 --- a/gateway/commands.go +++ b/gateway/commands.go @@ -68,10 +68,10 @@ func (g *Gateway) RequestGuildMembers(data RequestGuildMembersData) error { } type UpdateVoiceStateData struct { - GuildID discord.Snowflake `json:"guild_id"` - ChannelID *discord.Snowflake `json:"channel_id"` // nullable - SelfMute bool `json:"self_mute"` - SelfDeaf bool `json:"self_deaf"` + GuildID discord.Snowflake `json:"guild_id"` + ChannelID discord.Snowflake `json:"channel_id"` // nullable + SelfMute bool `json:"self_mute"` + SelfDeaf bool `json:"self_deaf"` } func (g *Gateway) UpdateVoiceState(data UpdateVoiceStateData) error { diff --git a/voice/session.go b/voice/session.go index 433b763..df86e17 100644 --- a/voice/session.go +++ b/voice/session.go @@ -115,9 +115,9 @@ func (s *Session) JoinChannel(gID, cID discord.Snowflake, muted, deafened bool) s.speaking = false // Ensure that if `cID` is zero that it passes null to the update event. - var channelID *discord.Snowflake + var channelID discord.Snowflake = -1 if cID.Valid() { - channelID = &cID + channelID = cID } // https://discordapp.com/developers/docs/topics/voice-connections#retrieving-voice-server-information @@ -225,7 +225,7 @@ func (s *Session) Disconnect() error { err := s.session.Gateway.UpdateVoiceState(gateway.UpdateVoiceStateData{ GuildID: s.state.GuildID, - ChannelID: nil, + ChannelID: discord.NullSnowflake, SelfMute: true, SelfDeaf: true, })