Esempio n. 1
0
func createIRCHandler(cfg config.ConfigStruct) *irc.Client {
	conn, err := net.Dial("tcp", createServerPort(cfg))
	if err != nil {
		panic("Failed to connect to remote IRC server")
	}

	ircConfig := irc.ClientConfig{
		Nick:    (*cfg.IRCCfg).Nick,
		Pass:    (*cfg.IRCCfg).Pass,
		User:    (*cfg.IRCCfg).Nick,
		Name:    (*cfg.IRCCfg).Nick,
		Handler: irc.HandlerFunc(ircHandler),
	}

	client := irc.NewClient(conn, ircConfig)
	go func() {
		err = client.Run()
		if err != nil {
			log.Panicf("%v", err)
			panic("Failed to start IRC client.")
		}
	}()

	return client
}
Esempio n. 2
0
func main() {
	handler := irc.NewBasicMux()

	client := irc.NewClient(irc.HandlerFunc(handler.HandleEvent), *nick, *user, "SplatBot by Xena", "")

	handler.Event("001", func(c *irc.Client, e *irc.Event) {
		c.Writef("MODE %s +B", c.CurrentNick())
		c.Writef("JOIN %s", *channels)
	})

	handler.Event("PRIVMSG", handlePrivmsg)

	var err error

	if *ssl {
		err = client.DialTLS(fmt.Sprintf("%s:%d", *server, *port), nil)
	} else {
		err = client.Dial(fmt.Sprintf("%s:%d", *server, *port))
	}
	if err != nil {
		panic(err)
	}
}