Adopted several packages to use NullSnowflake and NullSeconds

This commit is contained in:
diamondburned (Forefront) 2020-05-08 14:25:07 -07:00
parent 4e1dd8e2f4
commit 23b0abdfec
6 changed files with 18 additions and 26 deletions

View File

@ -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"`
}

View File

@ -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")

View File

@ -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"`

View File

@ -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",

View File

@ -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 {

View File

@ -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,
})