structs.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. package discordgo
  2. import (
  3. "net"
  4. "golang.org/x/net/websocket"
  5. )
  6. // TODO: Eventually everything here gets moved to a better place.
  7. // A Message stores all data related to a specific Discord message.
  8. type Message struct {
  9. ID string `json:"id"`
  10. Author User `json:"author"`
  11. Content string `json:"content"`
  12. Attachments []Attachment `json:"attachments"`
  13. Tts bool `json:"tts"`
  14. Embeds []Embed `json:"embeds"`
  15. Timestamp string `json:"timestamp"`
  16. MentionEveryone bool `json:"mention_everyone"`
  17. EditedTimestamp string `json:"edited_timestamp"`
  18. Mentions []User `json:"mentions"`
  19. ChannelID string `json:"channel_id"`
  20. }
  21. // An Attachment stores data for message attachments.
  22. type Attachment struct { //TODO figure this out
  23. }
  24. // An Embed stores data for message embeds.
  25. type Embed struct { // TODO figure this out
  26. }
  27. // A VoiceRegion stores data for a specific voice region server.
  28. type VoiceRegion struct {
  29. ID string `json:"id"`
  30. Name string `json:"name"`
  31. Hostname string `json:"sample_hostname"`
  32. Port int `json:"sample_port"`
  33. }
  34. // A VoiceICE stores data for voice ICE servers.
  35. type VoiceICE struct {
  36. TTL string `json:"ttl"`
  37. Servers []ICEServer `json:"servers"`
  38. }
  39. // A ICEServer stores data for a specific voice ICE server.
  40. type ICEServer struct {
  41. URL string `json:"url"`
  42. Username string `json:"username"`
  43. Credential string `json:"credential"`
  44. }
  45. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  46. type Invite struct {
  47. MaxAge int `json:"max_age"`
  48. Code string `json:"code"`
  49. Guild Guild `json:"guild"`
  50. Revoked bool `json:"revoked"`
  51. CreatedAt string `json:"created_at"` // TODO make timestamp
  52. Temporary bool `json:"temporary"`
  53. Uses int `json:"uses"`
  54. MaxUses int `json:"max_uses"`
  55. Inviter User `json:"inviter"`
  56. XkcdPass bool `json:"xkcdpass"`
  57. Channel Channel `json:"channel"`
  58. }
  59. // A Channel holds all data related to an individual Discord channel.
  60. type Channel struct {
  61. ID string `json:"id"`
  62. GuildID string `json:"guild_id"`
  63. Name string `json:"name"`
  64. Topic string `json:"topic"`
  65. Position int `json:"position"`
  66. Type string `json:"type"`
  67. PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites"`
  68. IsPrivate bool `json:"is_private"`
  69. LastMessageID string `json:"last_message_id"`
  70. Recipient User `json:"recipient"`
  71. }
  72. // A PermissionOverwrite holds permission overwrite data for a Channel
  73. type PermissionOverwrite struct {
  74. ID string `json:"id"`
  75. Type string `json:"type"`
  76. Deny int `json:"deny"`
  77. Allow int `json:"allow"`
  78. }
  79. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  80. // sometimes referred to as Servers in the Discord client.
  81. type Guild struct {
  82. ID string `json:"id"`
  83. Name string `json:"name"`
  84. Icon string `json:"icon"`
  85. Region string `json:"region"`
  86. AfkTimeout int `json:"afk_timeout"`
  87. AfkChannelID string `json:"afk_channel_id"`
  88. EmbedChannelID string `json:"embed_channel_id"`
  89. EmbedEnabled bool `json:"embed_enabled"`
  90. OwnerID string `json:"owner_id"`
  91. Large bool `json:"large"` // ??
  92. JoinedAt string `json:"joined_at"` // make this a timestamp
  93. Roles []Role `json:"roles"`
  94. Members []Member `json:"members"`
  95. Presences []Presence `json:"presences"`
  96. Channels []Channel `json:"channels"`
  97. VoiceStates []VoiceState `json:"voice_states"`
  98. }
  99. // A Role stores information about Discord guild member roles.
  100. type Role struct {
  101. ID string `json:"id"`
  102. Name string `json:"name"`
  103. Managed bool `json:"managed"`
  104. Color int `json:"color"`
  105. Hoist bool `json:"hoist"`
  106. Position int `json:"position"`
  107. Permissions int `json:"permissions"`
  108. }
  109. // A VoiceState stores the voice states of Guilds
  110. type VoiceState struct {
  111. UserID string `json:"user_id"`
  112. Suppress bool `json:"suppress"`
  113. SessionID string `json:"session_id"`
  114. SelfMute bool `json:"self_mute"`
  115. SelfDeaf bool `json:"self_deaf"`
  116. Mute bool `json:"mute"`
  117. Deaf bool `json:"deaf"`
  118. ChannelID string `json:"channel_id"`
  119. }
  120. // A Presence stores the online, offline, or idle and game status of Guild members.
  121. type Presence struct {
  122. User User `json:"user"`
  123. Status string `json:"status"`
  124. GameID int `json:"game_id"`
  125. }
  126. // A Member stores user information for Guild members.
  127. type Member struct {
  128. GuildID string `json:"guild_id"`
  129. JoinedAt string `json:"joined_at"`
  130. Deaf bool `json:"deaf"`
  131. Mute bool `json:"mute"`
  132. User User `json:"user"`
  133. Roles []string `json:"roles"`
  134. }
  135. // A Session represents a connection to the Discord REST API.
  136. // token : The authentication token returned from Discord
  137. // Debug : If set to ture debug logging will be displayed.
  138. type Session struct {
  139. Token string // Authentication token for this session
  140. Debug bool // Debug for printing JSON request/responses
  141. Cache int // number in X to cache some responses
  142. SessionID string // from websocket READY packet
  143. // Settable Callback functions for Websocket Events
  144. OnEvent func(*Session, Event) // should Event be *Event?
  145. OnReady func(*Session, Ready)
  146. OnTypingStart func(*Session, TypingStart)
  147. OnMessageCreate func(*Session, Message)
  148. OnMessageUpdate func(*Session, Message)
  149. OnMessageDelete func(*Session, MessageDelete)
  150. OnMessageAck func(*Session, MessageAck)
  151. OnPresenceUpdate func(*Session, PresenceUpdate)
  152. OnVoiceStateUpdate func(*Session, VoiceState)
  153. OnChannelCreate func(*Session, Channel)
  154. OnChannelUpdate func(*Session, Channel)
  155. OnChannelDelete func(*Session, Channel)
  156. OnGuildCreate func(*Session, Guild)
  157. OnGuildUpdate func(*Session, Guild)
  158. OnGuildDelete func(*Session, Guild)
  159. OnGuildMemberAdd func(*Session, Member)
  160. OnGuildMemberRemove func(*Session, Member)
  161. OnGuildMemberDelete func(*Session, Member) // which is it?
  162. OnGuildMemberUpdate func(*Session, Member)
  163. OnGuildRoleCreate func(*Session, GuildRole)
  164. OnGuildRoleUpdate func(*Session, GuildRole)
  165. OnGuildRoleDelete func(*Session, GuildRoleDelete)
  166. OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
  167. wsConn *websocket.Conn
  168. //TODO, add bools for like.
  169. // are we connnected to websocket?
  170. // have we authenticated to login?
  171. // lets put all the general session
  172. // tracking and infos here.. clearly
  173. // Everything below here is used for Voice testing.
  174. // This stuff is almost guarenteed to change a lot
  175. // and is even a bit hackish right now.
  176. VwsConn *websocket.Conn // new for voice
  177. VSessionID string
  178. VToken string
  179. VEndpoint string
  180. VGuildID string
  181. VChannelID string
  182. Vop2 VoiceOP2
  183. UDPConn *net.UDPConn
  184. }
  185. // A User stores all data for an individual Discord user.
  186. type User struct {
  187. ID string `json:"id"`
  188. Email string `json:"email"`
  189. Username string `json:"username"`
  190. Avatar string `json:"Avatar"`
  191. Verified bool `json:"verified"`
  192. //Discriminator int `json:"discriminator,string"` // TODO: See below
  193. }
  194. // Discriminator sometimes comes as a string
  195. // and sometimes it comes as a int. Weird.
  196. // to avoid errors I've just commented it out
  197. // but it doesn't seem to just kill the whole
  198. // program. Heartbeat is taken on READY even
  199. // with error and the system continues to read
  200. // it just doesn't seem able to handle this one
  201. // field correctly. Need to research this more.
  202. // A PrivateChannel stores all data for a specific user private channel.
  203. type PrivateChannel struct {
  204. ID string `json:"id"`
  205. IsPrivate bool `json:"is_private"`
  206. LastMessageID string `json:"last_message_id"`
  207. Recipient User `json:"recipient"`
  208. } // merge with channel?
  209. // A Settings stores data for a specific users Discord client settings.
  210. type Settings struct {
  211. RenderEmbeds bool `json:"render_embeds"`
  212. InlineEmbedMedia bool `json:"inline_embed_media"`
  213. EnableTtsCommand bool `json:"enable_tts_command"`
  214. MessageDisplayCompact bool `json:"message_display_compact"`
  215. Locale string `json:"locale"`
  216. ShowCurrentGame bool `json:"show_current_game"`
  217. Theme string `json:"theme"`
  218. MutedChannels []string `json:"muted_channels"`
  219. }
  220. // An Event provides a basic initial struct for all websocket event.
  221. type Event struct {
  222. Type string `json:"t"`
  223. State int `json:"s"`
  224. Operation int `json:"o"`
  225. Direction int `json:"dir"`
  226. RawData json.RawMessage `json:"d"`
  227. }
  228. // A Ready stores all data for the websocket READY event.
  229. type Ready struct {
  230. Version int `json:"v"`
  231. SessionID string `json:"session_id"`
  232. HeartbeatInterval time.Duration `json:"heartbeat_interval"`
  233. User User `json:"user"`
  234. ReadState []ReadState
  235. PrivateChannels []PrivateChannel
  236. Guilds []Guild
  237. }
  238. // ReadState might need to move? Gives me the read status
  239. // of all my channels when first connecting. I think :)
  240. // A ReadState stores data on the read state of channels.
  241. type ReadState struct {
  242. MentionCount int
  243. LastMessageID string `json:"last_message_id"`
  244. ID string `json:"id"`
  245. }
  246. // A TypingStart stores data for the typing start websocket event.
  247. type TypingStart struct {
  248. UserID string `json:"user_id"`
  249. ChannelID string `json:"channel_id"`
  250. Timestamp int `json:"timestamp"`
  251. }
  252. // A PresenceUpdate stores data for the pressence update websocket event.
  253. type PresenceUpdate struct {
  254. User User `json:"user"`
  255. Status string `json:"status"`
  256. Roles []string `json:"roles"`
  257. GuildID string `json:"guild_id"`
  258. GameID int `json:"game_id"`
  259. }
  260. // A MessageAck stores data for the message ack websocket event.
  261. type MessageAck struct {
  262. MessageID string `json:"message_id"`
  263. ChannelID string `json:"channel_id"`
  264. }
  265. // A MessageDelete stores data for the message delete websocket event.
  266. type MessageDelete struct {
  267. ID string `json:"id"`
  268. ChannelID string `json:"channel_id"`
  269. } // so much like MessageAck..
  270. // A GuildIntegrationsUpdate stores data for the guild integrations update
  271. // websocket event.
  272. type GuildIntegrationsUpdate struct {
  273. GuildID string `json:"guild_id"`
  274. }
  275. // A GuildRole stores data for guild role websocket events.
  276. type GuildRole struct {
  277. Role Role `json:"role"`
  278. GuildID string `json:"guild_id"`
  279. }
  280. // A GuildRoleDelete stores data for the guild role delete websocket event.
  281. type GuildRoleDelete struct {
  282. RoleID string `json:"role_id"`
  283. GuildID string `json:"guild_id"`
  284. }