Exemple #1
0
func main() {
	flag.Usage = func() {
		program := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
		fmt.Println("Usage: " + program + " [-i | -h] config.json")
		flag.PrintDefaults()
	}

	if len(os.Args) < 2 {
		flag.Usage()
		os.Exit(1)
	}

	flag.Parse()

	confarg := 1
	if *i {
		confarg = 2
	}
	rconf, err := rbot.ReadConfigFile(os.Args[confarg])
	if err != nil {
		panic(err)
	}

	var (
		preConnectMsg, postConnectMsg string
		bot                           *rbot.Bot
	)

	if *i {
		preConnectMsg, postConnectMsg = "", ""
		bot = cbot.NewCLIBot(rconf)
	} else {
		preConnectMsg, postConnectMsg = "Connecting... ", "Done"
		bot = rbot.NewBot(rain.Version(), rconf)
	}

	setup.Default(bot)
	bot.EnableModules()
	bot.DefaultConnectWithMsg(preConnectMsg, postConnectMsg)

	reason, err := bot.WaitForQuit()

	if err != nil {
		fmt.Printf("Quit Error: %s\n", reason)
		os.Exit(1)
	}

	fmt.Printf("Quit: %s\n", reason)
}
Exemple #2
0
// Default is the default setup for listeners on the bot. It includes the module manager command,
// a privmsg listener to parse commands, and common irc housekeeping listeners (Join, kick, etc).
func Default(b *rbot.Bot) {
	mm := ModuleManager{b}
	l := Listeners{b}

	b.Handler.AddInternalCommand("m", mm.GetCommand())

	b.AddListener(irc.RPL_TOPIC, l.RplTopic)
	b.AddListener(irc.RPL_NAMREPLY, l.RplNamreply)

	b.AddListener(irc.PRIVMSG, l.Privmsg)
	b.AddListener(irc.JOIN, l.Join)
	b.AddListener(irc.KICK, l.Kick)
	b.AddListener(irc.KILL, l.Kill)
	b.AddListener(irc.PART, l.Part)
	b.AddListener(irc.QUIT, l.Quit)
	b.AddListener(irc.NICK, l.Nick)

	b.AddListener(irc.ERR_NICKNAMEINUSE, l.ErrNicknameInUse)
}