jsonapi

package
v24.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package jsonapi handles the json api for discord

Index

Constants

This section is empty.

Variables

View Source
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

func (d *DiscordJSONClient) GetGateway(ctx context.Context) (entity.Gateway, error)

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"`
	Footer      EmbedFooter  `json:"footer,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 {
	Text string `json:"text"`
}

EmbedFooter is a json object that represents the footer of an embed

type HTTPClient

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

func (m Message) MarshalToJSON() ([]byte, error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL