discord

package
v1.6.0-pre1.0...-9505211 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

SelectMenu types.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionsRow

type ActionsRow struct {
	Components []MessageComponent `json:"components"`
}

ActionsRow is a container for components within one row.

func (ActionsRow) MarshalJSON

func (r ActionsRow) MarshalJSON() ([]byte, error)

MarshalJSON is a method for marshaling ActionsRow to a JSON object.

func (ActionsRow) Type

func (r ActionsRow) Type() ComponentType

Type is a method to get the type of a component.

func (*ActionsRow) UnmarshalJSON

func (r *ActionsRow) UnmarshalJSON(data []byte) error

UnmarshalJSON is a helper function to unmarshal Actions Row.

type Bucket

type Bucket struct {
	sync.Mutex
	Key       string
	Remaining int

	Userdata interface{}
	// contains filtered or unexported fields
}

Bucket represents a ratelimit bucket, each bucket gets ratelimited individually (-global ratelimits)

func (*Bucket) Release

func (b *Bucket) Release(headers *fasthttp.ResponseHeader) error

Release unlocks the bucket and reads the headers to update the buckets ratelimit info and locks up the whole thing in case if there's a global ratelimit.

type Button

type Button struct {
	Label    string         `json:"label"`
	Style    ButtonStyle    `json:"style"`
	Disabled bool           `json:"disabled"`
	Emoji    ComponentEmoji `json:"emoji"`

	// NOTE: Only button with LinkButton style can have link. Also, URL is mutually exclusive with CustomID.
	URL      string `json:"url,omitempty"`
	CustomID string `json:"custom_id,omitempty"`
}

Button represents button component.

func (Button) MarshalJSON

func (b Button) MarshalJSON() ([]byte, error)

MarshalJSON is a method for marshaling Button to a JSON object.

func (Button) Type

func (Button) Type() ComponentType

Type is a method to get the type of a component.

type ButtonStyle

type ButtonStyle uint

ButtonStyle is style of button.

const (
	// PrimaryButton is a button with blurple color.
	PrimaryButton ButtonStyle = 1
	// SecondaryButton is a button with grey color.
	SecondaryButton ButtonStyle = 2
	// SuccessButton is a button with green color.
	SuccessButton ButtonStyle = 3
	// DangerButton is a button with red color.
	DangerButton ButtonStyle = 4
	// LinkButton is a special type of button which navigates to a URL. Has grey color.
	LinkButton ButtonStyle = 5
)

Button styles.

type Channel

type Channel struct {
	ID      string `json:"id"`
	GuildID string `json:"guild_id"`
}

type Client

type Client struct {
	Ctx          context.Context
	Token        string
	Handlers     Handlers
	Gateway      gateway.Gateway
	ChannelID    string
	GuildID      string
	CommandsData *[]CommandData
	RateLimiter  *RateLimiter
}

func NewClient

func NewClient(ctx context.Context, token string) *Client

func (*Client) AddHandler

func (client *Client) AddHandler(event gateway.EventType, function any) error

func (*Client) ChooseSelectMenu

func (client *Client) ChooseSelectMenu(message gateway.EventMessage, row int, column int, values []string) error

func (*Client) ClickButton

func (client *Client) ClickButton(message gateway.EventMessage, row int, column int) error

func (*Client) ClickDmButton

func (client *Client) ClickDmButton(message gateway.EventMessage, row int, column int) error

func (*Client) Close

func (client *Client) Close()

func (*Client) Connect

func (client *Client) Connect() error

func (*Client) GetCommandInfo

func (client *Client) GetCommandInfo(commandName string) *CommandData

func (*Client) GetCommands

func (client *Client) GetCommands(guildID string) (map[string]CommandData, error)

func (*Client) GetGuildID

func (client *Client) GetGuildID(channelID string) string

func (*Client) Log

func (client *Client) Log(logType LogType, msg string)

func (*Client) RequestWithLockedBucket

func (client *Client) RequestWithLockedBucket(method, urlStr string, b []byte, bucket *Bucket, sequence int) error

func (*Client) SendCommand

func (client *Client) SendCommand(commandName string, options map[string]string) error

func (*Client) SendMessage

func (client *Client) SendMessage(op gateway.Opcode, data gateway.MessageData) error

func (*Client) SendSubCommand

func (client *Client) SendSubCommand(commandName string, subCommandName string, options map[string]string) error

func (*Client) SubmitModal

func (client *Client) SubmitModal(modal gateway.EventModalCreate) error

type CommandData

type CommandData struct {
	ID                   string         `json:"id"`
	Type                 int            `json:"type"`
	ApplicationID        string         `json:"application_id"`
	Version              string         `json:"version"`
	Name                 string         `json:"name"`
	Description          string         `json:"description"`
	DmPermission         bool           `json:"dm_permission"`
	IntegrationTypes     []int          `json:"integration_types"`
	GlobalPopularityRank int            `json:"global_popularity_rank"`
	Options              CommandOptions `json:"options,omitempty"`
}

type CommandOptions

type CommandOptions []struct {
	Type        int    `json:"type"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Required    bool   `json:"required,omitempty"`
}

type CommandSendOptions

type CommandSendOptions struct {
	Type  int    `json:"type"`
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ComponentEmoji

type ComponentEmoji struct {
	Name     string `json:"name,omitempty"`
	ID       string `json:"id,omitempty"`
	Animated bool   `json:"animated,omitempty"`
}

ComponentEmoji represents button emoji, if it does have one.

type ComponentType

type ComponentType uint

ComponentType is type of component.

const (
	ActionsRowComponent            ComponentType = 1
	ButtonComponent                ComponentType = 2
	SelectMenuComponent            ComponentType = 3
	TextInputComponent             ComponentType = 4
	UserSelectMenuComponent        ComponentType = 5
	RoleSelectMenuComponent        ComponentType = 6
	MentionableSelectMenuComponent ComponentType = 7
	ChannelSelectMenuComponent     ComponentType = 8
)

MessageComponent types.

type Handlers

type Handlers struct {
	OnReady         []func(data gateway.EventReady)
	OnMessageCreate []func(data gateway.EventMessage)
	OnMessageUpdate []func(data gateway.EventMessage)
	OnModalCreate   []func(data gateway.EventModalCreate)
	// contains filtered or unexported fields
}

func (*Handlers) Add

func (handlers *Handlers) Add(event gateway.EventType, function any) error

type LogType

type LogType string
const (
	Info  LogType = "INF"
	Error LogType = "ERR"
)

type MessageComponent

type MessageComponent interface {
	json.Marshaler
	Type() ComponentType
}

MessageComponent is a base interface for all message components.

func MessageComponentFromJSON

func MessageComponentFromJSON(b []byte) (MessageComponent, error)

MessageComponentFromJSON is a helper function for unmarshaling message components

type RateLimiter

type RateLimiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RateLimiter holds all ratelimit buckets

func NewRatelimiter

func NewRatelimiter() *RateLimiter

NewRatelimiter returns a new RateLimiter

func (*RateLimiter) GetBucket

func (r *RateLimiter) GetBucket(key string) *Bucket

GetBucket retrieves or creates a bucket

func (*RateLimiter) GetWaitTime

func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration

GetWaitTime returns the duration you should wait for a Bucket

func (*RateLimiter) LockBucket

func (r *RateLimiter) LockBucket(bucketID string) *Bucket

LockBucket Locks until a request can be made

func (*RateLimiter) LockBucketObject

func (r *RateLimiter) LockBucketObject(b *Bucket) *Bucket

LockBucketObject Locks an already resolved bucket until a request can be made

type SelectMenu

type SelectMenu struct {
	// Type of the select menu.
	MenuType SelectMenuType `json:"type,omitempty"`
	// CustomID is a developer-defined identifier for the select menu.
	CustomID string `json:"custom_id,omitempty"`
	// The text which will be shown in the menu if there's no default options or all options was deselected and component was closed.
	Placeholder string `json:"placeholder"`
	// This value determines the minimal amount of selected items in the menu.
	MinValues *int `json:"min_values,omitempty"`
	// This value determines the maximal amount of selected items in the menu.
	// If MaxValues or MinValues are greater than one then the user can select multiple items in the component.
	MaxValues int `json:"max_values,omitempty"`
	// List of default values for auto-populated select menus.
	// NOTE: Number of entries should be in the range defined by MinValues and MaxValues.
	DefaultValues []SelectMenuDefaultValue `json:"default_values,omitempty"`

	Options  []SelectMenuOption `json:"options,omitempty"`
	Disabled bool               `json:"disabled"`
}

SelectMenu represents select menu component.

func (SelectMenu) MarshalJSON

func (s SelectMenu) MarshalJSON() ([]byte, error)

MarshalJSON is a method for marshaling SelectMenu to a JSON object.

func (SelectMenu) Type

func (s SelectMenu) Type() ComponentType

Type is a method to get the type of a component.

type SelectMenuDefaultValue

type SelectMenuDefaultValue struct {
	// ID of the entity.
	ID string `json:"id"`
	// Type of the entity.
	Type SelectMenuDefaultValueType `json:"type"`
}

SelectMenuDefaultValue represents an entity selected by default in auto-populated select menus.

type SelectMenuDefaultValueType

type SelectMenuDefaultValueType string

SelectMenuDefaultValueType represents the type of an entity selected by default in auto-populated select menus.

const (
	SelectMenuDefaultValueUser    SelectMenuDefaultValueType = "user"
	SelectMenuDefaultValueRole    SelectMenuDefaultValueType = "role"
	SelectMenuDefaultValueChannel SelectMenuDefaultValueType = "channel"
)

SelectMenuDefaultValue types.

type SelectMenuOption

type SelectMenuOption struct {
	Label       string         `json:"label,omitempty"`
	Value       string         `json:"value"`
	Description string         `json:"description"`
	Emoji       ComponentEmoji `json:"emoji"`
	// Determines whenever option is selected by default or not.
	Default bool `json:"default"`
}

SelectMenuOption represents an option for a select menu.

type SelectMenuType

type SelectMenuType ComponentType

SelectMenuType represents select menu type.

type TextInput

type TextInput struct {
	CustomID    string         `json:"custom_id"`
	Label       string         `json:"label"`
	Style       TextInputStyle `json:"style"`
	Placeholder string         `json:"placeholder,omitempty"`
	Value       string         `json:"value,omitempty"`
	Required    bool           `json:"required"`
	MinLength   int            `json:"min_length,omitempty"`
	MaxLength   int            `json:"max_length,omitempty"`
}

TextInput represents text input component.

func (TextInput) MarshalJSON

func (m TextInput) MarshalJSON() ([]byte, error)

MarshalJSON is a method for marshaling TextInput to a JSON object.

func (TextInput) Type

func (TextInput) Type() ComponentType

Type is a method to get the type of a component.

type TextInputStyle

type TextInputStyle uint

TextInputStyle is style of text in TextInput component.

const (
	TextInputShort     TextInputStyle = 1
	TextInputParagraph TextInputStyle = 2
)

Text styles

type TooManyRequests

type TooManyRequests struct {
	Bucket     string  `json:"bucket"`
	Message    string  `json:"message"`
	RetryAfter float64 `json:"retry_after"`
}

A TooManyRequests struct holds information received from Discord when receiving a HTTP 429 response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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