Documentation
¶
Overview ¶
Package jsonapi handles the json api for discord
Index ¶
- Variables
- type DiscordJSONClient
- func (d *DiscordJSONClient) BulkOverwriteGlobalCommands(ctx context.Context, aid string, cmds []entity.ApplicationCommand) (resCmds []entity.ApplicationCommand, err error)
- func (d *DiscordJSONClient) BulkOverwriteGuildCommandPermissions(ctx context.Context, aid string, gid snowflake.Snowflake, ...) (resPerms []entity.ApplicationCommandPermissions, err error)
- func (d *DiscordJSONClient) BulkOverwriteGuildCommands(ctx context.Context, aid string, gid snowflake.Snowflake, ...) (resCmds []entity.ApplicationCommand, err error)
- func (d *DiscordJSONClient) CreateReaction(ctx context.Context, cid, mid snowflake.Snowflake, emoji string) (resp *http.Response, err error)
- func (d *DiscordJSONClient) DeferInteractionResponse(ctx context.Context, ixID snowflake.Snowflake, ixToken string) error
- func (d *DiscordJSONClient) GetGateway(ctx context.Context) (entity.Gateway, error)
- func (d *DiscordJSONClient) GetGlobalCommands(ctx context.Context, aid string) (cmds []entity.ApplicationCommand, err error)
- func (d *DiscordJSONClient) GetGuildCommands(ctx context.Context, aid string, gid snowflake.Snowflake) (cmds []entity.ApplicationCommand, err error)
- func (d *DiscordJSONClient) GetGuildMember(ctx context.Context, gid, uid snowflake.Snowflake) (respData entity.GuildMember, err error)
- func (d *DiscordJSONClient) GetInteractionResponse(ctx context.Context, aid snowflake.Snowflake, ixToken string) (respData entity.Message, err error)
- func (d *DiscordJSONClient) GetMessage(ctx context.Context, cid, mid snowflake.Snowflake) (respData entity.Message, err error)
- func (d *DiscordJSONClient) SendInteractionAutocomplete(ctx context.Context, ixID snowflake.Snowflake, ixToken string, m marshaler) error
- func (d *DiscordJSONClient) SendInteractionMessage(ctx context.Context, ixID snowflake.Snowflake, ixToken string, m marshaler) error
- func (d *DiscordJSONClient) SendMessage(ctx context.Context, cid snowflake.Snowflake, m marshaler) (respData entity.Message, err error)
- func (d *DiscordJSONClient) SetDebug(val bool)
- type Embed
- type EmbedField
- type EmbedFooter
- type HTTPClient
- type InteractionAutocompleteResponse
- type InteractionCallbackMessage
- type InteractionCallbackType
- type Logger
- type Message
- type MessageReference
- type MessageWithEmbed
Constants ¶
This section is empty.
Variables ¶
var Err = errors.New("error response")
Err is the error that is wrapped and returned when there is a non-200 api response
Functions ¶
This section is empty.
Types ¶
type DiscordJSONClient ¶
type DiscordJSONClient struct {
// contains filtered or unexported fields
}
DiscordJSONClient is a json client for interacting wth discord
func NewDiscordJSONClient ¶
func NewDiscordJSONClient(deps dependencies, apiURL string) *DiscordJSONClient
NewDiscordJSONClient creates a new DiscordJSONClient
func (*DiscordJSONClient) BulkOverwriteGlobalCommands ¶
func (d *DiscordJSONClient) BulkOverwriteGlobalCommands(ctx context.Context, aid string, cmds []entity.ApplicationCommand) (resCmds []entity.ApplicationCommand, err error)
BulkOverwriteGlobalCommands overwrites the global commands
func (*DiscordJSONClient) BulkOverwriteGuildCommandPermissions ¶
func (d *DiscordJSONClient) BulkOverwriteGuildCommandPermissions(ctx context.Context, aid string, gid snowflake.Snowflake, perms []entity.ApplicationCommandPermissions) (resPerms []entity.ApplicationCommandPermissions, err error)
BulkOverwriteGuildCommandPermissions overwrites the guild command permissions
func (*DiscordJSONClient) BulkOverwriteGuildCommands ¶
func (d *DiscordJSONClient) BulkOverwriteGuildCommands(ctx context.Context, aid string, gid snowflake.Snowflake, cmds []entity.ApplicationCommand) (resCmds []entity.ApplicationCommand, err error)
BulkOverwriteGuildCommands overwrites the guild commands
func (*DiscordJSONClient) CreateReaction ¶
func (d *DiscordJSONClient) CreateReaction(ctx context.Context, cid, mid snowflake.Snowflake, emoji string) (resp *http.Response, err error)
CreateReaction adds a reaction to a message
func (*DiscordJSONClient) DeferInteractionResponse ¶
func (d *DiscordJSONClient) DeferInteractionResponse(ctx context.Context, ixID snowflake.Snowflake, ixToken string) error
DeferInteractionResponse sends a deferral for an interaction response
func (*DiscordJSONClient) GetGateway ¶
GetGateway retrieves information about the gateway
func (*DiscordJSONClient) GetGlobalCommands ¶
func (d *DiscordJSONClient) GetGlobalCommands(ctx context.Context, aid string) (cmds []entity.ApplicationCommand, err error)
GetGlobalCommands gets the registered global commands
func (*DiscordJSONClient) GetGuildCommands ¶
func (d *DiscordJSONClient) GetGuildCommands(ctx context.Context, aid string, gid snowflake.Snowflake) (cmds []entity.ApplicationCommand, err error)
GetGuildCommands gets the currently registered guild commands
func (*DiscordJSONClient) GetGuildMember ¶
func (d *DiscordJSONClient) GetGuildMember(ctx context.Context, gid, uid snowflake.Snowflake) (respData entity.GuildMember, err error)
GetGuildMember retrieves information about a guild memeber
func (*DiscordJSONClient) GetInteractionResponse ¶
func (d *DiscordJSONClient) GetInteractionResponse(ctx context.Context, aid snowflake.Snowflake, ixToken string) (respData entity.Message, err error)
GetInteractionResponse retrieves an interaction response
func (*DiscordJSONClient) GetMessage ¶
func (d *DiscordJSONClient) GetMessage(ctx context.Context, cid, mid snowflake.Snowflake) (respData entity.Message, err error)
GetMessage retrieves information about a discord message
func (*DiscordJSONClient) SendInteractionAutocomplete ¶
func (d *DiscordJSONClient) SendInteractionAutocomplete(ctx context.Context, ixID snowflake.Snowflake, ixToken string, m marshaler) error
SendInteractionAutocomplete sends an interaction autocomplete response
func (*DiscordJSONClient) SendInteractionMessage ¶
func (d *DiscordJSONClient) SendInteractionMessage(ctx context.Context, ixID snowflake.Snowflake, ixToken string, m marshaler) error
SendInteractionMessage sends an interaction response message
func (*DiscordJSONClient) SendMessage ¶
func (d *DiscordJSONClient) SendMessage(ctx context.Context, cid snowflake.Snowflake, m marshaler) (respData entity.Message, err error)
SendMessage sends a message to a channel
func (*DiscordJSONClient) SetDebug ¶
func (d *DiscordJSONClient) SetDebug(val bool)
SetDebug turns on or off debugging for the client
type Embed ¶
type Embed struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` URL string `json:"url,omitempty"` Timestamp string `json:"timestamp,omitempty"` Color int `json:"color,omitempty"` Fields []EmbedField `json:"fields,omitempty"` }
Embed is a json object that represents an embed in a MessageWithEmbed
type EmbedField ¶
type EmbedField struct { Name string `json:"name"` Value string `json:"value"` Inline bool `json:"inline"` }
EmbedField is a json object that represents a field in an Embed
type EmbedFooter ¶
type EmbedFooter struct {
}EmbedFooter is a json object that represents the footer of an embed
type HTTPClient ¶
type HTTPClient interface { SetHeaders(http.Header) Get(context.Context, string, *http.Header) (*http.Response, error) GetBody(context.Context, string, *http.Header) (*http.Response, []byte, error) GetJSON(context.Context, string, *http.Header, interface{}) (*http.Response, error) Post(context.Context, string, *http.Header, io.Reader) (*http.Response, error) PostBody(context.Context, string, *http.Header, io.Reader) (*http.Response, []byte, error) PostJSON(context.Context, string, *http.Header, io.Reader, interface{}) (*http.Response, error) Put(context.Context, string, *http.Header, io.Reader) (*http.Response, error) PutBody(context.Context, string, *http.Header, io.Reader) (*http.Response, []byte, error) PutJSON(context.Context, string, *http.Header, io.Reader, interface{}) (*http.Response, error) }
HTTPClient is the interface of an http client
type InteractionAutocompleteResponse ¶
type InteractionAutocompleteResponse struct {
Choices []entity.ApplicationCommandOptionChoice `json:"choices"`
}
InteractionAutocompleteResponse represents an interaction autocomplete response
func (InteractionAutocompleteResponse) MarshalToJSON ¶
func (m InteractionAutocompleteResponse) MarshalToJSON() ([]byte, error)
MarshalToJSON marshals a InteractionAutocompleteResponse into json
type InteractionCallbackMessage ¶
type InteractionCallbackMessage struct { Type InteractionCallbackType `json:"type"` Data json.RawMessage `json:"data,omitempty"` }
InteractionCallbackMessage is the message from an interaction callback
type InteractionCallbackType ¶
type InteractionCallbackType int
InteractionCallbackType is the type of an interaction callback
const ( CallbackTypePong InteractionCallbackType = 1 CallbackTypeChannelMessage InteractionCallbackType = 4 CallbackTypeDeferredChannelMessage InteractionCallbackType = 5 CallbackTypeDeferredUpdate InteractionCallbackType = 6 CallbackTypeUpdate InteractionCallbackType = 7 CallbackTypeAutocomplete InteractionCallbackType = 8 )
These are the InteractionCallbackType values
type Logger ¶
type Logger = interface { Log(keyvals ...interface{}) error Message(string, ...interface{}) Err(string, error, ...interface{}) Printf(string, ...interface{}) }
Logger is the interface expected for logging
type Message ¶
type Message struct { Content string `json:"content"` Tts bool `json:"tts"` ReplyTo *MessageReference `json:"message_reference,omitempty"` Flags int `json:"flags,omitempty"` }
Message is the json object that is sent to the discord api to post a plain-text message to a server
func (Message) MarshalToJSON ¶
MarshalToJSON marshals a Message into json
type MessageReference ¶
type MessageReference struct { MessageID string `json:"message_id,omitempty"` ChannelID string `json:"channel_id,omitempty"` GuildID string `json:"guild_id,omitempty"` }
MessageReference contains the information to uniquely point at a discord message
type MessageWithEmbed ¶
type MessageWithEmbed struct { Content string `json:"content"` Tts bool `json:"tts"` Embeds []Embed `json:"embeds"` ReplyTo *MessageReference `json:"message_reference,omitempty"` Flags int `json:"flags,omitempty"` }
MessageWithEmbed is the json object that is sent to the discord api to post an embed message to a server
func (MessageWithEmbed) MarshalToJSON ¶
func (m MessageWithEmbed) MarshalToJSON() ([]byte, error)
MarshalToJSON marshals a MessageWithEmbed into json