fuse

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: GPL-3.0 Imports: 14 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

func (*GuildManager) CommandHandler

func (mng *GuildManager) CommandHandler() *command.CommandHandler

func (*GuildManager) Connection

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

func (*GuildManager) GlobalManager

func (mng *GuildManager) GlobalManager() *Manager

func (*GuildManager) Guild

func (mng *GuildManager) Guild() *discordgo.Guild

func (*GuildManager) ListenForComponent

func (mng *GuildManager) ListenForComponent(customId string, handler component.ComponentHandlerFunc)

func (*GuildManager) Logger

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

func (*GuildManager) ModalHandler

func (mng *GuildManager) ModalHandler() *modal.ModalHandler

func (*GuildManager) Save

func (mng *GuildManager) Save() error

func (*GuildManager) Session

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

func (*GuildManager) Start

func (mng *GuildManager) Start() error

func (*GuildManager) Stop

func (mng *GuildManager) Stop() error

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

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 {
	// Name returns the name of the service
	Name() string
	// 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 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