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 ¶
- Variables
- func ConfusedLang() string
- func ConnectDB() (*sqlx.DB, error)
- func DB() *sqlx.DB
- func GetPlugin(db *sqlx.DB, m *dt.Msg) (p *dt.Plugin, route string, directroute, followup bool, err error)
- func LoadConf() error
- func LoadEnvVars() error
- func NewMsg(u *dt.User, cmd string) (*dt.Msg, error)
- func NewServer() (r *httprouter.Router, err error)
- func ProcessText(r *http.Request) (ret string, err error)
- func RandSeq(n int) string
- func RespondWithHelp(in *dt.Msg) string
- func RespondWithHelpConfused(in *dt.Msg) string
- func RespondWithNicety(in *dt.Msg) string
- func RespondWithOffense(in *dt.Msg) string
- func StemTokens(tokens []string) []string
- func TokenizeSentence(sent string) []string
- type Header
- type PkgMap
- type PluginJSON
Constants ¶
This section is empty.
Variables ¶
var AllPlugins = []*dt.Plugin{}
AllPlugins contains a set of all registered plugins.
var ErrInvalidUserPass = errors.New("Invalid username/password combination")
ErrInvalidUserPass reports an invalid username/password combination during login.
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 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 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 ¶
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 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
StemTokens returns the porter2 (snowball) stems for each token passed into it.
func TokenizeSentence ¶ added in v0.2.0
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 ¶ added in v0.2.0
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".
Source Files
¶
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. |