コード例 #1
0
ファイル: handlers.go プロジェクト: b33f/sp0rkle
// NOTE: Nothing but the bot should register for IRC events!
func (bot *Sp0rkle) RegisterHandlers(r event.EventRegistry) {
	// Generic shim to wrap an irc event into a bot event.
	forward_event := func(name string) event.Handler {
		return client.NewHandler(func(irc *client.Conn, line *client.Line) {
			getState(irc).Dispatch("bot_"+name, &base.Line{Line: *line.Copy()})
		})
	}

	r.AddHandler(client.NewHandler(bot_connected), "connected")
	r.AddHandler(client.NewHandler(bot_disconnected), "disconnected")
	r.AddHandler(client.NewHandler(bot_privmsg), "privmsg")
	r.AddHandler(forward_event("action"), "action")
	// These are mostly for the seen plugin.
	r.AddHandler(forward_event("join"), "join")
	r.AddHandler(forward_event("part"), "part")
	r.AddHandler(forward_event("kick"), "kick")
	r.AddHandler(forward_event("quit"), "quit")
	r.AddHandler(forward_event("nick"), "nick")

	// This is a special handler that triggers a rebuild and re-exec
	r.AddHandler(client.NewHandler(bot_rebuild), "notice")
	// This is a special handler that triggers a shutdown and disconnect
	r.AddHandler(client.NewHandler(bot_shutdown), "notice")
}
コード例 #2
0
ファイル: bot.go プロジェクト: pzsz/sp0rkle
func Handle(h base.Handler, event ...string) {
	// TODO(fluffle): push CommandSet way of doing things down into goirc
	irc.ER.AddHandler(client.NewHandler(func(_ *client.Conn, l *client.Line) {
		h.Execute(transformLine(l))
	}), event...)
}