Discord: refactor: move json.OptionT to dedicated json/option package
This commit is contained in:
parent
65bb8d21ee
commit
c642c8f306
|
@ -3,7 +3,7 @@ package api
|
|||
import (
|
||||
"github.com/diamondburned/arikawa/discord"
|
||||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
"github.com/diamondburned/arikawa/utils/json/option"
|
||||
)
|
||||
|
||||
var EndpointChannels = Endpoint + "channels/"
|
||||
|
@ -48,7 +48,7 @@ func (c *Client) CreateChannel(
|
|||
|
||||
type MoveChannelData struct {
|
||||
ID discord.Snowflake `json:"id"`
|
||||
Position json.OptionInt `json:"position"`
|
||||
Position option.Int `json:"position"`
|
||||
}
|
||||
|
||||
// MoveChannel modifies the position of channels in the guild. Requires
|
||||
|
@ -69,21 +69,21 @@ func (c *Client) Channel(channelID discord.Snowflake) (*discord.Channel, error)
|
|||
type ModifyChannelData struct {
|
||||
// All types
|
||||
Name string `json:"name,omitempty"`
|
||||
Position json.OptionInt `json:"position,omitempty"`
|
||||
Position option.Int `json:"position,omitempty"`
|
||||
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
||||
|
||||
// Text only
|
||||
Topic json.OptionString `json:"topic,omitempty"`
|
||||
NSFW json.OptionBool `json:"nsfw,omitempty"`
|
||||
Topic option.String `json:"topic,omitempty"`
|
||||
NSFW option.Bool `json:"nsfw,omitempty"`
|
||||
|
||||
// 0-21600 seconds, refer to (discord.Channel).UserRateLimit.
|
||||
UserRateLimit json.OptionInt `json:"rate_limit_per_user,omitempty"`
|
||||
UserRateLimit option.Int `json:"rate_limit_per_user,omitempty"`
|
||||
|
||||
// Voice only
|
||||
// 8000 - 96000 (or 128000 for Nitro)
|
||||
VoiceBitrate json.OptionUint `json:"bitrate,omitempty"`
|
||||
VoiceBitrate option.Uint `json:"bitrate,omitempty"`
|
||||
// 0 no limit, 1-99
|
||||
VoiceUserLimit json.OptionUint `json:"user_limit,omitempty"`
|
||||
VoiceUserLimit option.Uint `json:"user_limit,omitempty"`
|
||||
|
||||
// Text OR Voice
|
||||
CategoryID discord.Snowflake `json:"parent_id,string,omitempty"`
|
||||
|
|
12
api/guild.go
12
api/guild.go
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
"github.com/diamondburned/arikawa/discord" // for clarity
|
||||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
"github.com/diamondburned/arikawa/utils/json/option"
|
||||
)
|
||||
|
||||
var EndpointGuilds = Endpoint + "guilds/"
|
||||
|
@ -134,8 +134,8 @@ func (c *Client) LeaveGuild(id discord.Snowflake) error {
|
|||
|
||||
// https://discordapp.com/developers/docs/resources/guild#modify-guild-json-params
|
||||
type ModifyGuildData struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Region json.OptionString `json:"region,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Region option.String `json:"region,omitempty"`
|
||||
|
||||
// package d is just package discord
|
||||
Verification *discord.Verification `json:"verification_level,omitempty"`
|
||||
|
@ -155,7 +155,7 @@ type ModifyGuildData struct {
|
|||
RulesChannelID discord.Snowflake `json:"rules_channel_id,omitempty"`
|
||||
PublicUpdatesChannelID discord.Snowflake `json:"public_updates_channel_id,omitempty"`
|
||||
|
||||
PreferredLocale json.OptionString `json:"preferred_locale,omitempty"`
|
||||
PreferredLocale option.String `json:"preferred_locale,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ModifyGuild(id discord.Snowflake, data ModifyGuildData) (*discord.Guild, error) {
|
||||
|
@ -236,8 +236,8 @@ func (c *Client) AttachIntegration(
|
|||
// https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params
|
||||
type ModifyIntegrationData struct {
|
||||
ExpireBehavior *discord.ExpireBehavior `json:"expire_behavior"`
|
||||
ExpireGracePeriod json.OptionInt `json:"expire_grace_period"`
|
||||
EnableEmoticons json.OptionBool `json:"enable_emoticons"` // limited to twitch
|
||||
ExpireGracePeriod option.Int `json:"expire_grace_period"`
|
||||
EnableEmoticons option.Bool `json:"enable_emoticons"` // limited to twitch
|
||||
}
|
||||
|
||||
// ModifyIntegration requires MANAGE_GUILD.
|
||||
|
|
|
@ -3,7 +3,7 @@ package api
|
|||
import (
|
||||
"github.com/diamondburned/arikawa/discord"
|
||||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
"github.com/diamondburned/arikawa/utils/json/option"
|
||||
)
|
||||
|
||||
func (c *Client) Member(guildID, userID discord.Snowflake) (*discord.Member, error) {
|
||||
|
@ -80,9 +80,9 @@ func (c *Client) MembersAfter(
|
|||
|
||||
// AnyMemberData, all fields are optional.
|
||||
type AnyMemberData struct {
|
||||
Nick json.OptionString `json:"nick,omitempty"`
|
||||
Mute json.OptionBool `json:"mute,omitempty"`
|
||||
Deaf json.OptionBool `json:"deaf,omitempty"`
|
||||
Nick option.String `json:"nick,omitempty"`
|
||||
Mute option.Bool `json:"mute,omitempty"`
|
||||
Deaf option.Bool `json:"deaf,omitempty"`
|
||||
|
||||
Roles *[]discord.Snowflake `json:"roles,omitempty"`
|
||||
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package json
|
||||
|
||||
type (
|
||||
OptionBool = *bool
|
||||
OptionString = *string
|
||||
OptionUint = *uint
|
||||
OptionInt = *int
|
||||
)
|
||||
|
||||
var (
|
||||
True = getBool(true)
|
||||
False = getBool(false)
|
||||
|
||||
ZeroUint = Uint(0)
|
||||
ZeroInt = Int(0)
|
||||
|
||||
EmptyString = String("")
|
||||
)
|
||||
|
||||
func Uint(u uint) OptionUint {
|
||||
return &u
|
||||
}
|
||||
|
||||
func Int(i int) OptionInt {
|
||||
return &i
|
||||
}
|
||||
|
||||
func String(s string) OptionString {
|
||||
return &s
|
||||
}
|
||||
|
||||
func getBool(Bool bool) OptionBool {
|
||||
return &Bool
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package option
|
||||
|
||||
// Bool is the option type for bool.
|
||||
type Bool *bool
|
||||
|
||||
var (
|
||||
True = newBool(true)
|
||||
False = newBool(false)
|
||||
)
|
||||
|
||||
// newBool creates a new Bool with the value of the passed bool.
|
||||
func newBool(b bool) Bool {
|
||||
return &b
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package option
|
||||
|
||||
type (
|
||||
// Uint is the option type for unsigned integers (uint).
|
||||
Uint *uint
|
||||
// Int is the option type for integers (int).
|
||||
Int *int
|
||||
)
|
||||
|
||||
var (
|
||||
// ZeroUint is a Uint with 0 as value.
|
||||
ZeroUint = NewUint(0)
|
||||
// ZeroInt is an Int with 0 as value.
|
||||
ZeroInt = NewInt(0)
|
||||
)
|
||||
|
||||
// NewUint creates a new Uint using the value of the passed uint.
|
||||
func NewUint(u uint) Uint {
|
||||
return &u
|
||||
}
|
||||
|
||||
// NewInt creates a new Int using the value of the passed int.
|
||||
func NewInt(i int) Int {
|
||||
return &i
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package option
|
||||
|
||||
// String is the option type for strings.
|
||||
type String *string
|
||||
|
||||
// EmptyString is a zero-length string.
|
||||
var EmptyString = NewString("")
|
||||
|
||||
// NewString creates a new String with the value of the passed string.
|
||||
func NewString(s string) String {
|
||||
return &s
|
||||
}
|
Loading…
Reference in New Issue