events.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. package discordgo
  2. import (
  3. "encoding/json"
  4. )
  5. // This file contains all the possible structs that can be
  6. // handled by AddHandler/EventHandler.
  7. // DO NOT ADD ANYTHING BUT EVENT HANDLER STRUCTS TO THIS FILE.
  8. //go:generate go run tools/cmd/eventhandlers/main.go
  9. // Connect is the data for a Connect event.
  10. // This is a synthetic event and is not dispatched by Discord.
  11. type Connect struct{}
  12. // Disconnect is the data for a Disconnect event.
  13. // This is a synthetic event and is not dispatched by Discord.
  14. type Disconnect struct{}
  15. // RateLimit is the data for a RateLimit event.
  16. // This is a synthetic event and is not dispatched by Discord.
  17. type RateLimit struct {
  18. *TooManyRequests
  19. URL string
  20. }
  21. // Event provides a basic initial struct for all websocket events.
  22. type Event struct {
  23. Operation int `json:"op"`
  24. Sequence int64 `json:"s"`
  25. Type string `json:"t"`
  26. RawData json.RawMessage `json:"d"`
  27. // Struct contains one of the other types in this file.
  28. Struct interface{} `json:"-"`
  29. }
  30. // A Ready stores all data for the websocket READY event.
  31. type Ready struct {
  32. Version int `json:"v"`
  33. SessionID string `json:"session_id"`
  34. User *User `json:"user"`
  35. ReadState []*ReadState `json:"read_state"`
  36. PrivateChannels []*Channel `json:"private_channels"`
  37. Guilds []*Guild `json:"guilds"`
  38. // Undocumented fields
  39. Settings *Settings `json:"user_settings"`
  40. UserGuildSettings []*UserGuildSettings `json:"user_guild_settings"`
  41. Relationships []*Relationship `json:"relationships"`
  42. Presences []*Presence `json:"presences"`
  43. Notes map[string]string `json:"notes"`
  44. }
  45. // ChannelCreate is the data for a ChannelCreate event.
  46. type ChannelCreate struct {
  47. *Channel
  48. }
  49. // ChannelUpdate is the data for a ChannelUpdate event.
  50. type ChannelUpdate struct {
  51. *Channel
  52. }
  53. // ChannelDelete is the data for a ChannelDelete event.
  54. type ChannelDelete struct {
  55. *Channel
  56. }
  57. // ChannelPinsUpdate stores data for a ChannelPinsUpdate event.
  58. type ChannelPinsUpdate struct {
  59. LastPinTimestamp string `json:"last_pin_timestamp"`
  60. ChannelID string `json:"channel_id"`
  61. GuildID string `json:"guild_id,omitempty"`
  62. }
  63. // GuildCreate is the data for a GuildCreate event.
  64. type GuildCreate struct {
  65. *Guild
  66. }
  67. // GuildUpdate is the data for a GuildUpdate event.
  68. type GuildUpdate struct {
  69. *Guild
  70. }
  71. // GuildDelete is the data for a GuildDelete event.
  72. type GuildDelete struct {
  73. *Guild
  74. BeforeDelete *Guild `json:"-"`
  75. }
  76. // GuildBanAdd is the data for a GuildBanAdd event.
  77. type GuildBanAdd struct {
  78. User *User `json:"user"`
  79. GuildID string `json:"guild_id"`
  80. }
  81. // GuildBanRemove is the data for a GuildBanRemove event.
  82. type GuildBanRemove struct {
  83. User *User `json:"user"`
  84. GuildID string `json:"guild_id"`
  85. }
  86. // GuildMemberAdd is the data for a GuildMemberAdd event.
  87. type GuildMemberAdd struct {
  88. *Member
  89. }
  90. // GuildMemberUpdate is the data for a GuildMemberUpdate event.
  91. type GuildMemberUpdate struct {
  92. *Member
  93. }
  94. // GuildMemberRemove is the data for a GuildMemberRemove event.
  95. type GuildMemberRemove struct {
  96. *Member
  97. }
  98. // GuildRoleCreate is the data for a GuildRoleCreate event.
  99. type GuildRoleCreate struct {
  100. *GuildRole
  101. }
  102. // GuildRoleUpdate is the data for a GuildRoleUpdate event.
  103. type GuildRoleUpdate struct {
  104. *GuildRole
  105. }
  106. // A GuildRoleDelete is the data for a GuildRoleDelete event.
  107. type GuildRoleDelete struct {
  108. RoleID string `json:"role_id"`
  109. GuildID string `json:"guild_id"`
  110. }
  111. // A GuildEmojisUpdate is the data for a guild emoji update event.
  112. type GuildEmojisUpdate struct {
  113. GuildID string `json:"guild_id"`
  114. Emojis []*Emoji `json:"emojis"`
  115. }
  116. // A GuildMembersChunk is the data for a GuildMembersChunk event.
  117. type GuildMembersChunk struct {
  118. GuildID string `json:"guild_id"`
  119. Members []*Member `json:"members"`
  120. ChunkIndex int `json:"chunk_index"`
  121. ChunkCount int `json:"chunk_count"`
  122. Presences []*Presence `json:"presences,omitempty"`
  123. }
  124. // GuildIntegrationsUpdate is the data for a GuildIntegrationsUpdate event.
  125. type GuildIntegrationsUpdate struct {
  126. GuildID string `json:"guild_id"`
  127. }
  128. // MessageAck is the data for a MessageAck event.
  129. type MessageAck struct {
  130. MessageID string `json:"message_id"`
  131. ChannelID string `json:"channel_id"`
  132. }
  133. // MessageCreate is the data for a MessageCreate event.
  134. type MessageCreate struct {
  135. *Message
  136. }
  137. // UnmarshalJSON is a helper function to unmarshal MessageCreate object.
  138. func (m *MessageCreate) UnmarshalJSON(b []byte) error {
  139. return json.Unmarshal(b, &m.Message)
  140. }
  141. // MessageUpdate is the data for a MessageUpdate event.
  142. type MessageUpdate struct {
  143. *Message
  144. // BeforeUpdate will be nil if the Message was not previously cached in the state cache.
  145. BeforeUpdate *Message `json:"-"`
  146. }
  147. // UnmarshalJSON is a helper function to unmarshal MessageUpdate object.
  148. func (m *MessageUpdate) UnmarshalJSON(b []byte) error {
  149. return json.Unmarshal(b, &m.Message)
  150. }
  151. // MessageDelete is the data for a MessageDelete event.
  152. type MessageDelete struct {
  153. *Message
  154. BeforeDelete *Message `json:"-"`
  155. }
  156. // UnmarshalJSON is a helper function to unmarshal MessageDelete object.
  157. func (m *MessageDelete) UnmarshalJSON(b []byte) error {
  158. return json.Unmarshal(b, &m.Message)
  159. }
  160. // MessageReactionAdd is the data for a MessageReactionAdd event.
  161. type MessageReactionAdd struct {
  162. *MessageReaction
  163. }
  164. // MessageReactionRemove is the data for a MessageReactionRemove event.
  165. type MessageReactionRemove struct {
  166. *MessageReaction
  167. }
  168. // MessageReactionRemoveAll is the data for a MessageReactionRemoveAll event.
  169. type MessageReactionRemoveAll struct {
  170. *MessageReaction
  171. }
  172. // PresencesReplace is the data for a PresencesReplace event.
  173. type PresencesReplace []*Presence
  174. // PresenceUpdate is the data for a PresenceUpdate event.
  175. type PresenceUpdate struct {
  176. Presence
  177. GuildID string `json:"guild_id"`
  178. }
  179. // Resumed is the data for a Resumed event.
  180. type Resumed struct {
  181. Trace []string `json:"_trace"`
  182. }
  183. // RelationshipAdd is the data for a RelationshipAdd event.
  184. type RelationshipAdd struct {
  185. *Relationship
  186. }
  187. // RelationshipRemove is the data for a RelationshipRemove event.
  188. type RelationshipRemove struct {
  189. *Relationship
  190. }
  191. // TypingStart is the data for a TypingStart event.
  192. type TypingStart struct {
  193. UserID string `json:"user_id"`
  194. ChannelID string `json:"channel_id"`
  195. GuildID string `json:"guild_id,omitempty"`
  196. Timestamp int `json:"timestamp"`
  197. }
  198. // UserUpdate is the data for a UserUpdate event.
  199. type UserUpdate struct {
  200. *User
  201. }
  202. // UserSettingsUpdate is the data for a UserSettingsUpdate event.
  203. type UserSettingsUpdate map[string]interface{}
  204. // UserGuildSettingsUpdate is the data for a UserGuildSettingsUpdate event.
  205. type UserGuildSettingsUpdate struct {
  206. *UserGuildSettings
  207. }
  208. // UserNoteUpdate is the data for a UserNoteUpdate event.
  209. type UserNoteUpdate struct {
  210. ID string `json:"id"`
  211. Note string `json:"note"`
  212. }
  213. // VoiceServerUpdate is the data for a VoiceServerUpdate event.
  214. type VoiceServerUpdate struct {
  215. Token string `json:"token"`
  216. GuildID string `json:"guild_id"`
  217. Endpoint string `json:"endpoint"`
  218. }
  219. // VoiceStateUpdate is the data for a VoiceStateUpdate event.
  220. type VoiceStateUpdate struct {
  221. *VoiceState
  222. // BeforeUpdate will be nil if the VoiceState was not previously cached in the state cache.
  223. BeforeUpdate *VoiceState `json:"-"`
  224. }
  225. // MessageDeleteBulk is the data for a MessageDeleteBulk event
  226. type MessageDeleteBulk struct {
  227. Messages []string `json:"ids"`
  228. ChannelID string `json:"channel_id"`
  229. GuildID string `json:"guild_id"`
  230. }
  231. // WebhooksUpdate is the data for a WebhooksUpdate event
  232. type WebhooksUpdate struct {
  233. GuildID string `json:"guild_id"`
  234. ChannelID string `json:"channel_id"`
  235. }
  236. // InteractionCreate is the data for a InteractionCreate event
  237. type InteractionCreate struct {
  238. *Interaction
  239. }
  240. // UnmarshalJSON is a helper function to unmarshal Interaction object.
  241. func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
  242. return json.Unmarshal(b, &i.Interaction)
  243. }