HalHandlers

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

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

Go to latest
Published: Jan 12, 2015 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChoreTest = &hal.Chore{
	Name:  `test-chore`,
	Sched: `0 * * * * * *`,
	Room:  `C031P7M3E`,
	Run: func(res *hal.Response) error {
		return res.Send(`successful test!`)
	},
}
View Source
var Gifme = &hal.Handler{
	Method:  hal.RESPOND,
	Pattern: `gif me (.*)`,
	Usage:   `*Gifme*: botname gif me freddie mercury: returns a random rated:PG gif of freddy mercury via the giphy API`,
	Run: func(res *hal.Response) error {

		search := res.Match[1]
		q := url.QueryEscape(search)
		myurl := fmt.Sprintf("http://api.giphy.com/v1/gifs/random?rating=pg&api_key=dc6zaTOxFJmzC&tag=%s", q)
		hal.Logger.Debug(`myurl is`, myurl)
		g := new(gifyout)
		resp, _ := http.Get(myurl)
		dec := json.NewDecoder(resp.Body)
		dec.Decode(g)
		return res.Send(g.Data.Image_url)
	},
}
View Source
var Help = &hal.Handler{
	Method:  hal.RESPOND,
	Pattern: `help`,
	Usage:   `*help*: prints this message when you type "botname help"`,
	Run: func(res *hal.Response) error {
		var reply string
		handlers := res.Robot.Handlers()
		HandlerType := reflect.ValueOf(new(hal.Handler)).Elem()

		for _, h := range handlers {
			hval := reflect.ValueOf(h).Elem()
			hal.Logger.Debug("this hval is a ", hval.Type())
			if hval.Type() == HandlerType.Type() {
				usage := hval.FieldByName(`Usage`)
				reply = fmt.Sprintf("%s\n%s", reply, usage)
			}
		}
		return res.Send(reply)
	},
}
View Source
var IKR = &ikr{}

Ping exports

View Source
var ListChores = &hal.Handler{
	Method:  hal.RESPOND,
	Pattern: `(list chores)|(chore list)`,
	Usage:   `*Chores/ListChores*: botname (list chores)|(chore list): lists all registered chores`,
	Run: func(res *hal.Response) error {
		var reply string
		if len(res.Robot.Chores) == 0 {
			reply = `No chores have been registered (sorry?)`
		} else {
			reply = `Name  :small_blue_diamond:  Schedule  :small_blue_diamond:  Firing in  :small_blue_diamond: Current State`
			for _, c := range res.Robot.Chores {
				reply = fmt.Sprintf("%s\n%s:small_blue_diamond:%s:small_blue_diamond:%v:small_blue_diamond:%s", reply, c.Name, c.Sched, c.Next.Sub(time.Now()), c.State)
			}
		}
		return res.Reply(reply)
	},
}
View Source
var ListRooms = &hal.Handler{
	Method:  hal.RESPOND,
	Usage:   `*Chores/ListRooms*: botname (what room)|(list *room)|(room *list): prints the Name of the current chatroom`,
	Pattern: `(what room)|(list *room)|(room *list)`,
	Run: func(res *hal.Response) error {
		room := res.Message.Room
		reply := fmt.Sprintf("Current room is: %s", room)
		return res.Send(reply)
	},
}
View Source
var LoveAndWar = &hal.Handler{
	Method:  hal.RESPOND,
	Usage:   `*LoveAndWar*: botname (love|insult) <noun>: bot replies with a compliment or insult respectively ** Warning this plugin uses external API's and may return NSFW responses**`,
	Pattern: `(love|insult) (@*\w+)`,
	Run: func(res *hal.Response) error {
		act := res.Match[1]
		user := res.Match[2]
		if user == `me` {
			user = res.Envelope.User.Name
		}
		now := time.Now()
		rand.Seed(int64(now.Unix()))

		var reply string
		if act == `love` {
			reply = makeLove(user)
		} else if act == `insult` {
			reply = makeWar(user)
		}
		return res.Send(reply)
	},
}
View Source
var ManageChores = &hal.Handler{
	Method:  hal.RESPOND,
	Usage:   `*Chores/ManageChores*: botname (start|stop) chore [chorename]: stops or starts the named chore`,
	Pattern: `(start|stop) chore (.*)`,
	Run: func(res *hal.Response) error {
		var reply string
		act := res.Match[1]
		cname := res.Match[2]
		c := hal.GetChoreByName(cname, res.Robot)
		if c == nil {
			reply = fmt.Sprintf("Chore not found: %s", (cname[3]))
		} else {
			if act == `stop ` {
				hal.KillChore(c)
			} else {
				hal.StartChore(c)
			}
			reply = fmt.Sprintf("%s\n%s:small_blue_diamond:%s:small_blue_diamond:%v:small_blue_diamond:%s", reply, c.Name, c.Sched, c.Next.Sub(time.Now()), c.State)
		}
		return res.Reply(reply)
	},
}
View Source
var Quantifyme = &hal.Handler{
	Method:  hal.RESPOND,
	Pattern: `quantify (\S+)`,
	Usage:   `*Quantifyme*: botname quantify <noun>: replies with a randomly generated quantification of funny but probably NSFW personal attributes like 'mads', 'fucks', horribleness and passive-aggresivity`,
	Run: func(res *hal.Response) error {
		user := res.Match[1]
		if user == `me` {
			user = `you`
		}
		now := time.Now()
		rand.Seed(int64(now.Unix()))
		states := []string{`passive aggressive`, `mads`, `fucks`, `horrible`}
		state := states[rand.Intn(len(states)-1)]
		var reply string
		switch state {
		case `horrible`, `passive aggressive`:
			if user == `you` {
				reply = fmt.Sprintf(`%s are currently %%%d.%04d %s`, user, rand.Intn(int(100)), rand.Intn(int(1000)), state)
			} else {
				reply = fmt.Sprintf(`%s is currently %%%d.%04d %s`, user, rand.Intn(int(100)), rand.Intn(int(1000)), state)
			}
		case `mads`:
			if user == `you` {
				reply = fmt.Sprintf(`%s are %d.%04d %s`, user, rand.Intn(int(4)), rand.Intn(int(1000)), state)
			} else {
				reply = fmt.Sprintf(`%s is %d.%04d %s`, user, rand.Intn(int(4)), rand.Intn(int(1000)), state)
			}
		case `fucks`:
			if user == `you` {
				reply = fmt.Sprintf(`%s give precisely %f %s`, user, rand.Float64(), state)
			} else {
				reply = fmt.Sprintf(`%s gives precisely %f %s`, user, rand.Float64(), state)
			}
		}

		return res.Reply(reply)
	},
}
View Source
var Syn = &hal.Handler{
	Method:  hal.RESPOND,
	Usage:   `*Syn*: bothaname syn: responds with an 'ack'`,
	Pattern: `syn`,
	Run: func(res *hal.Response) error {
		return res.Reply(`ack`)
	},
}
View Source
var Tableflip = &hal.Handler{
	Method:  hal.HEAR,
	Usage:   `*tableflip*: bot overhears the pattern: (table)*flip(table)* and responds by flipping a unicode table`,
	Pattern: `(table)*flip(table)*`,
	Run: func(res *hal.Response) error {
		return res.Send(`(╯°□°)╯︵ ┻━┻`)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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