v0.0.0-...-07de05f Latest Latest

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

Go to latest
Published: Jul 20, 2022 License: AGPL-3.0 Imports: 8 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Event

type Event struct {
	Type EventType

	Shard     int
	NumShards int

	Msg string

	// When this event occured
	Time time.Time

Event holds data for an event

func (*Event) String

func (c *Event) String() string

type EventType

type EventType int
const (
	// Sent when the connection to the gateway was established
	EventConnected EventType = iota

	// Sent when the connection is lose

	// Sent when the connection was sucessfully resumed

	// Sent on ready

	// Sent when Open() is called

	// Sent when Close() is called

	// Sent when an error occurs

func (EventType) String

func (c EventType) String() string

type Manager

type Manager struct {

	// Name of the bot, to appear before log messages as a prefix
	// and in the title of the updated status message
	Name string

	// All the shard sessions
	Sessions []*discordgo.Session

	// If set logs connection status events to this channel
	LogChannel string

	// If set keeps an updated satus message in this channel
	StatusMessageChannel string

	// The function that provides the guild counts per shard, used fro the updated status message
	// Should return a slice of guild counts, with the index being the shard number
	GuildCountsFunc func() []int

	// Called on events, by default this is set to a function that logs it to log.Printf
	// You can override this if you want another behaviour, or just set it to nil for nothing.
	OnEvent func(e *Event)

	// SessionFunc creates a new session and returns it, override the default one if you have your own
	// session settings to apply
	SessionFunc SessionFunc
	// contains filtered or unexported fields

func New

func New(token string) *Manager

New creates a new shard manager with the defaults set, after you have created this you call Manager.Start To start connecting dshardmanager.New("Bot asd", OptLogChannel(someChannel), OptLogEventsToDiscord(true, true))

func (*Manager) AddHandler

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

Adds an event handler to all shards All event handlers will be added to new sessions automatically.

func (*Manager) GetFullStatus

func (m *Manager) GetFullStatus() *Status

GetFullStatus retrieves the full status at this instant

func (*Manager) GetNumShards

func (m *Manager) GetNumShards() int

GetNumShards returns the current set number of shards

func (*Manager) GetRecommendedCount

func (m *Manager) GetRecommendedCount() (int, error)

GetRecommendedCount gets the recommended sharding count from discord, this will also set the shard count internally if called Should not be called after calling Start(), will have undefined behaviour

func (*Manager) Init

func (m *Manager) Init() error

Init initializesthe manager, retreiving the recommended shard count if needed and initalizes all the shards

func (*Manager) LogConnectionEventStd

func (m *Manager) LogConnectionEventStd(e *Event)

LogConnectionEventStd is the standard connection event logger, it logs it to whatever log.output is set to.

func (*Manager) OnDiscordConnected

func (m *Manager) OnDiscordConnected(s *discordgo.Session, evt *discordgo.Connect)

func (*Manager) OnDiscordDisconnected

func (m *Manager) OnDiscordDisconnected(s *discordgo.Session, evt *discordgo.Disconnect)

func (*Manager) OnDiscordReady

func (m *Manager) OnDiscordReady(s *discordgo.Session, evt *discordgo.Ready)

func (*Manager) OnDiscordResumed

func (m *Manager) OnDiscordResumed(s *discordgo.Session, evt *discordgo.Resumed)

func (*Manager) Session

func (m *Manager) Session(shardID int) *discordgo.Session

Session retrieves a session from the sessions map, rlocking it in the process

func (*Manager) SessionForGuild

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

SessionForGuild returns the session for the specified guild

func (*Manager) SessionForGuildS

func (m *Manager) SessionForGuildS(guildID string) *discordgo.Session

SessionForGuildS is the same as SessionForGuild but accepts the guildID as a string for convenience

func (*Manager) SetNumShards

func (m *Manager) SetNumShards(n int)

SetNumShards sets the number of shards to use, if you want to override the recommended count Should not be called after calling Start(), will panic

func (*Manager) ShardForGuild

func (m *Manager) ShardForGuild(guildID string) int64

func (*Manager) Start

func (m *Manager) Start() error

Start starts the shard manager, opening all gateway connections

func (*Manager) StdGuildCountsFunc

func (m *Manager) StdGuildCountsFunc() []int

StdGuildsFunc uses the standard states to return the guilds

func (*Manager) StdSessionFunc

func (m *Manager) StdSessionFunc(token string) (*discordgo.Session, error)

StdSessionFunc is the standard session provider, it does nothing to the actual session

func (*Manager) StopAll

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

StopAll stops all the shard sessions and returns the last error that occured

type SessionFunc

type SessionFunc func(token string) (*discordgo.Session, error)

type ShardStatus

type ShardStatus struct {
	Shard     int  `json:"shard"`
	OK        bool `json:"ok"`
	Started   bool `json:"started"`
	NumGuilds int  `json:"num_guilds"`

type Status

type Status struct {
	Shards    []*ShardStatus `json:"shards"`
	NumGuilds int            `json:"num_guilds"`

Jump to

Keyboard shortcuts

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