mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-03-23 02:19:22 +00:00
API: implement option and nullable types.
This commit is contained in:
parent
b30a1fb7d2
commit
b17c32187e
|
@ -27,8 +27,8 @@ type CreateChannelData struct {
|
|||
|
||||
UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
|
||||
|
||||
NSFW bool `json:"nsfw"`
|
||||
Position int `json:"position,omitempty"`
|
||||
NSFW bool `json:"nsfw,omitempty"`
|
||||
Position option.Int `json:"position,omitempty"`
|
||||
|
||||
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
||||
CategoryID discord.Snowflake `json:"parent_id,string,omitempty"`
|
||||
|
@ -68,9 +68,11 @@ func (c *Client) Channel(channelID discord.Snowflake) (*discord.Channel, error)
|
|||
|
||||
type ModifyChannelData struct {
|
||||
// All types
|
||||
Name string `json:"name,omitempty"`
|
||||
Position option.Int `json:"position,omitempty"`
|
||||
Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
// Type allows conversions between text and news channels.
|
||||
Type *discord.ChannelType `json:"type,omitempty"`
|
||||
Position option.Int `json:"position,omitempty"`
|
||||
Permissions *[]discord.Overwrite `json:"permission_overwrites,omitempty"`
|
||||
|
||||
// Text only
|
||||
Topic option.String `json:"topic,omitempty"`
|
||||
|
|
|
@ -143,7 +143,7 @@ type ModifyGuildData struct {
|
|||
ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"` // nullable
|
||||
|
||||
AFKChannelID discord.Snowflake `json:"afk_channel_id,string,omitempty"`
|
||||
AFKTimeout discord.Seconds `json:"afk_timeout,omitempty"`
|
||||
AFKTimeout option.Seconds `json:"afk_timeout,omitempty"`
|
||||
|
||||
OwnerID discord.Snowflake `json:"owner_id,omitempty"`
|
||||
|
||||
|
|
16
api/role.go
16
api/role.go
|
@ -3,6 +3,7 @@ package api
|
|||
import (
|
||||
"github.com/diamondburned/arikawa/discord"
|
||||
"github.com/diamondburned/arikawa/utils/httputil"
|
||||
"github.com/diamondburned/arikawa/utils/json/option"
|
||||
)
|
||||
|
||||
func (c *Client) AddRole(guildID, userID, roleID discord.Snowflake) error {
|
||||
|
@ -23,7 +24,7 @@ func (c *Client) Roles(guildID discord.Snowflake) ([]discord.Role, error) {
|
|||
EndpointGuilds+guildID.String()+"/roles")
|
||||
}
|
||||
|
||||
type AnyRoleData struct {
|
||||
type CreateRoleData struct {
|
||||
Name string `json:"name,omitempty"` // "new role"
|
||||
Color discord.Color `json:"color,omitempty"` // 0
|
||||
Hoist bool `json:"hoist,omitempty"` // false (show role separately)
|
||||
|
@ -32,7 +33,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 CreateRoleData) (*discord.Role, error) {
|
||||
var role *discord.Role
|
||||
return role, c.RequestJSON(
|
||||
&role, "POST",
|
||||
|
@ -60,9 +61,18 @@ func (c *Client) MoveRole(
|
|||
)
|
||||
}
|
||||
|
||||
type ModifyRoleData struct {
|
||||
Name string `json:"name,omitempty"` // "new role"
|
||||
Color option.Color `json:"color,omitempty"` // 0
|
||||
Hoist option.Bool `json:"hoist,omitempty"` // false (show role separately)
|
||||
|
||||
Mentionable option.Bool `json:"mentionable,omitempty"` // false
|
||||
Permissions discord.Permissions `json:"permissions,omitempty"` // @everyone
|
||||
}
|
||||
|
||||
func (c *Client) ModifyRole(
|
||||
guildID, roleID discord.Snowflake,
|
||||
data AnyRoleData) (*discord.Role, error) {
|
||||
data ModifyRoleData) (*discord.Role, error) {
|
||||
|
||||
var role *discord.Role
|
||||
return role, c.RequestJSON(
|
||||
|
|
|
@ -23,7 +23,7 @@ func (c *Client) Me() (*discord.User, error) {
|
|||
|
||||
type ModifySelfData struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
Avatar Image `json:"image,omitempty"`
|
||||
Avatar *Image `json:"image,omitempty"`
|
||||
}
|
||||
|
||||
func (c *Client) ModifyMe(data ModifySelfData) (*discord.User, error) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package discord
|
||||
|
||||
import (
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/diamondburned/arikawa/utils/json"
|
||||
)
|
||||
|
||||
type AuditLog struct {
|
||||
|
|
|
@ -9,6 +9,4 @@ var (
|
|||
)
|
||||
|
||||
// newBool creates a new Bool with the value of the passed bool.
|
||||
func newBool(b bool) Bool {
|
||||
return &b
|
||||
}
|
||||
func newBool(b bool) Bool { return &b }
|
||||
|
|
|
@ -1,25 +1,23 @@
|
|||
package option
|
||||
|
||||
type (
|
||||
// Uint is the option type for unsigned integers (uint).
|
||||
Uint *uint
|
||||
// Int is the option type for integers (int).
|
||||
Int *int
|
||||
)
|
||||
// ================================ Uint ================================
|
||||
|
||||
var (
|
||||
// ZeroUint is a Uint with 0 as value.
|
||||
ZeroUint = NewUint(0)
|
||||
// ZeroInt is an Int with 0 as value.
|
||||
ZeroInt = NewInt(0)
|
||||
)
|
||||
// Uint is the option type for unsigned integers (uint).
|
||||
type Uint *uint
|
||||
|
||||
// ZeroUint is a Uint with 0 as value.
|
||||
var ZeroUint = NewUint(0)
|
||||
|
||||
// NewUint creates a new Uint using the value of the passed uint.
|
||||
func NewUint(u uint) Uint {
|
||||
return &u
|
||||
}
|
||||
func NewUint(u uint) Uint { return &u }
|
||||
|
||||
// ================================ Int ================================
|
||||
|
||||
// Int is the option type for integers (int).
|
||||
type Int *int
|
||||
|
||||
// ZeroInt is an Int with 0 as value.
|
||||
var ZeroInt = NewInt(0)
|
||||
|
||||
// NewInt creates a new Int using the value of the passed int.
|
||||
func NewInt(i int) Int {
|
||||
return &i
|
||||
}
|
||||
func NewInt(i int) Int { return &i }
|
||||
|
|
|
@ -7,6 +7,4 @@ type String *string
|
|||
var EmptyString = NewString("")
|
||||
|
||||
// NewString creates a new String with the value of the passed string.
|
||||
func NewString(s string) String {
|
||||
return &s
|
||||
}
|
||||
func NewString(s string) String { return &s }
|
||||
|
|
Loading…
Reference in a new issue