discord.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /******************************************************************************
  2. * A Discord API for Golang.
  3. *
  4. * Currently only the REST API is functional. I will add on the websocket
  5. * layer once I get the API section where I want it.
  6. *
  7. * The idea is that this file is where we pull together the wsapi, and
  8. * restapi to create a single do-it-all struct
  9. *
  10. * NOTE!!! Currently this file has no purpose, it is here for future
  11. * access methods. EVERYTHING HERE will just go away or be changed
  12. * substantially in the future.
  13. */
  14. package discordgo
  15. // A Discord structure represents a all-inclusive (hopefully) structure to
  16. // access the Discord REST API for a given authenticated user.
  17. type Discord struct {
  18. Session *Session
  19. User User
  20. Servers []Server
  21. }
  22. // New creates a new connection to Discord and returns a Discord structure.
  23. // This provides an easy entry where most commonly needed information is
  24. // automatically fetched.
  25. // TODO add websocket code in here too
  26. func New(email string, password string) (d *Discord, err error) {
  27. session := Session{}
  28. session.Token, err = session.Login(email, password)
  29. if err != nil {
  30. return
  31. }
  32. user, err := session.Self()
  33. if err != nil {
  34. return
  35. }
  36. servers, err := session.Servers()
  37. d = &Discord{session, user, servers}
  38. return
  39. }
  40. // Renew essentially reruns the New command without creating a new session.
  41. // This will update all the user, server, and channel information that was
  42. // fetched with the New command. This is not an efficient way of doing this
  43. // but if used infrequently it does provide convenience.
  44. func (d *Discord) Renew() (err error) {
  45. d.User, err = Users(&d.Session, "@me")
  46. d.Servers, err = Servers(&d.Session, "@me")
  47. return
  48. }