radigast

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2015 License: Apache-2.0 Imports: 7 Imported by: 1

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

Developing 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.Chat().Send(s.Message().Channel().ID(), 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
	// 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
all

Jump to

Keyboard shortcuts

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