modules

package
v0.0.0-...-4d485cf Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2016 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BrainTest = &lazlo.Module{
	Name:  `BrainTest`,
	Usage: `"%BOTNAME% brain [set|get] <key> <value>": tests lazlo's persistent storage (aka the brain)`,
	Run: func(b *lazlo.Broker) {
		callback := b.MessageCallback(`(?i:brain) ((?i)set|get) (\w+) *(\w*)$`, true)
		for {
			msg := <-callback.Chan
			brain := b.Brain
			cmd := msg.Match[1]
			key := msg.Match[2]
			if matched, _ := regexp.MatchString(`(?i)set`, cmd); matched {
				val := msg.Match[3]
				if err := brain.Set(key, []byte(val)); err != nil {
					msg.Event.Reply(fmt.Sprintf("Sorry, something went wrong: %s", err))
					lazlo.Logger.Error(err)
				} else {
					msg.Event.Reply(fmt.Sprintf("Ok, %s set to %s", key, val))
				}
			} else {
				val, err := brain.Get(key)
				if err != nil {
					msg.Event.Reply(fmt.Sprintf("Sorry, something went wrong: %s", err))
				} else {
					msg.Event.Reply(string(val))
				}
			}
		}
	},
}
View Source
var CBTable []CBMap

CBtable allows us to Retrieve lua.LState by callback case index

Cases is used by reflect.Select to deliver events from lazlo

View Source
var Help = &lazlo.Module{
	Name:  `Help`,
	Usage: `"%BOTNAME% help": prints the usage information of every registered plugin`,
	Run:   helpRun,
}
View Source
var LinkTest = &lazlo.Module{
	Name:  `LinkTest`,
	Usage: `"%BOTNAME% linkme foo" : creates a clickable link at servername/foo`,
	Run: func(b *lazlo.Broker) {
		clickChan := make(chan string)
		optionChan := make(chan string)
		command_cb := b.MessageCallback(`(?i)(link *me) (.*)`, true)
		command_cb1 := b.MessageCallback(`(?i)(link *test)`, true)
		command_cb2 := b.MessageCallback(`(?i)(link *choice)`, true)
		for {
			select {
			case msg := <-command_cb.Chan:
				msg.Event.Reply(newLink(b, msg.Match[2], clickChan))
			case msg := <-command_cb1.Chan:
				msg.Event.Reply(`<http://www.google.com|foo>`)
			case msg := <-command_cb2.Chan:
				msg.Event.Reply(newChoice(b, optionChan))
			case click := <-clickChan:
				b.Say(fmt.Sprintf("Somebody clicked on %s", click))
			case option := <-optionChan:
				if option == `THIS` {
					b.Say(fmt.Sprintf("I knew you'd get with this.. cause this is kinda phat"))
				} else {
					b.Say(fmt.Sprintf("Not a Blacksheep fan eh? bummer."))
				}
			}
		}
	},
}
View Source
var LuaMod = &lazlo.Module{
	Name:  `LuaMod`,
	Usage: `%HIDDEN% this module implements lua scripting of lazlo`,
	Run:   luaMain,
}

luaMod implements a lua-parsing plugin for Lazlo. this enables lazlo to be scripted via lua instead of GO, which is preferable in some contexts (simpler(?), no recompiles for changes etc..).

View Source
var LuaScripts []LuaScript

LuaScripts allows us to Retrieve lua.LState by LuaScript.Robot.ID

View Source
var PrettyHelp = &lazlo.Module{
	Name:  `Help`,
	Usage: `"%BOTNAME% help": prints the usage information of every registered plugin`,
	Run: func(b *lazlo.Broker) {
		cb := b.MessageCallback(`(?i)help`, true)
		for {
			pm := <-cb.Chan
			go getPrettyHelp(b, &pm)
		}
	},
}
View Source
var QuestionTest = &lazlo.Module{
	Name: `QuestionTest`,
	Usage: `"%BOTNAME% askme foo" : replies with the question: foo?
%BOTNAME% qtest : runs an automated question test`,
	Run: func(b *lazlo.Broker) {
		cb1 := b.MessageCallback(`(?i)(ask *me) (.*)`, true)
		cb2 := b.MessageCallback(`(?i)(qtest)`, true)
		for {
			select {
			case newReq := <-cb1.Chan:
				go newQuestion(b, newReq)
			case newReq := <-cb2.Chan:
				go runTest(b, newReq)
			}
		}
	},
}
View Source
var RTMPing = &lazlo.Module{
	Name:  `RTMPing`,
	Usage: `Automatially sends an RTM Ping to SlackHQ every 20 seconds`,
	Run:   rtmrun,
}
View Source
var Syn = &lazlo.Module{
	Name:  `Ping`,
	Usage: `"%BOTNAME% (ping|syn)" : Test that the bot is currently running`,
	Run:   pingRun,
}

Functions

This section is empty.

Types

type CBMap

type CBMap struct {
	Func     lua.LValue
	Callback reflect.Value
	Script   *LuaScript
}

A CBMap maps a specific callback Case to it's respective lua function and parent lua script

type LocalPatternMatch

type LocalPatternMatch lazlo.PatternMatch

Keep a local version of lazlo.Patternmatch so we can add methods to it

func (LocalPatternMatch) Reply

func (pm LocalPatternMatch) Reply(words string)

lua function to reply to a message passed to a lua-side callback

type LuaScript

type LuaScript struct {
	Robot *Robot
	State *lua.LState
}

Each LuaScript represents a single lua script/state machine

type Robot

type Robot struct {
	ID int
}

func (*Robot) GetID

func (r *Robot) GetID() int

func (Robot) Hear

func (r Robot) Hear(pat string, lfunc lua.LValue)

lua function to overhear a message

func (Robot) Respond

func (r Robot) Respond(pat string, lfunc lua.LValue)

lua function to process a command

Jump to

Keyboard shortcuts

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