func NewSession(conf *Config) (Session, error) {

	// ensure valid api version
	if conf.APIVersion == 0 {
		conf.APIVersion = 6 // the current discord API, for now v6
	}
	switch conf.APIVersion { // todo: simplify
	case 1:
		fallthrough
	case 2:
		fallthrough
	case 3:
		fallthrough
	case 4:
		fallthrough
	case 5:
		return nil, errors.New("outdated API version")
	case 6: // supported
	default:
		return nil, errors.New("Discord API version is not yet supported")
	}

	if conf.HTTPClient == nil {
		// http client configuration
		conf.HTTPClient = &http.Client{
			Timeout: time.Second * 10,
		}
	}

	// Use websocket to keep the socket connection going
	// default communication encoding to json
	if conf.APIEncoding == "" {
		conf.APIEncoding = JSONEncoding
	}
	if conf.ProjectName == "" {
		conf.ProjectName = LibraryInfo()
	}
	dws, err := websocket.NewClient(&websocket.Config{
		// user settings
		Token:      conf.Token,
		HTTPClient: conf.HTTPClient,
		Debug:      conf.Debug,

		// identity
		Browser:             LibraryInfo(),
		Device:              conf.ProjectName,
		GuildLargeThreshold: 250, // TODO: config

		// lib specific
		DAPIVersion:   conf.APIVersion,
		DAPIEncoding:  conf.APIEncoding,
		ChannelBuffer: 1,
	})
	if err != nil {
		return nil, err
	}

	// request client
	reqConf := &httd.Config{
		APIVersion:                   conf.APIVersion,
		BotToken:                     conf.Token,
		UserAgentSourceURL:           GitHubURL,
		UserAgentVersion:             constant.Version,
		HTTPClient:                   conf.HTTPClient,
		CancelRequestWhenRateLimited: conf.CancelRequestWhenRateLimited,
	}
	reqClient := httd.NewClient(reqConf)

	// event dispatcher
	evtDispatcher := NewDispatch(dws)

	// create a disgord client/instance/session
	c := &Client{
		config:        conf,
		httpClient:    conf.HTTPClient,
		ws:            dws,
		socketEvtChan: dws.DiscordWSEventChan(),
		token:         conf.Token,
		evtDispatch:   evtDispatcher,
		state:         NewCache(),
		req:           reqClient,
	}

	return c, nil
}
// NewSession create a client and return the Session interface
NewSession create a client and return the Session interface
// NewSession create a client and return the Session interface
func NewSession(conf *Config) (Session, error) {
	if conf.APIVersion == 0 {
		conf.APIVersion = 6 
	}
	switch conf.APIVersion { 
	case 1:
		fallthrough
	case 2:
		fallthrough
	case 3:
		fallthrough
	case 4:
		fallthrough
	case 5:
		return nil, errors.New("outdated API version")
	case 6: 
	default:
		return nil, errors.New("Discord API version is not yet supported")
	}
	if conf.HTTPClient == nil {
		conf.HTTPClient = &http.Client{
			Timeout: time.Second * 10,
		}
	}
	if conf.APIEncoding == "" {
		conf.APIEncoding = JSONEncoding
	}
	if conf.ProjectName == "" {
		conf.ProjectName = LibraryInfo()
	}
	dws, err := websocket.NewClient(&websocket.Config{
		Token:      conf.Token,
		HTTPClient: conf.HTTPClient,
		Debug:      conf.Debug,
		Browser:             LibraryInfo(),
		Device:              conf.ProjectName,
		GuildLargeThreshold: 250, 
		DAPIVersion:   conf.APIVersion,
		DAPIEncoding:  conf.APIEncoding,
		ChannelBuffer: 1,
	})
	if err != nil {
		return nil, err
	}
	reqConf := &httd.Config{
		APIVersion:                   conf.APIVersion,
		BotToken:                     conf.Token,
		UserAgentSourceURL:           GitHubURL,
		UserAgentVersion:             constant.Version,
		HTTPClient:                   conf.HTTPClient,
		CancelRequestWhenRateLimited: conf.CancelRequestWhenRateLimited,
	}
	reqClient := httd.NewClient(reqConf)
	evtDispatcher := NewDispatch(dws)
	c := &Client{
		config:        conf,
		httpClient:    conf.HTTPClient,
		ws:            dws,
		socketEvtChan: dws.DiscordWSEventChan(),
		token:         conf.Token,
		evtDispatch:   evtDispatcher,
		state:         NewCache(),
		req:           reqClient,
	}
	return c, nil
}
func NewSession ( conf * Config ) ( Session , error ) { if conf . APIVersion == 0 { conf . APIVersion = 6 } switch conf . APIVersion { case 1 : fallthrough case 2 : fallthrough case 3 : fallthrough case 4 : fallthrough case 5 : return nil , errors . New ( " " ) case 6 : default : return nil , errors . New ( " " ) } if conf . HTTPClient == nil { conf . HTTPClient = & http . Client { Timeout : time . Second * 10 , } } if conf . APIEncoding == " " { conf . APIEncoding = JSONEncoding } if conf . ProjectName == " " { conf . ProjectName = LibraryInfo ( ) } dws , err := websocket . NewClient ( & websocket . Config { Token : conf . Token , HTTPClient : conf . HTTPClient , Debug : conf . Debug , Browser : LibraryInfo ( ) , Device : conf . ProjectName , GuildLargeThreshold : 250 , DAPIVersion : conf . APIVersion , DAPIEncoding : conf . APIEncoding , ChannelBuffer : 1 , } ) if err != nil { return nil , err } reqConf := & httd . Config { APIVersion : conf . APIVersion , BotToken : conf . Token , UserAgentSourceURL : GitHubURL , UserAgentVersion : constant . Version , HTTPClient : conf . HTTPClient , CancelRequestWhenRateLimited : conf . CancelRequestWhenRateLimited , } reqClient := httd . NewClient ( reqConf ) evtDispatcher := NewDispatch ( dws ) c := & Client { config : conf , httpClient : conf . HTTPClient , ws : dws , socketEvtChan : dws . DiscordWSEventChan ( ) , token : conf . Token , evtDispatch : evtDispatcher , state : NewCache ( ) , req : reqClient , } return c , nil }
NewSession create a client and return the Session interface
NewSession create a client and return the Session interface
// ensure valid api version // the current discord API, for now v6 // todo: simplify // supported // http client configuration // Use websocket to keep the socket connection going // default communication encoding to json // user settings // identity // TODO: config // lib specific // request client // event dispatcher // create a disgord client/instance/session