discord.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /******************************************************************************
  2. * Discordgo v0 by Bruce Marriner <bruce@sqls.net>
  3. * A DiscordApp API for Golang.
  4. *
  5. * Currently only the REST API is functional. I will add on the websocket
  6. * layer once I get the API section where I want it.
  7. *
  8. */
  9. package discordgo
  10. // Define known API URL paths as global constants
  11. const (
  12. discordUrl = "http://discordapp.com"
  13. discordApi = discordUrl + "/api/"
  14. servers = discordApi + "guilds"
  15. channels = discordApi + "channels"
  16. users = discordApi + "users"
  17. )
  18. // possible all-inclusive strut..
  19. type Discord struct {
  20. Session
  21. User User
  22. Servers []Server
  23. }
  24. // Create a new connection to Discord API. Returns a client session handle.
  25. // this is a all inclusive type of easy setup command that will return
  26. // a connection, user information, and available channels.
  27. // This is probably the most common way to use the library but you
  28. // can use the "manual" functions below instead.
  29. func New(email string, password string) (discord *Discord, err error) {
  30. session := Session{}
  31. session.Token, err = session.RequestToken(email, password)
  32. if err != nil {
  33. return
  34. }
  35. user, err := session.Self()
  36. if err != nil {
  37. return
  38. }
  39. servers, err := session.Servers()
  40. discord = &Discord{session, user, servers}
  41. return
  42. }