radigast

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2015 License: Apache-2.0 Imports: 8 Imported by: 0

README

Radigast - Go Slack bot with configurable plugins.

Radigast is based on https://github.com/FogCreek/victor which is a fork of https://github.com/brettbuddin/victor and uses the Slack Real Time Messaging API.

Configuration

Radigast loads configuration from a TOML file. The main configuration must be under [radigast] and the configuration for each plugin must be under [plugin_name]

See config.toml.sample for a complete example.

How to use it

Run radigast -config radigast.toml to connect to slack.

Plugins

Radigast supports two types of plugins: The first type of plugin is a Go plugin that must be compiled with the Radigast cli tool. See more under Developing Go Plugins The second type of plugin uses JSON-RPC and can be written in most languages.

An RPC plugin must provide the following methods: For an RPC plugin to work, it must offer the following methods:

 Name() string
 Description() string
 Usage() []string
 Handle(args) string

The args in Handle(args) will be of the following struct type:

 type Args struct {
 	// Chat user calling the plugin.
 	User string
 	// The arguments a user passes to the bot.
 	Fields []string
 }

RPC plugins must be installed in a directory specified in the config file. Each plugin name must be added to the rpcplugins array in the config.

Developing Go Plugins

Radigast uses the same plugin model as telegraf

  • A plugin must conform to the plugins.Registrator interface
  • Plugins should call plugins.Add in their init function to register themselves
  • To be available to the Radigast command, plugins must be added to the github.com/groob/radigast/plugins/all/all.go file.
  • A plugin will only be configured by radigast if there is a [plugin_name] section in the config file

Plugin Interface

type Registrator interface {
	Register() []victor.HandlerDocPair
}

Plugin example

package hello

import (
	"fmt"

	"github.com/FogCreek/victor"
	"github.com/groob/radigast/plugins"
)

// Configuration struct
// toml will unmarshal any options provided under [hello] in
// radigast.toml
type Hello struct {
	// AnOption      string
	// AnotherOption string
}

// Register implements plugins.Registrator
func (h Hello) Register() []victor.HandlerDocPair {
	return []victor.HandlerDocPair{
		&victor.HandlerDoc{
			CmdHandler:     h.helloFunc,
			CmdName:        "hello",
			CmdDescription: "reply back with the user name",
			CmdUsage:       []string{"NAME"},
		},
	}
}

// Bot Handler
// write your plugin logic here.
func (h Hello) helloFunc(s victor.State) {
	msg := fmt.Sprintf("Hello %s!", s.Message().User().Name())
	s.Reply(msg)
}

func init() {
	// register the plugin
	plugins.Add("hello", func() plugins.Registrator {
		return &Hello{}
	})
}

Example usage

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("invalid configuration")

Invalid toml config

Functions

This section is empty.

Types

type Config

type Config struct {
	SlackToken  string
	BotName     string
	PluginsPath string
	Rpcplugins  []string
	// contains filtered or unexported fields
}

Config holds the radigast configuration

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig unmarshalls toml config file for radigast and all plugins

func (Config) LoadPlugins

func (c Config) LoadPlugins(r victor.Robot)

LoadPlugins registers victor.Handlers with radigast and adds any additional configuration to the plugin

Directories

Path Synopsis
cmd
example-rpc
all

Jump to

Keyboard shortcuts

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