示例#1
0
文件: sed.go 项目: peted27/gherkin
func Register(c *irc.Connection) {
	c.AddCallback("PRIVMSG", lib.PrivmsgHandler(
		func(e *irc.Event) {
			handle(e)
		}, &lib.Command{
			Private: false,
			Direct:  false,
			Command: false,
			Line:    true,
		}))
}
示例#2
0
func main() {
	flag.Parse()

	bot := irc.IRC(*nick, *ident)

	//bot.VerboseCallbackHandler = *debug
	bot.Debug = *debug

	// using ssl? configure here
	if *ssl {
		bot.UseTLS = *ssl
		bot.TLSConfig = &tls.Config{InsecureSkipVerify: true}
	}

	// connect the bot
	if err := bot.Connect(*host); err != nil {
		bot.Log.Printf("Error: %s\n", err)
	}

	// setup callbacks to join managed channels
	for _, ch := range strings.Split(*channels, ",") {

		bot.AddCallback("001",
			func(e *irc.Event) {
				bot.Join(ch)
				bot.Log.Printf("bot: joining channel %s\n", ch)
			})

	}

	// pong! plugin
	bot.AddCallback("PRIVMSG", lib.PrivmsgHandler(
		func(e *irc.Event) {
			if strings.HasPrefix(e.Arguments[1], "!ping") {
				e.Connection.Privmsg(e.Arguments[0], "pong!")
			}
		}, &lib.Command{
			Private: false,
			Direct:  false,
			Command: true,
			Line:    false,
		}))

	// slap plugin
	bot.AddCallback("PRIVMSG", lib.PrivmsgHandler(
		func(e *irc.Event) {
			if strings.HasPrefix(e.Arguments[1], "!slap") {
				e.Connection.Action(e.Arguments[0], "slaps "+e.Nick+" around a bit with a large trout!")
			}
		}, &lib.Command{
			Private: false,
			Direct:  false,
			Command: true,
			Line:    false,
		}))

	urltitle.Register(bot)
	sed.Register(bot)

	bot.Loop()

}