//LoadBot creates bot instance from config file.
LoadBot creates bot instance from config file.
// LoadBot creates bot instance from config file .
func LoadBot(path string, verbose bool) Hitbot {
	raw := new(bytes.Buffer)
	f, err := os.Open(path)
	if err != nil {
		log.Fatalf("Fatal error while opening config: %v", err)
	}
	_, err = raw.ReadFrom(f)
	if err != nil {
		log.Fatalf("Fatal error while reading config: %v", err)
	}
	var c config
	if err := json.Unmarshal(raw.Bytes(), &c); err != nil {
		log.Fatalf("Fatal error while processing config: %v", err)
	}
	bot := NewBot(c.Name)
	bot.Verbose(verbose)
	bot.GetServers()
	bot.GetID()
	bot.Auth(c.Pass)
	bot.RegisterBuiltinHandlers()
	channels := make([]string, 64)
	for _, channel := range c.Channels {
		channels = append(channels, channel.Name)
		bot.chCmds[channel.Name] = chCmd{cmds: make(map[string]HandlerFunc), cmdHandlers: make(map[string]cmd)}
		for _, comm := range channel.Commands {
			bot.chCmds[channel.Name].cmdHandlers[comm.Name] = cmd{Handler: comm.Handler, Role: comm.Role, Data: comm.Data}
		}
	}
	for _, comm := range c.Commands {
		bot.cmdHandlers[comm.Name] = cmd{Handler: comm.Handler, Role: comm.Role, Data: comm.Data}
	}
	bot.Connect(channels...)
	bot.NameColor(c.NameColor)
	return bot
}
func LoadBot ( path string , verbose bool ) Hitbot { raw := new ( bytes . Buffer ) f , err := os . Open ( path ) if err != nil { log . Fatalf ( " " , err ) } _ , err = raw . ReadFrom ( f ) if err != nil { log . Fatalf ( " " , err ) } var c config if err := json . Unmarshal ( raw . Bytes ( ) , & c ) ; err != nil { log . Fatalf ( " " , err ) } bot := NewBot ( c . Name ) bot . Verbose ( verbose ) bot . GetServers ( ) bot . GetID ( ) bot . Auth ( c . Pass ) bot . RegisterBuiltinHandlers ( ) channels := make ( [ ] string , 64 ) for _ , channel := range c . Channels { channels = append ( channels , channel . Name ) bot . chCmds [ channel . Name ] = chCmd { cmds : make ( map [ string ] HandlerFunc ) , cmdHandlers : make ( map [ string ] cmd ) } for _ , comm := range channel . Commands { bot . chCmds [ channel . Name ] . cmdHandlers [ comm . Name ] = cmd { Handler : comm . Handler , Role : comm . Role , Data : comm . Data } } } for _ , comm := range c . Commands { bot . cmdHandlers [ comm . Name ] = cmd { Handler : comm . Handler , Role : comm . Role , Data : comm . Data } } bot . Connect ( channels ... ) bot . NameColor ( c . NameColor ) return bot }
LoadBot creates bot instance from config file.
LoadBot creates bot instance from config file .