discord

package
v0.0.0-...-16b2e41 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownError         websocket.StatusCode = 4000
	UnknownOpcode        websocket.StatusCode = 4001
	DecodeError          websocket.StatusCode = 4002
	NotAuthenticated     websocket.StatusCode = 4003
	AuthenticationFailed websocket.StatusCode = 4004
	AlreadyAuthenticated websocket.StatusCode = 4005
	InvalidSeq           websocket.StatusCode = 4007
	RateLimited          websocket.StatusCode = 4008
	SessionTimedOut      websocket.StatusCode = 4009
	InvalidShard         websocket.StatusCode = 4010
	ShardingRequired     websocket.StatusCode = 4011
	InvalidAPIVersion    websocket.StatusCode = 4012
	InvalidIntent        websocket.StatusCode = 4013
	DisallowedIntent     websocket.StatusCode = 4014
)

Variables

This section is empty.

Functions

func URLFor

func URLFor(endpoint string, args ...any) string

Types

type Client

type Client struct {
	Err error // set on fatal errors
	// contains filtered or unexported fields
}

func NewClient

func NewClient(logger *slog.Logger, token string) *Client

func (*Client) CheckAPIResponse

func (c *Client) CheckAPIResponse(resp *http.Response)

This is obviously stupid.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

func (*Client) DecodeFormatting

func (c *Client) DecodeFormatting(msg Message) string

func (*Client) Errors

func (c *Client) Errors() <-chan error

func (*Client) Fatal

func (c *Client) Fatal() <-chan struct{}

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, data any) (*http.Response, error)

func (*Client) Run

func (c *Client) Run(ctx context.Context, dataCh chan<- Message, errCh chan<- error)

type EventType

type EventType string
const (
	TypeMessageCreate EventType = "MESSAGE_CREATE"
	TypeReady         EventType = "READY"
	TypeResumed       EventType = "RESUMED"
)

type GatewayEvent

type GatewayEvent struct {
	Op   OpType
	Data any       `json:"d"`
	Seq  *int      `json:"s"`
	Type EventType `json:"t,omitempty"`
}

type GatewayResume

type GatewayResume struct {
	Token     string `json:"token"`
	SessionID string `json:"session_id"`
	Seq       *int   `json:"seq"`
}

payload for sending resume ops

type HelloData

type HelloData struct {
	HeartbeatInterval int `mapstructure:"heartbeat_interval"`
}

type Intent

type Intent int
const (
	Guilds Intent = 1 << iota
	GuildMembers
	GuildModeration
	GuildEmojiAndStickers
	GuildIntegrations
	GuildWebhooks
	GuildInvites
	GuildVoiceStates
	GuildPresences
	GuildMessages
	GuildMessageReactions
	GuildMessageTyping
	DirectMessages
	DirectMessageReactions
	DirectMessageTyping
	MessageContent
	GuildScheduledEvents
	AutoModerationConfiguration = 1 << 20
	AutoModerationExecution     = 1 << 21
)

taken from https://discord.com/developers/docs/topics/gateway#list-of-intents

type Message

type Message struct {
	ID        string
	Author    User
	Content   string
	ChannelID string `mapstructure:"channel_id"`
	Mentions  []User
}

incomplete, obviously

type OpType

type OpType int
const (
	// An event was dispatched
	Dispatch OpType = iota
	// Fired periodically by the client to keep the connection alive.
	Heartbeat
	// Starts a new session during the initial handshake.
	Identify
	// Update the client's presence.
	PresenceUpdate
	// Used to join/leave or move between voice channels.
	VoiceStateUpdate

	// Resume a previous session that was disconnected.
	Resume
	// You should attempt to reconnect and resume immediately.
	Reconnect
	// Request information about offline guild members in a large guild.
	RequestGuildMembers
	// The session has been invalidated. You should reconnect and identify/resume accordingly.
	InvalidSession
	// Sent immediately after connecting, contains the heartbeat_interval to use.
	Hello
	// Sent in response to receiving a heartbeat to acknowledge that it has been received.
	HeartbeatACK
)

type Ready

type Ready struct {
	APIVersion       int `mapstructure:"v"`
	User             User
	SessionID        string `mapstructure:"session_id"`
	ResumeGatewayURL string `mapstructure:"resume_gateway_url"`
}

type User

type User struct {
	ID            string
	Username      string
	Discriminator string
	IsBot         bool `mapstructure:"bot"`
}

Jump to

Keyboard shortcuts

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