Documentation ¶
Index ¶
- Constants
- Variables
- type Event
- type EventType
- type Manager
- func (m *Manager) AddHandler(handler interface{})
- func (m *Manager) GetFullStatus() *Status
- func (m *Manager) GetNumShards() int
- func (m *Manager) GetRecommendedCount() (int, error)
- func (m *Manager) Init() error
- func (m *Manager) LogConnectionEventStd(e *Event)
- func (m *Manager) OnDiscordConnected(s *discordgo.Session, evt *discordgo.Connect)
- func (m *Manager) OnDiscordDisconnected(s *discordgo.Session, evt *discordgo.Disconnect)
- func (m *Manager) OnDiscordReady(s *discordgo.Session, evt *discordgo.Ready)
- func (m *Manager) OnDiscordResumed(s *discordgo.Session, evt *discordgo.Resumed)
- func (m *Manager) Session(shardID int) *discordgo.Session
- func (m *Manager) SessionForGuild(guildID int64) *discordgo.Session
- func (m *Manager) SessionForGuildS(guildID string) *discordgo.Session
- func (m *Manager) SetNumShards(n int)
- func (m *Manager) Start() error
- func (m *Manager) StdGuildCountsFunc() []int
- func (m *Manager) StdSessionFunc(token string) (*discordgo.Session, error)
- func (m *Manager) StopAll() (err error)
- type SessionFunc
- type ShardStatus
- type Status
Constants ¶
const ( VersionMajor = 0 VersionMinor = 2 VersionPath = 0 )
Variables ¶
var (
VersionString = strconv.Itoa(VersionMajor) + "." + strconv.Itoa(VersionMinor) + "." + strconv.Itoa(VersionPath)
)
Functions ¶
This section is empty.
Types ¶
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
type EventType ¶
type EventType int
const ( // Sent when the connection to the gateway was established EventConnected EventType = iota // Sent when the connection is lose EventDisconnected // Sent when the connection was sucessfully resumed EventResumed // Sent on ready EventReady // Sent when Open() is called EventOpen // Sent when Close() is called EventClose // Sent when an error occurs EventError )
type Manager ¶
type Manager struct { sync.RWMutex // 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 int64 // If set keeps an updated satus message in this channel StatusMessageChannel int64 // 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 ¶
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 ¶
GetFullStatus retrieves the full status at this instant
func (*Manager) GetNumShards ¶
GetNumShards returns the current set number of shards
func (*Manager) GetRecommendedCount ¶
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 ¶
Init initializesthe manager, retreiving the recommended shard count if needed and initalizes all the shards
func (*Manager) LogConnectionEventStd ¶
LogConnectionEventStd is the standard connection event logger, it logs it to whatever log.output is set to.
func (*Manager) OnDiscordConnected ¶
func (*Manager) OnDiscordDisconnected ¶
func (m *Manager) OnDiscordDisconnected(s *discordgo.Session, evt *discordgo.Disconnect)
func (*Manager) OnDiscordReady ¶
func (*Manager) OnDiscordResumed ¶
func (*Manager) Session ¶
Session retrieves a session from the sessions map, rlocking it in the process
func (*Manager) SessionForGuild ¶
SessionForGuild returns the session for the specified guild
func (*Manager) SessionForGuildS ¶
SessionForGuildS is the same as SessionForGuild but accepts the guildID as a string for convenience
func (*Manager) SetNumShards ¶
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) StdGuildCountsFunc ¶
StdGuildsFunc uses the standard states to return the guilds
func (*Manager) StdSessionFunc ¶
StdSessionFunc is the standard session provider, it does nothing to the actual session
type ShardStatus ¶
type ShardStatus struct { Shard int `json:"shard"` Status discordgo.GatewayStatus `json:"status"` Started bool `json:"started"` NumGuilds int `json:"num_guilds"` }
type Status ¶
type Status struct { Shards []*ShardStatus `json:"shards"` NumGuilds int `json:"num_guilds"` }