Example #1
0
func main() {
	var err error
	defer func() {
		if x := recover(); x != nil {
			fmt.Fprintf(os.Stderr, "Fatal error: %s\nExiting.", x)
			os.Exit(1)
		}
	}()

	confFile := flag.String("c", "./mcbot.conf", "The location of the configuration file to be used.")
	flag.Parse()

	if config, err = ReadConfig(*confFile); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
	}

	if bot, err = ircbot.NewBot(config.Nick, config.Pass, config.IrcDomain, config.IrcServer, config.IrcPort,
		config.SSL, config.AttnChar[0]); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
	}

	if server, err = mcserver.NewServer(config.MCServerCommand.Command, config.MCServerCommand.Args,
		config.MCServerDir, logInfo, logErr); err != nil {
		fmt.Fprintf(os.Stderr, "%s\n", err)
	}

	go commandDispatch()
	go readConsoleInput()
	go teeServerOutput()
	bot.SetPrivmsgHandler(directedIRC, echoIRCToServer)
	bot.JoinChannel(config.IrcChan, config.IrcChanKey)

	select {}
}
Example #2
0
func main() {
	var err error

	//Create a new bot
	bot, err = irc.NewBot(
		"goirc-bot",         //The bot's nick
		"",                  //The bot's nickserv password (blank for none)
		"www.github.com",    //The bot's domain
		"chat.freenode.org", //IRC server to connect to
		7070,                //Remote port to connect on
		true,                //Use ssl?
		'!',                 //Char used to address the bot
	)

	if err != nil {
		fmt.Println(err)
		return
	}

	//Control how the bot will react to various IRC commands using the bot's
	//Actions map.  By default the only thing the bot will do is respond to PING
	//requests.  Functions must have the signature:
	// `func(bot *irc.Bot, msg *irc.Message) *irc.Message`
	bot.Actions["INVITE"] = join

	//PRIVMSG can be handled as above, or you can use the convenience method below.
	//It accepts two functions, the first will be called for messages directed
	//to the bot via its attention char, addressing it by name, or by sending it a
	//private message.  The second will be called for all other messages
	bot.SetPrivmsgHandler(sayHi, ctcpEcho)

	//Attempt to join the given channel, here we're joining an unkeyed channel.
	bot.JoinChannel("#echo", "")

	//No further work to be done in main, block indefinitely
	select {}
}