session.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /******************************************************************************
  2. * A Discord API for Golang.
  3. *
  4. * This file has structs and functions specific to a session.
  5. *
  6. * A session is a single connection to Discord for a given
  7. * user and all REST and Websock API functions exist within
  8. * a session.
  9. *
  10. * See the restapi.go and wsapi.go for more information.
  11. */
  12. package discordgo
  13. import (
  14. "net"
  15. "github.com/gorilla/websocket"
  16. )
  17. // A Session represents a connection to the Discord REST API.
  18. // token : The authentication token returned from Discord
  19. // Debug : If set to ture debug logging will be displayed.
  20. type Session struct {
  21. Token string // Authentication token for this session
  22. Debug bool // Debug for printing JSON request/responses
  23. Cache int // number in X to cache some responses
  24. SessionID string // from websocket READY packet
  25. // Settable Callback functions for Websocket Events
  26. OnEvent func(*Session, Event) // should Event be *Event?
  27. OnReady func(*Session, Ready)
  28. OnTypingStart func(*Session, TypingStart)
  29. OnMessageCreate func(*Session, Message)
  30. OnMessageUpdate func(*Session, Message)
  31. OnMessageDelete func(*Session, MessageDelete)
  32. OnMessageAck func(*Session, MessageAck)
  33. OnPresenceUpdate func(*Session, PresenceUpdate)
  34. OnVoiceStateUpdate func(*Session, VoiceState)
  35. OnChannelCreate func(*Session, Channel)
  36. OnChannelUpdate func(*Session, Channel)
  37. OnChannelDelete func(*Session, Channel)
  38. OnGuildCreate func(*Session, Guild)
  39. OnGuildUpdate func(*Session, Guild)
  40. OnGuildDelete func(*Session, Guild)
  41. OnGuildMemberAdd func(*Session, Member)
  42. OnGuildMemberRemove func(*Session, Member)
  43. OnGuildMemberDelete func(*Session, Member) // which is it?
  44. OnGuildMemberUpdate func(*Session, Member)
  45. OnGuildRoleCreate func(*Session, GuildRole)
  46. OnGuildRoleUpdate func(*Session, GuildRole)
  47. OnGuildRoleDelete func(*Session, GuildRoleDelete)
  48. OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
  49. wsConn *websocket.Conn
  50. //TODO, add bools for like.
  51. // are we connnected to websocket?
  52. // have we authenticated to login?
  53. // lets put all the general session
  54. // tracking and infos here.. clearly
  55. // Everything below here is used for Voice testing.
  56. // This stuff is almost guarenteed to change a lot
  57. // and is even a bit hackish right now.
  58. VwsConn *websocket.Conn // new for voice
  59. VSessionID string
  60. VToken string
  61. VEndpoint string
  62. VGuildID string
  63. VChannelID string
  64. Vop2 VoiceOP2
  65. UDPConn *net.UDPConn
  66. }