bot

package module
v0.0.0-...-c6e671b Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 11 Imported by: 1

README

bot

Core bot functionality for Snart.

Documentation

Overview

Package bot contains the general workings of a Snart Bot.

Index

Constants

This section is empty.

Variables

View Source
var Log = minori.GetLogger("bot")

Log is the logger for the bot package.

View Source
var Plugins = make(map[string]Plugin)

Plugins holds the plugins to be loaded into a Bot on startup.

Functions

func GamerUptime

func GamerUptime(b *Bot) (*dg.Game, error)

GamerUptime is an example Gamer that shows the Bot's uptime.

func Register

func Register(name string, plug Plugin)

Register adds a Plugin to the Plugins.

Types

type Bot

type Bot struct {
	DB      *db.DB
	Session *dg.Session

	Router *route.Router
	Gamers []Gamer

	Interrupt chan Interrupt
	Startup   time.Time
}

Bot holds all the internal workings of a Snart bot.

func NewBot

func NewBot(d *db.DB) (*Bot, error)

NewBot creates a Bot from a given DB connection.

func (*Bot) AddGamer

func (b *Bot) AddGamer(g Gamer)

AddGamer registers a Gamer into the Bot.

func (*Bot) Admin

func (b *Bot) Admin(c *route.Ctx) bool

Admin checks if the author has bot-wide admin privileges. (implements route.Okay)

func (*Bot) CycleGamers

func (b *Bot) CycleGamers()

CycleGamers cycles through displaying the Gamers registered on the Bot.

func (*Bot) GoPlugins

func (b *Bot) GoPlugins()

GoPlugins spawns all of the Plugins on the Bot.

func (*Bot) NotifyInterrupt

func (b *Bot) NotifyInterrupt(sigs ...os.Signal)

NotifyInterrupt uses signal.Notify and a pipe goroutine to send OS-level interrupts on the Bot's Interrupt.

func (*Bot) Route

func (b *Bot) Route(s *dg.Session, m *dg.MessageCreate)

Route is an event handler for dispatching a *dg.MessageCreate to the Bot's Router.

func (*Bot) Start

func (b *Bot) Start() error

Start performs the Bot's startup functions, and then waits until an interrupt.

func (*Bot) WaitReady

func (b *Bot) WaitReady()

WaitReady loops until the Bot has a valid Session, and then calls the Bot's DB's WaitReady method.

type Gamer

type Gamer func(*Bot) (*dg.Game, error)

Gamer provides a Discord Game status for a given Bot state.

func GamerText

func GamerText(text string, typ dg.GameType) Gamer

GamerText return an example Gamer that shows the given text and game type.

type Interrupt

type Interrupt struct {
	Sig os.Signal
	Err error
}

Interrupt wraps an os.Signal or error which causes a Bot to exit.

type Plugin

type Plugin func(*Bot) error

Plugin is a function which registers a plugin onto a Bot.

Jump to

Keyboard shortcuts

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