discordha

package
v0.0.0-...-82e9c16 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2020 License: AGPL-3.0 Imports: 12 Imported by: 0

README

DiscordHA

DiscordHA (Discord High Available) is library on to be used together with discord-go to deploy Discord bots in high availability. It relies on Etcd as a locking system to prevent events of being received twice, this works in a first locked principle for now.

Discord HA is not meant for sharding but enables Discord bots to have multiple replicas.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorCacheKeyNotExist = errors.New("Cache key does not exist")

ErrorCacheKeyNotExist is the error the cache returns if a key does not exist

Functions

This section is empty.

Types

type Config

type Config struct {
	Session            *discordgo.Session
	HA                 bool
	LockUpdateInterval time.Duration
	LockTTL            time.Duration
	EtcdEndpoints      []string
	Context            context.Context
}

Config contains the configuration for HA

type HA

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

HA is a helper struct for high available discordgo using etcd

func New

func New(c Config) (*HA, error)

New gives a HA instance for a given configuration

func (*HA) CacheRead

func (h *HA) CacheRead(cache, key string, want interface{}) (interface{}, error)

CacheRead reads a key from a specific cache, returns ErrorCacheKeyNotExist if not found

func (*HA) CacheWrite

func (h *HA) CacheWrite(cache, key string, data interface{}, ttl time.Duration) error

CacheWrite writes an object to a specific cache with a specific key, will be purged after TTL expires

func (*HA) Lock

func (h *HA) Lock(obj interface{}) (bool, error)

Lock tries to acquire a lock on an event, it will return true if the instance that requests it may process the request.

func (*HA) LockVoice

func (h *HA) LockVoice(channelID string) (bool, error)

LockVoice locks a voice channel ID, returns true if successful

func (*HA) SendVoiceCommand

func (h *HA) SendVoiceCommand(channelID string, command VoiceCommand) error

SendVoiceCommand sends a string command to the instance handling the voice channel These can be received using WatchVoiceCommands

func (*HA) Unlock

func (h *HA) Unlock(obj interface{}) error

Unlock will release a lock on an event

func (*HA) UnlockVoice

func (h *HA) UnlockVoice(channelID string) error

UnlockVoice unlocks a voice channel ID

func (*HA) WatchVoiceCommands

func (h *HA) WatchVoiceCommands(ctx context.Context, channelID string) chan VoiceCommand

WatchVoiceCommands gives a channel with commands transmitted by SendVoiceCommand

type VoiceCommand

type VoiceCommand struct {
	ChannelID string `json:"channelID"`
	File      string `json:"file"`
	UserID    string `json:"userID"`
}

Jump to

Keyboard shortcuts

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