コード例 #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
ファイル: gherkin.go プロジェクト: peted27/gherkin
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()

}