sento

package module
v0.0.0-...-853a7a3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sento is a discord bot framework.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultConfig for a discord bot
	DefaultConfig = Config{
		Prefix: "#!",
	}
)

Functions

This section is empty.

Types

type Bot

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

Bot is a sento-powered bot application

func New

func New(options ...Option) (bot *Bot, err error)

New returns a new sento-powered discord bot

func (*Bot) EmitEvent

func (bot *Bot) EmitEvent(eventType EventType, data interface{})

EmitEvent and broadcast it to all listeners

func (*Bot) LogError

func (b *Bot) LogError(msg string, fields ...LogField)

LogError logs an error to the console

func (*Bot) LogInfo

func (b *Bot) LogInfo(msg string, fields ...LogField)

LogInfo logs the `msg` to the console

func (*Bot) Send

func (bot *Bot) Send(info HandleInfo, message string) (err error)

Send `message` into the given channel

func (*Bot) Sess

func (bot *Bot) Sess() *discordgo.Session

func (*Bot) Start

func (bot *Bot) Start() (err error)

Start an instance of the bot

func (*Bot) Stop

func (bot *Bot) Stop() (err error)

Stop the bot

type Config

type Config struct {
	Token      string
	InviteLink string
	Prefix     string
}

Config for a sento-powered discord bot

type EventData

type EventData struct {
	Bot  *Bot
	Data interface{}
}

EventData for a listener

type EventListener

type EventListener interface {
	Type() EventType
	Chan() chan EventData
}

EventListener interface used for defining listeners

type EventType

type EventType int

EventType indicates the supported event types

const (
	// EventConnected emitted when the discord session opens
	EventConnected EventType = iota
	// EventMessageSent emitted when the bot sends a message
	EventMessageSent
	// EventMessageReceived emitted when the bot processes a message
	EventMessageReceived
	// EventDisconnected emitted when the discord session closes
	EventDisconnected
)

type HandleInfo

type HandleInfo struct {
	Trigger        string
	GuildID        string
	ChannelID      string
	MessageID      string
	AuthorID       string
	MessageContent string
}

HandleInfo about a single trigger instance

func (HandleInfo) Message

func (hi HandleInfo) Message(bot *Bot) (*discordgo.Message, error)

Message returns the discord message that originated this trigger

type Handler

type Handler interface {
	// Name of the handler
	Name() string
	// Triggers for a given handler
	Triggers() []string
	// Handle the trigger instance
	Handle(bot *Bot, info HandleInfo) error

	// Start runs when the bot connection has been made
	// and is adding all handlers
	Start(bot *Bot) error
	// Stop runs when the bot is being shut down
	Stop(bot *Bot) error
}

Handler listens for an specific command and contain all the logic necesary for it

type LogField

type LogField = zap.Field

LogField for a logger

func FieldString

func FieldString(key string, value string) LogField

FieldString for a log entry

type Option

type Option func(*Bot) error

Option for a sent-powered discord bot

func UseConfig

func UseConfig(cfg *Config) Option

UseConfig sets the config for a bot

func UseConfigFile

func UseConfigFile(path string) Option

UseConfigFile makes a robot use the indicated config file. Note that the config MUST be in TOML format.

func UseHandlers

func UseHandlers(handlers ...Handler) Option

UseHandlers sets the handlers for a bot

func UseListeners

func UseListeners(listeners ...EventListener) Option

UseListeners sets the listeners for a bot

Jump to

Keyboard shortcuts

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