Documentation ¶
Index ¶
- type Config
- type GuildConfiguration
- type GuildManager
- func (mng *GuildManager) AddHandler(handler interface{})
- func (mng *GuildManager) BotUser() *discordgo.User
- func (mng *GuildManager) CommandHandler() *command.CommandHandler
- func (mng *GuildManager) Connection() *gorm.DB
- func (mng *GuildManager) FetchServiceConfig(config interface{}, defaults ...interface{}) error
- func (mng *GuildManager) GlobalManager() *Manager
- func (mng *GuildManager) Guild() *discordgo.Guild
- func (mng *GuildManager) ListenForComponent(customId string, handler component.ComponentHandlerFunc)
- func (mng *GuildManager) Logger() log.Logger
- func (mng *GuildManager) ModalHandler() *modal.ModalHandler
- func (mng *GuildManager) Save() error
- func (mng *GuildManager) SaveServiceConfig(config interface{}) error
- func (mng *GuildManager) Session() *discordgo.Session
- func (mng *GuildManager) Start() error
- func (mng *GuildManager) Stop() error
- type Manager
- func (mng *Manager) BotUser() *discordgo.User
- func (mng *Manager) Config() *Config
- func (mng *Manager) Connection() *gorm.DB
- func (mng *Manager) CreateServices(guildManager *GuildManager) ([]Service, error)
- func (mng *Manager) GuildExists(guildID string) bool
- func (mng *Manager) GuildManager(guildID string) (*GuildManager, error)
- func (mng *Manager) Logger() log.Logger
- func (mng *Manager) Member(guildID string) (*discordgo.Member, error)
- func (mng *Manager) OnStart(f ManagerStartFunc)
- func (mng *Manager) RegisterService(s Service)
- func (mng *Manager) Session() *discordgo.Session
- func (mng *Manager) Start() error
- func (mng *Manager) Stop()
- type ManagerStartFunc
- type Service
- type ServiceConfiguration
- type StringArray
- type Timestamp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // The token used to authenticate with Discord Token string }
Config is the structure that holds the configuration for the manager It holds the token used to authenticate with Discord and the string used to connect to the database
type GuildConfiguration ¶
type GuildConfiguration struct { // GuildID is the ID of the guild and is used as the primary key GuildID string `gorm:"primarykey"` }
GuildConfiguration is the structure that holds the configuration for a single guild
type GuildManager ¶
type GuildManager struct {
// contains filtered or unexported fields
}
GuildManager is the structure that manages all of the services for a single guild It holds the guild's ID, its configuration, the database connection, and the Discord session
func CreateGuildManager ¶
func CreateGuildManager(manager *Manager, config *GuildConfiguration) (*GuildManager, error)
func (*GuildManager) AddHandler ¶
func (mng *GuildManager) AddHandler(handler interface{})
AddHandler is a wrapper for the session handler but limits the handler to only the guild This may seem excessive but it is a good practice to prevent accidental checking of the wrong guild
func (*GuildManager) BotUser ¶
func (mng *GuildManager) BotUser() *discordgo.User
BotUser returns the bot user for the guild
func (*GuildManager) CommandHandler ¶
func (mng *GuildManager) CommandHandler() *command.CommandHandler
CommandHandler returns the command handler for the guild
func (*GuildManager) Connection ¶
func (mng *GuildManager) Connection() *gorm.DB
Connection returns the database connection for the guild
func (*GuildManager) FetchServiceConfig ¶ added in v0.0.3
func (mng *GuildManager) FetchServiceConfig(config interface{}, defaults ...interface{}) error
FetchServiceConfig fetches the service configuration from the database If the configuration does not exist, it will be created for the guild An example of this in action would be like so:
var config MyServiceConfig err := mng.FetchServiceConfig(&config) ...
func (*GuildManager) GlobalManager ¶
func (mng *GuildManager) GlobalManager() *Manager
GlobalManager returns Fuse's global manager instance
func (*GuildManager) Guild ¶
func (mng *GuildManager) Guild() *discordgo.Guild
Guild returns the instance of the guild
func (*GuildManager) ListenForComponent ¶
func (mng *GuildManager) ListenForComponent(customId string, handler component.ComponentHandlerFunc)
ListenForComponent registers a handler for a specific component
func (*GuildManager) Logger ¶
func (mng *GuildManager) Logger() log.Logger
Logger returns the logger for the guild
func (*GuildManager) ModalHandler ¶
func (mng *GuildManager) ModalHandler() *modal.ModalHandler
ModalHandler returns the modal handler for the guild
func (*GuildManager) Save ¶
func (mng *GuildManager) Save() error
Save saves the built-in guild configuration to the database
func (*GuildManager) SaveServiceConfig ¶ added in v0.0.3
func (mng *GuildManager) SaveServiceConfig(config interface{}) error
SaveServiceConfig saves the service configuration to the database
func (*GuildManager) Session ¶
func (mng *GuildManager) Session() *discordgo.Session
Session returns the Discord session for the guild
func (*GuildManager) Start ¶
func (mng *GuildManager) Start() error
Start starts all of the services for the guild and registers all handlers, both component and command
func (*GuildManager) Stop ¶
func (mng *GuildManager) Stop() error
Stop stops all of the services for the guild and deinitializes the command handler
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager is the overarching structure that manages all of the guild sub-services Moreover, it holds the database connection and handles all Discord events
func NewManager ¶
func (*Manager) Connection ¶
func (*Manager) CreateServices ¶
func (mng *Manager) CreateServices(guildManager *GuildManager) ([]Service, error)
CreateServices creates a service for a provided guild manager
func (*Manager) GuildExists ¶
func (*Manager) GuildManager ¶
func (mng *Manager) GuildManager(guildID string) (*GuildManager, error)
func (*Manager) OnStart ¶
func (mng *Manager) OnStart(f ManagerStartFunc)
func (*Manager) RegisterService ¶
RegisterService registers a service to be created when the manager starts In most cases, an empty struct should be passed in as the argument This is because the actual guild services will be created using service.Create()
type ManagerStartFunc ¶
type Service ¶
type Service interface { // Create creates a new instance of the service for a provided guild manager Create(mng *GuildManager) (Service, error) // Start is called when the service is started Start(mng *GuildManager) error // Stop is called when the service is stopped Stop(mng *GuildManager) error }
Service is the interface that all services must implement It defines the methods that are called when the service is started or stopped
type ServiceConfiguration ¶ added in v0.0.3
type ServiceConfiguration struct { // GuildID is the ID of the guild and is used as the primary key GuildId string `gorm:"primary_key"` }
ServiceConfiguration is a simple struct used to store a service's configuration in the database This is not always required but has a configured guild ID field for convenience
type StringArray ¶
type StringArray []string
StringArray is a wrapper around []string that implements the sql.Scanner and driver.Valuer interfaces
func (*StringArray) Scan ¶
func (a *StringArray) Scan(value any) error
type Timestamp ¶
Timestamp represents a Discord timestamp in milliseconds