core

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2016 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package core handles the internal logic of Abot. It's kept separate from the shared/ libraries which plugins may depend upon. This package should rarely (if ever) be used externally outside of Abot's core.

Index

Constants

This section is empty.

Variables

View Source
var AllPlugins = []*dt.Plugin{}

AllPlugins contains a set of all registered plugins.

View Source
var ErrInvalidUserPass = errors.New("Invalid username/password combination")

ErrInvalidUserPass reports an invalid username/password combination during login.

View Source
var RegPlugins = PkgMap{
	// contains filtered or unexported fields
}

RegPlugins initializes a PkgMap and holds it in global memory, which works OK given PkgMap is an atomic, thread-safe map.

Functions

func ConfusedLang added in v0.2.0

func ConfusedLang() string

ConfusedLang returns a randomized response signalling that Abot is confused or could not understand the user's request.

func ConnectDB added in v0.2.0

func ConnectDB() (*sqlx.DB, error)

ConnectDB opens a connection to the database.

func DB

func DB() *sqlx.DB

DB returns a connection the database. This is used internally across packages, and isn't needed when building plugins. If you're building a plugin, use your plugin's p.DB instead.

func GetPlugin

func GetPlugin(db *sqlx.DB, m *dt.Msg) (p *dt.Plugin, route string, directroute,
	followup bool, err error)

GetPlugin attempts to find a plugin and route for the given msg input if none can be found, it checks the database for the last route used and gets the plugin for that. If there is no previously used plugin, we return errMissingPlugin. The bool value return indicates whether this plugin is different from the last plugin used by the user.

func LoadConf added in v0.2.0

func LoadConf() error

LoadConf plugins.json into a usable struct.

func LoadEnvVars added in v0.2.0

func LoadEnvVars() error

LoadEnvVars from abot.env into memory

func NewMsg

func NewMsg(u *dt.User, cmd string) (*dt.Msg, error)

NewMsg builds a message struct with Tokens, Stems, and a Structured Input.

func NewServer

func NewServer() (r *httprouter.Router, err error)

NewServer connects to the database and boots all plugins before returning a server connection, database connection, and map of offensive words.

func ProcessText

func ProcessText(r *http.Request) (ret string, err error)

ProcessText is Abot's core logic. This function processes a user's message, routes it to the correct plugin, and handles edge cases like offensive language before returning a response to the user. Any user-presentable error is returned in the string. Errors returned from this function are not for the user, so they are handled by Abot explicitly on this function's return (logging, notifying admins, etc.).

func RandSeq added in v0.2.0

func RandSeq(n int) string

RandSeq generates a random sequence of letters of length n.

From https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-golang

func RespondWithHelp added in v0.2.0

func RespondWithHelp(in *dt.Msg) string

RespondWithHelp replies to the user when he or she asks for "help".

func RespondWithHelpConfused added in v0.2.0

func RespondWithHelpConfused(in *dt.Msg) string

RespondWithHelpConfused replies to the user when Abot is confused.

func RespondWithNicety

func RespondWithNicety(in *dt.Msg) string

RespondWithNicety replies to niceties that humans use, but Abot can ignore. Words like "Thank you" are not necessary for a robot, but it's important Abot respond correctly nonetheless.

func RespondWithOffense

func RespondWithOffense(in *dt.Msg) string

RespondWithOffense is a one-off function to respond to rude user language by refusing to process the command.

func StemTokens added in v0.2.0

func StemTokens(tokens []string) []string

StemTokens returns the porter2 (snowball) stems for each token passed into it.

func TokenizeSentence added in v0.2.0

func TokenizeSentence(sent string) []string

TokenizeSentence returns a sentence broken into tokens. Tokens are individual words as well as punctuation. For example, "Hi! How are you?" becomes []string{"Hi", "!", "How", "are", "you", "?"}. This also expands contractions into the words they represent, e.g. "How're you?" becomes []string{"How", "'", "are", "you", "?"}.

Types

type Header struct {
	ID       uint64
	Email    string
	Scopes   []string
	IssuedAt int64
}

Header represents an HTTP request's header from the front-end JS client. This is used to identify the logged in user in each web request and the permissions of that user.

type PkgMap added in v0.2.0

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

PkgMap is a thread-safe atomic map that's used to route user messages to the appropriate plugins. The map's key is the route in the form of command_object, e.g. "find_restaurant".

func (PkgMap) Get added in v0.2.0

func (pm PkgMap) Get(k string) *dt.Plugin

Get is a thread-safe, locking way to access the values of a PkgMap.

func (PkgMap) Set added in v0.2.0

func (pm PkgMap) Set(k string, v *dt.Plugin)

Set is a thread-safe, locking way to set the values of a PkgMap.

type PluginJSON added in v0.2.0

type PluginJSON struct {
	Name         string
	Description  string
	Version      float64
	ImportPath   string
	Dependencies map[string]string
}

PluginJSON holds the plugins.json structure.

func Conf added in v0.2.0

func Conf() *PluginJSON

Conf returns Abot's plugins.json configuration.

Directories

Path Synopsis
Package log is a logger used by Abot core and plugins.
Package log is a logger used by Abot core and plugins.
Package template builds commonly used emails filled in with custom information.
Package template builds commonly used emails filled in with custom information.
Package websocket manages websocket connections and notifications for Abot clients.
Package websocket manages websocket connections and notifications for Abot clients.

Jump to

Keyboard shortcuts

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