shards

package
v0.0.0-...-1920723 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	sync.RWMutex

	// Discord gateway.
	Gateway *discordgo.Session
	// Discord intent.
	Intent discordgo.Intent
	// Shards managed by this Manager.
	Shards []*Shard
	// Total Shard count.
	ShardCount int
	// contains filtered or unexported fields
}

Manager facilitates the management of Shards.

func New

func New(token string) (mgr *Manager, err error)

New creates a new shard manager and automatically scales the shards

func (*Manager) AddHandler

func (m *Manager) AddHandler(handler interface{})

AddHandler registers an event handler for all Shards.

func (*Manager) GuildCount

func (m *Manager) GuildCount() (count int)

GuildCount returns the amount of guilds that a Manager is handling

func (*Manager) RegisterIntent

func (m *Manager) RegisterIntent(intent discordgo.Intent)

RegisterIntent sets the Intent for all Shards' sessions.

func (*Manager) Restart

func (m *Manager) Restart() (err error)

Restart restarts the Manager, and rescales if necessary, all with zero downtime.

func (*Manager) SessionForDM

func (m *Manager) SessionForDM() *discordgo.Session

SessionForDM returns the proper session for sending and receiving DM's (must be Shard 0)

func (*Manager) SessionForGuild

func (m *Manager) SessionForGuild(guildID int64) *discordgo.Session

SessionForGuild returns the proper session for the specified guild.

func (*Manager) SetShardCount

func (m *Manager) SetShardCount(count int)

SetShardCount sets the number of shards

func (*Manager) Shutdown

func (m *Manager) Shutdown() (err error)

Shutdown gracefully terminates the Manager.

func (*Manager) Start

func (m *Manager) Start() (err error)

Start starts the Manager.

type Shard

type Shard struct {
	sync.RWMutex

	// The Discord session handling this Shard.
	Session *discordgo.Session
	// This Shard's ID.
	ID int
	// Total Shard count.
	ShardCount int
	// contains filtered or unexported fields
}

A Shard represents a shard.

func (*Shard) AddHandler

func (s *Shard) AddHandler(handler interface{})

AddHandler registers an event handler for a Shard.

Shouldn't be called after Init or results in undefined behavior.

func (*Shard) ApplicationCommandCreate

func (s *Shard) ApplicationCommandCreate(guildID string, cmd *discordgo.ApplicationCommand) error

ApplicationCommandCreate registers an application command for a Shard.

Shouldn't be called before Initialization.

func (*Shard) GuildCount

func (s *Shard) GuildCount() (count int)

GuildCount returns the amount of guilds that a Shard is handling.

func (*Shard) Init

func (s *Shard) Init(token string, ID, ShardCount int, intent discordgo.Intent) (err error)

Init initializes a shard with a bot token, its Shard ID, the total amount of shards, and a Discord intent.

func (*Shard) Stop

func (s *Shard) Stop() (err error)

Stop stops a shard.

Jump to

Keyboard shortcuts

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