eris

package module
v0.0.0-...-59c359b Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

README

eris

eris is a go library that wraps discordgo with the goal of creating an extensible bot framework as well as enabling faster bot development.

This is still in the early stages of production and no promises are made for the stability of any current features.

Plugins

eris defines a Plugin interface that can be used to add a whole slew of features to your bot while keeping things organized and readable. eris by default will also add a /plugins command to your bot that lets users see what cool features you have baked into your bot without requiring extra steps from you. A few working examples can be found in the plugins/ directory.

Using the Plugin Interface

The plugin interface is defined as follows:

type Plugin interface {
	Name() string
	Description() string
	Handlers() map[string]any
	Commands() map[string]*discordgo.ApplicationCommand
	Intents() []discordgo.Intent
}
Name

A thoughtful name should be returned by your plugin that gives a general idea of what it does.

Description

A slightly longer description of what your plugin does.

Handlers

A map of handler ids and handler functions. The handler function should be one of the many options provided by discordgo here. Handler ids are global to an eris bot, so it is recommended that they contain unique identifiers relevant to the plugin otherwise they might be overwritten. Return nil if not applicable.

Commands

A map of command ids and discordgo application commands. This is only necessary if your plugin configures any application commands. Like handlers, the id is global to an eris bot so care should be taken that there are no possible collisions with other plugin's commands. Return nil if not applicable.

Intents

A list of intents that are required by your plugin to function. This helps ensure that any plugins added to an eris bot will work out of the box without the need to configure additional intents manually.

Utils

Some additional utils are also packaged in the utils/ directory. These are aimed to be useful wrappers around discordgo functions to make some calls less involved or more readable.

Examples

An example bot built using eris can be found in the _example/ directory. This exact one probably won't live here forever.

Documentation

Index

Constants

View Source
const Version = "v0.0.1"

Variables

This section is empty.

Functions

This section is empty.

Types

type Bot

type Bot struct {
	Logger *slog.Logger
	// contains filtered or unexported fields
}

func NewBot

func NewBot(config Config, h slog.Handler) (*Bot, error)

func (*Bot) AddCommand

func (b *Bot) AddCommand(cmd *discordgo.ApplicationCommand, guildIds ...string)

AddCommand registers an ApplicationCommand to the specified guild Ids (global if empty). The supplied command will be compared against currently registered commands to prevent re-registering the same exact command.

func (*Bot) AddHandler

func (b *Bot) AddHandler(name string, handler any)

func (*Bot) AddIntent

func (b *Bot) AddIntent(intent discordgo.Intent)

func (*Bot) AddPlugin

func (b *Bot) AddPlugin(plugin Plugin, guildIds ...string) error

func (*Bot) Id

func (b *Bot) Id() string

func (*Bot) ReloadPlugin

func (b *Bot) ReloadPlugin(name string)

func (*Bot) RemoveCommand

func (b *Bot) RemoveCommand(cmdId string, guildIds ...string)

func (*Bot) RemoveHandler

func (b *Bot) RemoveHandler(name string)

func (*Bot) RemovePlugin

func (b *Bot) RemovePlugin(plugin Plugin, guildIds ...string)

func (*Bot) Restart

func (b *Bot) Restart() error

func (*Bot) Start

func (b *Bot) Start() error

func (*Bot) Stop

func (b *Bot) Stop() error

type BotState

type BotState int
const (
	StartedState BotState = iota
	StoppedState
	UnknownState
)

type Config

type Config struct {
	Token    string
	AdminIds []string `yaml:"admin_ids"`
}

type Plugin

type Plugin interface {
	Name() string
	Description() string
	Handlers() map[string]any
	Commands() map[string]*discordgo.ApplicationCommand
	Intents() []discordgo.Intent
}

Plugin is the baseline interface for extending bot behavior.

type PluginManager

type PluginManager struct {
	// contains filtered or unexported fields
}

func (PluginManager) Commands

func (PluginManager) Description

func (p PluginManager) Description() string

func (PluginManager) Handlers

func (p PluginManager) Handlers() map[string]any

func (PluginManager) Intents

func (p PluginManager) Intents() []discordgo.Intent

func (PluginManager) Name

func (p PluginManager) Name() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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