baepi

package
v0.0.0-...-ba309c1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package baepi defines a simple api for interactions between the bae and any handlers that define bae features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaeHistoKey

type BaeHistoKey struct {
	BaestFriendID string
	HandlerName   string
}

BaeHistoKey contains optional constraints when searching the bae's history.

type BaeHistoryEntry

type BaeHistoryEntry struct {
	HandlerName string
	Response    *Baesponse
	TimeSaid    time.Time
	RepliedTo   *BaestFriend
}

BaeHistoryEntry contains a single bae response along with metadata about what handler

func (*BaeHistoryEntry) Matches

func (he *BaeHistoryEntry) Matches(k *BaeHistoKey) bool

type BaeSayHandler

type BaeSayHandler interface {
	// ShouldSay returns whether a handler should respond. If this returns true,
	// SayWithBae will be called.
	ShouldSay(DiceBae, *Baevent) bool
	// SayWithBae returns what the bae should say when ShouldSay returns OK.
	SayWithBae(DiceBae, *Baevent) (*Baesponse, error)
}

BaeSayHandler defines the interface for a simple handler that conditionally responds to anyone in a channel containing the bae. Bae handlers need to only define under what conditions to trigger, and what to say if triggered. Mostly, this abstracts away the extra, unnecessary details provided by discordgo, since most of the time all the bae wants to do is reply to some hotword or regexp spoken by a player.

type Baesponse

type Baesponse struct {
	Message         string
	MentionUser     bool
	HandlerMetadata interface{}
}

Baesponse contains the bae's response to a Baevent. Beyond the message to be sent to the channel, it also includes a generic metadata argument that will be stored in the bae's history. Handlers can use this metadata by pulling old replies out of the bae's history.

type BaestFriend

type BaestFriend struct {
	ID       string
	Username string
}

BaestFriend defines a user entity in discord. The ID can be used to <@ID> mention a user in a Baesponse and the username is the human-readable username. This is essentially a subset of the User fields from discordgo.

func (*BaestFriend) Mention

func (bf *BaestFriend) Mention(message string) string

Mention returns a modified message string that will trigger a mention, e.g., @someuser: message, in Discord.

type Baevent

type Baevent struct {
	Speaker *BaestFriend
	Message string
}

Baevent is a Bae Event. Specifically, it encapsulates a user sending a message in a discord channel containing the bae.

type DiceBae

type DiceBae interface {
	LetsRoll() error
	LogInfo(string, ...interface{})
	LogError(string, ...interface{})
	FetchHistory(*BaeHistoKey, int) []*BaeHistoryEntry
}

DiceBae defines the public interface for the bae. This is what handlers will interact with instead of the raw, powerful bae implementation.

Jump to

Keyboard shortcuts

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