bot

package
v0.0.0-...-a7177cb Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2023 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Config config.Config

	State        *state.State
	DB           Database
	Interactions *bcr.Router

	Modules []Module
	// contains filtered or unexported fields
}

func New

func New(c config.Config) (bot *Bot, err error)

func (*Bot) Logger

func (*Bot) Logger() Logger

func (*Bot) Start

func (bot *Bot) Start(ctx context.Context) error

Start sets up all of the registered modules, and opens a connection to Discord.

type Database

type Database interface {
	Migrator() Migrator
	Scheduler() Scheduler

	Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
	Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

	GetContext(ctx context.Context, v any, sql string, args ...any) error
	SelectContext(ctx context.Context, v any, sql string, args ...any) error
	Get(v any, sql string, args ...any) error
	Select(v any, sql string, args ...any) error

	db.Config
}

type Event

type Event = db.Event

type HasConfig

type HasConfig interface {
	// SetupConfig should return a pointer to the configuration struct,
	// and a bool indicating whether the configuration file is required.
	//
	// The file name will be the module's Name() + the .yaml file extension.
	SetupConfig() (v any, required bool)
}

type Logger

type Logger interface {
	Debug(v ...any)
	Info(v ...any)
	Warn(v ...any)
	Error(v ...any)
	Fatal(v ...any)

	Debugf(tmpl string, v ...any)
	Infof(tmpl string, v ...any)
	Warnf(tmpl string, v ...any)
	Errorf(tmpl string, v ...any)
	Fatalf(tmpl string, v ...any)
}

type Migrator

type Migrator = db.MigratorInterface

type Module

type Module interface {

	// Name is used for the configuration file (suffixed with .yaml), database schema, and help command.
	// It should be lowercase.
	Name() string
	// Migrations are added to the database's Migrator.
	// nil if the module has no migrations.
	Migrations() migrate.MigrationSource

	// Setup is used to register aliases, handlers etc.
	// Most modules can just use Commands, AppCommands, Handlers, and EventTypes instead.
	Setup() error

	// Ready is called *in a separate goroutine* when the bot receives its first ready event
	Ready()

	// TODO: replace with slice of command structs
	Commands() []any

	// List of application commands to register with Discord
	AppCommands() []api.CreateCommandData

	// List of handlers to add to the bot
	Handlers() []any

	// EventTypes are registered to the database's Scheduler
	EventTypes() []db.Event
	// contains filtered or unexported methods
}

Module is a module. It must embed ModuleBase in this package.

Modules may also implement the following other interfaces: - HasConfig

type ModuleBase

type ModuleBase struct {
	*Bot
}

ModuleBase is the base for a module. It must be embedded into bot module types (usually called "Module" as well)

func (*ModuleBase) AppCommands

func (*ModuleBase) AppCommands() []api.CreateCommandData

func (*ModuleBase) Commands

func (*ModuleBase) Commands() []any

func (*ModuleBase) EventTypes

func (*ModuleBase) EventTypes() []db.Event

func (*ModuleBase) Handlers

func (*ModuleBase) Handlers() []any

func (*ModuleBase) Migrations

func (*ModuleBase) Migrations() migrate.MigrationSource

Methods that modules can override, defined here so that unused methods don't have to be added to modules.

func (*ModuleBase) Ready

func (*ModuleBase) Ready()

func (*ModuleBase) Setup

func (*ModuleBase) Setup() error

type Scheduler

type Scheduler = db.SchedulerInterface

type SchedulerBot

type SchedulerBot = db.Bot

Jump to

Keyboard shortcuts

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