fuse

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2023 License: GPL-3.0 Imports: 15 Imported by: 0

README

fuse

Fuse is a simple, multi-guild Discord bot library built in Go. It is designed to be easy to use and easy to extend through its service functionality.

BEWARE!

This library is still in development and is not ready for production use. It is currently being used in a few projects but isn't fully equipped for public use.

Many systems involved in this library are not fully fleshed out and contain ugly code. This will be fixed in the future but for now, use at your own risk.

Documentation

Index

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
	// The string used to connect to the database
	DatabaseString 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 NewManager(logger log.Logger, config *Config) (*Manager, error)

func (*Manager) BotUser

func (mng *Manager) BotUser() *discordgo.User

func (*Manager) Config

func (mng *Manager) Config() *Config

func (*Manager) Connection

func (mng *Manager) Connection() *gorm.DB

func (*Manager) CreateServices

func (mng *Manager) CreateServices(guildManager *GuildManager) ([]Service, error)

CreateServices creates a service for a provided guild manager

func (*Manager) GuildExists

func (mng *Manager) GuildExists(guildID string) bool

func (*Manager) GuildManager

func (mng *Manager) GuildManager(guildID string) (*GuildManager, error)

func (*Manager) Logger

func (mng *Manager) Logger() log.Logger

func (*Manager) Member

func (mng *Manager) Member(guildID string) (*discordgo.Member, error)

func (*Manager) OnStart

func (mng *Manager) OnStart(f ManagerStartFunc)

func (*Manager) RegisterService

func (mng *Manager) RegisterService(s Service)

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()

func (*Manager) Session

func (mng *Manager) Session() *discordgo.Session

func (*Manager) Start

func (mng *Manager) Start() error

func (*Manager) Stop

func (mng *Manager) Stop()

type ManagerStartFunc

type ManagerStartFunc func(*Manager) error

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

func (StringArray) Value

func (a StringArray) Value() (driver.Value, error)

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp represents a Discord timestamp in milliseconds

func CreateTimestamp

func CreateTimestamp(t time.Time) Timestamp

func (Timestamp) RelativeString

func (t Timestamp) RelativeString() string

func (Timestamp) String

func (t Timestamp) String() string

String returns a string representation of the timestamp in the format <t:1234567890> or <t:1234567890:R> if relative is true

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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