providers

package
v0.0.0-...-c3bab1b Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NotFoundError = errors.New("not found")
View Source
var ProviderNotReadyError = errors.New("provider is not ready")

Functions

This section is empty.

Types

type CacheProvider

type CacheProvider interface {
	// Get a key from Key/Value storage.
	Get(namespace string, key string) (interface{}, error)
	// Createsa new Key/Value pair in storage.
	Set(namespace string, key string, value interface{}) error
	// Delete a pair in Key/Value storage
	Delete(namespace string, key string) error
	// Clear entire namespace
	Clear(namespace string) error
	// Get all key/value pairs
	GetAll(namespace string) (map[string]interface{}, error)
	// Total amount of k/v pairs
	Total(namespace string) (int, error)
}

CacheProvider represents a cache storage.

type GatewayProvider

type GatewayProvider interface {
	// Set the token to use
	UseToken(token string)
	// Open connection to Discord with given shard ID and total shards
	Connect(shard int, total int) error
	// Close the connection
	Close() error
	// Add an OnOpen handler
	OnOpen(func())
	// Add an OnClose handler
	OnClose(func())
	// Add an OnPacket handler
	OnPacket(func(message interface{}))
	// Send a packet
	Send(json interface{}) error
	// Shard ID and total shards ran by this provider
	ShardInfo() [2]int
	// Sets presence
	UsePresence(presence gateway.UpdatePresence) error
	// Use intents
	UseIntents(intents utils.Flags) error
}

GatewayProvider represents a bi-directional connection between Discord and GooCord. A single GatewayProvider can only handle one shard.

type HTTPRestProvider

type HTTPRestProvider struct {
	// Authentication header used by this HTTPRestProvider
	Auth string
	// Base API url
	URL string
	// Client used for requests
	Client *http.Client
}

HTTPRestProvider is a basic RestProvider used by default. Uses HTTP to communicate with Discord's API

func NewHTTPRestProvider

func NewHTTPRestProvider(auth string) *HTTPRestProvider

NewHTTPRestProvider creates a new HTTPRestProvider

func (*HTTPRestProvider) Request

func (h *HTTPRestProvider) Request(method string, endpoint string, headers map[string]string, body interface{}) (resp *RestResponse, err error)

Request sends requests to Discord

func (*HTTPRestProvider) UseAPI

func (h *HTTPRestProvider) UseAPI(url string)

UseAPI changes API url

func (*HTTPRestProvider) UseAuth

func (h *HTTPRestProvider) UseAuth(auth string)

UseAuth sets a new Authorization header

type MapCacheNamespace

type MapCacheNamespace struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

MapCacheNamespace is a unit of cache used to separate different keys.

func NewMapCacheNamespace

func NewMapCacheNamespace() *MapCacheNamespace

NewMapCacheNamespace creates a new MapCacheNamespace

type MapCacheProvider

type MapCacheProvider struct {
	// contains filtered or unexported fields
}

MapCacheProvider is a basic CacheProvider used by default. Uses map as its main storage.

func NewMapCacheProvider

func NewMapCacheProvider() *MapCacheProvider

NewMapCacheProvider creates a new MapCacheProvider

func (*MapCacheProvider) Clear

func (c *MapCacheProvider) Clear(namespace string) (err error)

Clear clears MapCacheNamespace

func (*MapCacheProvider) Delete

func (c *MapCacheProvider) Delete(namespace string, key string) (err error)

Delete deletes a key pair from MapCacheNamespace

func (*MapCacheProvider) Get

func (c *MapCacheProvider) Get(namespace string, key string) (rv interface{}, err error)

Get gets a key from specific MapCacheNamespace

func (*MapCacheProvider) GetAll

func (c *MapCacheProvider) GetAll(namespace string) (data map[string]interface{}, err error)

GetAll gets all pairs from MapCacheNamespace

func (*MapCacheProvider) Set

func (c *MapCacheProvider) Set(namespace string, key string, value interface{}) (err error)

Set sets a key in given MapCacheNamespace

func (*MapCacheProvider) Total

func (c *MapCacheProvider) Total(namespace string) (res int, err error)

Total returns total amount of pairs stored in MapCacheNamespace

type Providers

type Providers struct {
	Cache *CacheProvider
}

Providers represent a set of providers used by Client

type RestProvider

type RestProvider interface {
	// Set an authorization header
	UseAuth(token string)
	// Set API url
	UseAPI(url string)
	// Send a request to Discord API
	Request(method string, endpoint string, headers map[string]string, body interface{}) (*RestResponse, error)
}

RestProvider represents a requester which sends requests to Discord. Internally, GooCord doesn't implement ratelimiting, RestProviders are responsible for that

type RestResponse

type RestResponse struct {
	// HTTP status code
	StatusCode int
	// HTTP Headers
	Headers map[string]string
	// Body
	Body interface{}
}

RestResponse represents a response from Discord API

type WebSocketGatewayProvider

type WebSocketGatewayProvider struct {
	utils.EventEmitter

	Conn      *websocket.Conn         // active connection
	Token     string                  // token used
	Shard     int                     // shard id
	Shards    int                     // total shards passed in IDENTIFY
	Ready     bool                    // whether the provider is ready
	Presence  *gateway.UpdatePresence // Current client's presence
	Intents   utils.Flags             // Intents used
	Sequence  *int                    // Sequence
	SessionID *int                    // Session's id used for resume
	Zlib      bool                    // Use zlib compression or not
	// contains filtered or unexported fields
}

WebSocketGatewayProvider is a basic GatewayProvider used by default. Uses WS to communicate with Discord's gateway

func NewWebSocketGatewayProvider

func NewWebSocketGatewayProvider(token string, intents utils.Flags) *WebSocketGatewayProvider

func (*WebSocketGatewayProvider) Beat

func (w *WebSocketGatewayProvider) Beat() error

Send heartbeat to gateway

func (*WebSocketGatewayProvider) Close

func (w *WebSocketGatewayProvider) Close() error

Close aborts the connection

func (*WebSocketGatewayProvider) Connect

func (w *WebSocketGatewayProvider) Connect(shard int, total int) (err error)

Connect instantiates connection to Discord

func (*WebSocketGatewayProvider) Decode

func (w *WebSocketGatewayProvider) Decode(data []byte, messageType int) (res interface{}, err error)

Decode some message

func (*WebSocketGatewayProvider) GetHeartbeat

Get heartbeat payload

func (*WebSocketGatewayProvider) GetIdentify

func (w *WebSocketGatewayProvider) GetIdentify() gateway.Identify

Get identify payload

func (*WebSocketGatewayProvider) Identify

func (w *WebSocketGatewayProvider) Identify() error

Send identify payload

func (*WebSocketGatewayProvider) OnClose

func (w *WebSocketGatewayProvider) OnClose(f func())

func (*WebSocketGatewayProvider) OnOpen

func (w *WebSocketGatewayProvider) OnOpen(f func())

func (*WebSocketGatewayProvider) OnPacket

func (w *WebSocketGatewayProvider) OnPacket(f func(interface{}))

func (*WebSocketGatewayProvider) Send

func (w *WebSocketGatewayProvider) Send(json interface{}) error

Send sends data to websocket

func (*WebSocketGatewayProvider) ShardInfo

func (w *WebSocketGatewayProvider) ShardInfo() [2]int

ShardInfo returns information about shards running

func (*WebSocketGatewayProvider) UseIntents

func (w *WebSocketGatewayProvider) UseIntents(intents utils.Flags) error

Set intents

func (*WebSocketGatewayProvider) UsePresence

func (w *WebSocketGatewayProvider) UsePresence(presence gateway.UpdatePresence) (err error)

Set presence

func (*WebSocketGatewayProvider) UseToken

func (w *WebSocketGatewayProvider) UseToken(token string)

UseToken sets a token to use

func (*WebSocketGatewayProvider) UseZlib

func (w *WebSocketGatewayProvider) UseZlib()

Jump to

Keyboard shortcuts

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