scarecrow

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

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

Go to latest
Published: Jul 18, 2016 License: GPL-2.0 Imports: 11 Imported by: 0

README

Scarecrow

Scarecrow is a chatbot written in Go. It connects to Slack and XMPP and can be chatted with in your terminal window, and it will probably be updated to connect to more things in the future too.

It uses RiveScript as its brain back-end, it remembers information about the people it chats with, keeps log files, etc.

Features

  • Slack integration
    • Users can chat with it over direct message and carry on a conversation
    • It can join public channels where it will sit in silence until a user talks directly to it, either by at-mentioning its username or starting a message with its name.
  • XMPP integration
    • Hangouts bot via the XMPP gateway: use talk.google.com port 443 instead of the standard XMPP ports (5222 or 5223)
    • Known to work with an ejabberd server with valid CA certificate (you may need to set "tls-disable": "true" in the bot's config)
  • User roles/permissions
    • Admin users can reload the RiveScript brain without rebooting the entire bot
    • Users across different platforms are uniquely identifiable, so you can add admin users without risking a different user with a matching name on a different platform having admin rights.
  • Goroutines are spawned for each individual bot connection, so you can run multiple bots from one instance of the program.
  • Chat with the bot on the console, too

Install and Build

Build it with make build

Run it with ./scarecrow-cli

Command line options are pretty basic: --debug for debug mode and --version to get the version number.

Documentation

Documentation is available as Markdown files in the docs/ directory.

License

Scarecrow - A RiveScript Chatbot written in Go
Copyright (C) 2015  Noah Petherbridge

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

See Also

RiveScript's official homepage, http://www.rivescript.com/

The RiveScript Go module, https://github.com/aichaos/rivescript-go

Documentation

Index

Constants

View Source
const (
	VERSION = "1.0.0"
)

Variables

View Source
var (
	RE_OP   = regexp.MustCompile(`^!op ([A-Za-z0-9\.@\-_]+?)$`)
	RE_DEOP = regexp.MustCompile(`^!deop ([A-Za-z0-9\.@\-_]+?)$`)
)

Functions

func MakeDirectory

func MakeDirectory(path string)

MakeDirectory makes a directory if it doesn't already exist.

Types

type Scarecrow

type Scarecrow struct {
	// Parameters.
	Debug bool

	// Internal structures.
	AdminsConfig types.AdminsConfig
	BotsConfig   types.BotsConfig
	Brain        *rivescript.RiveScript

	// Listeners.
	Listeners     map[string]listeners.Listener
	ListenersLock sync.RWMutex
}

Type Scarecrow represents the parent object of one or more bots.

func New

func New() *Scarecrow

func (*Scarecrow) Error

func (self *Scarecrow) Error(message string, a ...interface{})

func (*Scarecrow) GetReply

func (self *Scarecrow) GetReply(botUsername, username, message string, groupChat bool) string

GetReply actually gets a response for a user.

Parameters:

  • botUsername: The bot's username, for logging purposes.
  • username: The user's unique user ID.
  • message: The user's message.
  • groupChat: Whether this message originated from a public room and not a direct message.

func (*Scarecrow) Info

func (self *Scarecrow) Info(message string, a ...interface{})

func (*Scarecrow) InitBrain

func (self *Scarecrow) InitBrain()

InitBrain loads the RiveScript brain.

func (*Scarecrow) InitConfig

func (self *Scarecrow) InitConfig()

InitConfig loads the bot's configuration files.

func (*Scarecrow) IsAdmin

func (self *Scarecrow) IsAdmin(username string) bool

IsAdmin returns whether a user ID is an admin user or not.

func (*Scarecrow) LoadAdminsConfig

func (self *Scarecrow) LoadAdminsConfig() types.AdminsConfig

LoadAdminsConfig loads the config/admins.json config file.

func (*Scarecrow) LoadBotsConfig

func (self *Scarecrow) LoadBotsConfig() types.BotsConfig

LoadBotsConfig loads the config/bots.json config file.

func (*Scarecrow) LoadUservars

func (self *Scarecrow) LoadUservars(path string)

LoadUservars loads a user's RiveScript variables from disk.

func (*Scarecrow) Log

func (self *Scarecrow) Log(message string, a ...interface{})

func (*Scarecrow) LogTransaction

func (self *Scarecrow) LogTransaction(username, message, bot, reply string)

LogTransaction logs a full transaction between a user and the bot.

func (*Scarecrow) ManageListener

func (self *Scarecrow) ManageListener(request, answer chan types.CommunicationChannel)

ManageListener manages the Request/Answer channels for each listener.

func (*Scarecrow) OnMessage

func (self *Scarecrow) OnMessage(req *types.ReplyRequest, res chan types.CommunicationChannel)

func (*Scarecrow) OnStopped

func (self *Scarecrow) OnStopped(ev *types.Stopped)

OnStopped handles when a listener informs us that they have been stopped.

func (*Scarecrow) Run

func (self *Scarecrow) Run()

Run enters the main loop.

func (*Scarecrow) SaveAdminsConfig

func (self *Scarecrow) SaveAdminsConfig(cfg types.AdminsConfig)

SaveAdminsConfig saves the config/admins.json config file.

func (*Scarecrow) SaveUservars

func (self *Scarecrow) SaveUservars(username, path string)

SaveUservars saves a user's RiveScript variables to disk.

func (*Scarecrow) Shutdown

func (self *Scarecrow) Shutdown()

Shutdown shuts down all the bots.

func (*Scarecrow) Start

func (self *Scarecrow) Start()

Start initializes and runs the bots.

func (*Scarecrow) Warn

func (self *Scarecrow) Warn(message string, a ...interface{})

Directories

Path Synopsis
cmd
scarecrow
Main entry point for the Scarecrow chatbot application.
Main entry point for the Scarecrow chatbot application.
Package listeners provides implementations for various front-ends for the Scarecrow chatbot.
Package listeners provides implementations for various front-ends for the Scarecrow chatbot.
Package types contains shareable types between sub-modules.
Package types contains shareable types between sub-modules.

Jump to

Keyboard shortcuts

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