events.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. // ThreadCreate is the data for a ThreadCreate event.
  64. type ThreadCreate struct {
  65. *Channel
  66. NewlyCreated bool `json:"newly_created"`
  67. }
  68. // ThreadUpdate is the data for a ThreadUpdate event.
  69. type ThreadUpdate struct {
  70. *Channel
  71. BeforeUpdate *Channel `json:"-"`
  72. }
  73. // ThreadDelete is the data for a ThreadDelete event.
  74. type ThreadDelete struct {
  75. *Channel
  76. }
  77. // ThreadListSync is the data for a ThreadListSync event.
  78. type ThreadListSync struct {
  79. // The id of the guild
  80. GuildID string `json:"guild_id"`
  81. // The parent channel ids whose threads are being synced.
  82. // If omitted, then threads were synced for the entire guild.
  83. // This array may contain channel_ids that have no active threads as well, so you know to clear that data.
  84. ChannelIDs []string `json:"channel_ids"`
  85. // All active threads in the given channels that the current user can access
  86. Threads []*Channel `json:"threads"`
  87. // All thread member objects from the synced threads for the current user,
  88. // indicating which threads the current user has been added to
  89. Members []*ThreadMember `json:"members"`
  90. }
  91. // ThreadMemberUpdate is the data for a ThreadMemberUpdate event.
  92. type ThreadMemberUpdate struct {
  93. *ThreadMember
  94. GuildID string `json:"guild_id"`
  95. }
  96. // ThreadMembersUpdate is the data for a ThreadMembersUpdate event.
  97. type ThreadMembersUpdate struct {
  98. ID string `json:"id"`
  99. GuildID string `json:"guild_id"`
  100. MemberCount int `json:"member_count"`
  101. AddedMembers []AddedThreadMember `json:"added_members"`
  102. RemovedMembers []string `json:"removed_member_ids"`
  103. }
  104. // GuildCreate is the data for a GuildCreate event.
  105. type GuildCreate struct {
  106. *Guild
  107. }
  108. // GuildUpdate is the data for a GuildUpdate event.
  109. type GuildUpdate struct {
  110. *Guild
  111. }
  112. // GuildDelete is the data for a GuildDelete event.
  113. type GuildDelete struct {
  114. *Guild
  115. BeforeDelete *Guild `json:"-"`
  116. }
  117. // GuildBanAdd is the data for a GuildBanAdd event.
  118. type GuildBanAdd struct {
  119. User *User `json:"user"`
  120. GuildID string `json:"guild_id"`
  121. }
  122. // GuildBanRemove is the data for a GuildBanRemove event.
  123. type GuildBanRemove struct {
  124. User *User `json:"user"`
  125. GuildID string `json:"guild_id"`
  126. }
  127. // GuildMemberAdd is the data for a GuildMemberAdd event.
  128. type GuildMemberAdd struct {
  129. *Member
  130. }
  131. // GuildMemberUpdate is the data for a GuildMemberUpdate event.
  132. type GuildMemberUpdate struct {
  133. *Member
  134. }
  135. // GuildMemberRemove is the data for a GuildMemberRemove event.
  136. type GuildMemberRemove struct {
  137. *Member
  138. }
  139. // GuildRoleCreate is the data for a GuildRoleCreate event.
  140. type GuildRoleCreate struct {
  141. *GuildRole
  142. }
  143. // GuildRoleUpdate is the data for a GuildRoleUpdate event.
  144. type GuildRoleUpdate struct {
  145. *GuildRole
  146. }
  147. // A GuildRoleDelete is the data for a GuildRoleDelete event.
  148. type GuildRoleDelete struct {
  149. RoleID string `json:"role_id"`
  150. GuildID string `json:"guild_id"`
  151. }
  152. // A GuildEmojisUpdate is the data for a guild emoji update event.
  153. type GuildEmojisUpdate struct {
  154. GuildID string `json:"guild_id"`
  155. Emojis []*Emoji `json:"emojis"`
  156. }
  157. // A GuildMembersChunk is the data for a GuildMembersChunk event.
  158. type GuildMembersChunk struct {
  159. GuildID string `json:"guild_id"`
  160. Members []*Member `json:"members"`
  161. ChunkIndex int `json:"chunk_index"`
  162. ChunkCount int `json:"chunk_count"`
  163. Presences []*Presence `json:"presences,omitempty"`
  164. }
  165. // GuildIntegrationsUpdate is the data for a GuildIntegrationsUpdate event.
  166. type GuildIntegrationsUpdate struct {
  167. GuildID string `json:"guild_id"`
  168. }
  169. // MessageAck is the data for a MessageAck event.
  170. type MessageAck struct {
  171. MessageID string `json:"message_id"`
  172. ChannelID string `json:"channel_id"`
  173. }
  174. // MessageCreate is the data for a MessageCreate event.
  175. type MessageCreate struct {
  176. *Message
  177. }
  178. // UnmarshalJSON is a helper function to unmarshal MessageCreate object.
  179. func (m *MessageCreate) UnmarshalJSON(b []byte) error {
  180. return json.Unmarshal(b, &m.Message)
  181. }
  182. // MessageUpdate is the data for a MessageUpdate event.
  183. type MessageUpdate struct {
  184. *Message
  185. // BeforeUpdate will be nil if the Message was not previously cached in the state cache.
  186. BeforeUpdate *Message `json:"-"`
  187. }
  188. // UnmarshalJSON is a helper function to unmarshal MessageUpdate object.
  189. func (m *MessageUpdate) UnmarshalJSON(b []byte) error {
  190. return json.Unmarshal(b, &m.Message)
  191. }
  192. // MessageDelete is the data for a MessageDelete event.
  193. type MessageDelete struct {
  194. *Message
  195. BeforeDelete *Message `json:"-"`
  196. }
  197. // UnmarshalJSON is a helper function to unmarshal MessageDelete object.
  198. func (m *MessageDelete) UnmarshalJSON(b []byte) error {
  199. return json.Unmarshal(b, &m.Message)
  200. }
  201. // MessageReactionAdd is the data for a MessageReactionAdd event.
  202. type MessageReactionAdd struct {
  203. *MessageReaction
  204. Member *Member `json:"member,omitempty"`
  205. }
  206. // MessageReactionRemove is the data for a MessageReactionRemove event.
  207. type MessageReactionRemove struct {
  208. *MessageReaction
  209. }
  210. // MessageReactionRemoveAll is the data for a MessageReactionRemoveAll event.
  211. type MessageReactionRemoveAll struct {
  212. *MessageReaction
  213. }
  214. // PresencesReplace is the data for a PresencesReplace event.
  215. type PresencesReplace []*Presence
  216. // PresenceUpdate is the data for a PresenceUpdate event.
  217. type PresenceUpdate struct {
  218. Presence
  219. GuildID string `json:"guild_id"`
  220. }
  221. // Resumed is the data for a Resumed event.
  222. type Resumed struct {
  223. Trace []string `json:"_trace"`
  224. }
  225. // RelationshipAdd is the data for a RelationshipAdd event.
  226. type RelationshipAdd struct {
  227. *Relationship
  228. }
  229. // RelationshipRemove is the data for a RelationshipRemove event.
  230. type RelationshipRemove struct {
  231. *Relationship
  232. }
  233. // TypingStart is the data for a TypingStart event.
  234. type TypingStart struct {
  235. UserID string `json:"user_id"`
  236. ChannelID string `json:"channel_id"`
  237. GuildID string `json:"guild_id,omitempty"`
  238. Timestamp int `json:"timestamp"`
  239. }
  240. // UserUpdate is the data for a UserUpdate event.
  241. type UserUpdate struct {
  242. *User
  243. }
  244. // UserSettingsUpdate is the data for a UserSettingsUpdate event.
  245. type UserSettingsUpdate map[string]interface{}
  246. // UserGuildSettingsUpdate is the data for a UserGuildSettingsUpdate event.
  247. type UserGuildSettingsUpdate struct {
  248. *UserGuildSettings
  249. }
  250. // UserNoteUpdate is the data for a UserNoteUpdate event.
  251. type UserNoteUpdate struct {
  252. ID string `json:"id"`
  253. Note string `json:"note"`
  254. }
  255. // VoiceServerUpdate is the data for a VoiceServerUpdate event.
  256. type VoiceServerUpdate struct {
  257. Token string `json:"token"`
  258. GuildID string `json:"guild_id"`
  259. Endpoint string `json:"endpoint"`
  260. }
  261. // VoiceStateUpdate is the data for a VoiceStateUpdate event.
  262. type VoiceStateUpdate struct {
  263. *VoiceState
  264. // BeforeUpdate will be nil if the VoiceState was not previously cached in the state cache.
  265. BeforeUpdate *VoiceState `json:"-"`
  266. }
  267. // MessageDeleteBulk is the data for a MessageDeleteBulk event
  268. type MessageDeleteBulk struct {
  269. Messages []string `json:"ids"`
  270. ChannelID string `json:"channel_id"`
  271. GuildID string `json:"guild_id"`
  272. }
  273. // WebhooksUpdate is the data for a WebhooksUpdate event
  274. type WebhooksUpdate struct {
  275. GuildID string `json:"guild_id"`
  276. ChannelID string `json:"channel_id"`
  277. }
  278. // InteractionCreate is the data for a InteractionCreate event
  279. type InteractionCreate struct {
  280. *Interaction
  281. }
  282. // UnmarshalJSON is a helper function to unmarshal Interaction object.
  283. func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
  284. return json.Unmarshal(b, &i.Interaction)
  285. }