session.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /******************************************************************************
  2. * A Discord API for Golang.
  3. */
  4. package discordgo
  5. import "github.com/gorilla/websocket"
  6. // A Session represents a connection to the Discord REST API.
  7. // Token : The authentication token returned from Discord
  8. // Debug : If set to ture debug logging will be displayed.
  9. type Session struct {
  10. Token string // Authentication token for this session
  11. Gateway string // Websocket Gateway for this session
  12. Debug bool // Debug for printing JSON request/responses
  13. Cache int // number in X to cache some responses
  14. Websocket *websocket.Conn // TODO: use this
  15. //TODO, add bools for like.
  16. // are we connnected to websocket?
  17. // have we authenticated to login?
  18. // lets put all the general session
  19. // tracking and infos here.. clearly
  20. }
  21. /******************************************************************************
  22. * The below functions are "shortcut" methods for functions in restapi.go
  23. * Reference the client.go file for more documentation.
  24. */
  25. func (session *Session) Login(email string, password string) (token string, err error) {
  26. token, err = Login(session, email, password)
  27. return
  28. }
  29. func (session *Session) Self() (user User, err error) {
  30. user, err = Users(session, "@me")
  31. return
  32. }
  33. func (session *Session) PrivateChannels() (channels []Channel, err error) {
  34. channels, err = PrivateChannels(session, "@me")
  35. return
  36. }
  37. func (session *Session) Servers() (servers []Server, err error) {
  38. servers, err = Servers(session, "@me")
  39. return
  40. }
  41. // Logout ends a session and logs out from the Discord REST API.
  42. func (session *Session) Logout() (err error) {
  43. err = Logout(session)
  44. return
  45. }