events.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. // GuildScheduledEventCreate is the data for a GuildScheduledEventCreate event.
  170. type GuildScheduledEventCreate struct {
  171. *GuildScheduledEvent
  172. }
  173. // GuildScheduledEventUpdate is the data for a GuildScheduledEventUpdate event.
  174. type GuildScheduledEventUpdate struct {
  175. *GuildScheduledEvent
  176. }
  177. // GuildScheduledEventDelete is the data for a GuildScheduledEventDelete event.
  178. type GuildScheduledEventDelete struct {
  179. *GuildScheduledEvent
  180. }
  181. // MessageAck is the data for a MessageAck event.
  182. type MessageAck struct {
  183. MessageID string `json:"message_id"`
  184. ChannelID string `json:"channel_id"`
  185. }
  186. // MessageCreate is the data for a MessageCreate event.
  187. type MessageCreate struct {
  188. *Message
  189. }
  190. // UnmarshalJSON is a helper function to unmarshal MessageCreate object.
  191. func (m *MessageCreate) UnmarshalJSON(b []byte) error {
  192. return json.Unmarshal(b, &m.Message)
  193. }
  194. // MessageUpdate is the data for a MessageUpdate event.
  195. type MessageUpdate struct {
  196. *Message
  197. // BeforeUpdate will be nil if the Message was not previously cached in the state cache.
  198. BeforeUpdate *Message `json:"-"`
  199. }
  200. // UnmarshalJSON is a helper function to unmarshal MessageUpdate object.
  201. func (m *MessageUpdate) UnmarshalJSON(b []byte) error {
  202. return json.Unmarshal(b, &m.Message)
  203. }
  204. // MessageDelete is the data for a MessageDelete event.
  205. type MessageDelete struct {
  206. *Message
  207. BeforeDelete *Message `json:"-"`
  208. }
  209. // UnmarshalJSON is a helper function to unmarshal MessageDelete object.
  210. func (m *MessageDelete) UnmarshalJSON(b []byte) error {
  211. return json.Unmarshal(b, &m.Message)
  212. }
  213. // MessageReactionAdd is the data for a MessageReactionAdd event.
  214. type MessageReactionAdd struct {
  215. *MessageReaction
  216. Member *Member `json:"member,omitempty"`
  217. }
  218. // MessageReactionRemove is the data for a MessageReactionRemove event.
  219. type MessageReactionRemove struct {
  220. *MessageReaction
  221. }
  222. // MessageReactionRemoveAll is the data for a MessageReactionRemoveAll event.
  223. type MessageReactionRemoveAll struct {
  224. *MessageReaction
  225. }
  226. // PresencesReplace is the data for a PresencesReplace event.
  227. type PresencesReplace []*Presence
  228. // PresenceUpdate is the data for a PresenceUpdate event.
  229. type PresenceUpdate struct {
  230. Presence
  231. GuildID string `json:"guild_id"`
  232. }
  233. // Resumed is the data for a Resumed event.
  234. type Resumed struct {
  235. Trace []string `json:"_trace"`
  236. }
  237. // RelationshipAdd is the data for a RelationshipAdd event.
  238. type RelationshipAdd struct {
  239. *Relationship
  240. }
  241. // RelationshipRemove is the data for a RelationshipRemove event.
  242. type RelationshipRemove struct {
  243. *Relationship
  244. }
  245. // TypingStart is the data for a TypingStart event.
  246. type TypingStart struct {
  247. UserID string `json:"user_id"`
  248. ChannelID string `json:"channel_id"`
  249. GuildID string `json:"guild_id,omitempty"`
  250. Timestamp int `json:"timestamp"`
  251. }
  252. // UserUpdate is the data for a UserUpdate event.
  253. type UserUpdate struct {
  254. *User
  255. }
  256. // UserSettingsUpdate is the data for a UserSettingsUpdate event.
  257. type UserSettingsUpdate map[string]interface{}
  258. // UserGuildSettingsUpdate is the data for a UserGuildSettingsUpdate event.
  259. type UserGuildSettingsUpdate struct {
  260. *UserGuildSettings
  261. }
  262. // UserNoteUpdate is the data for a UserNoteUpdate event.
  263. type UserNoteUpdate struct {
  264. ID string `json:"id"`
  265. Note string `json:"note"`
  266. }
  267. // VoiceServerUpdate is the data for a VoiceServerUpdate event.
  268. type VoiceServerUpdate struct {
  269. Token string `json:"token"`
  270. GuildID string `json:"guild_id"`
  271. Endpoint string `json:"endpoint"`
  272. }
  273. // VoiceStateUpdate is the data for a VoiceStateUpdate event.
  274. type VoiceStateUpdate struct {
  275. *VoiceState
  276. // BeforeUpdate will be nil if the VoiceState was not previously cached in the state cache.
  277. BeforeUpdate *VoiceState `json:"-"`
  278. }
  279. // MessageDeleteBulk is the data for a MessageDeleteBulk event
  280. type MessageDeleteBulk struct {
  281. Messages []string `json:"ids"`
  282. ChannelID string `json:"channel_id"`
  283. GuildID string `json:"guild_id"`
  284. }
  285. // WebhooksUpdate is the data for a WebhooksUpdate event
  286. type WebhooksUpdate struct {
  287. GuildID string `json:"guild_id"`
  288. ChannelID string `json:"channel_id"`
  289. }
  290. // InteractionCreate is the data for a InteractionCreate event
  291. type InteractionCreate struct {
  292. *Interaction
  293. }
  294. // UnmarshalJSON is a helper function to unmarshal Interaction object.
  295. func (i *InteractionCreate) UnmarshalJSON(b []byte) error {
  296. return json.Unmarshal(b, &i.Interaction)
  297. }
  298. // InviteCreate is the data for a InviteCreate event
  299. type InviteCreate struct {
  300. *Invite
  301. ChannelID string `json:"channel_id"`
  302. GuildID string `json:"guild_id"`
  303. }
  304. // InviteDelete is the data for a InviteDelete event
  305. type InviteDelete struct {
  306. ChannelID string `json:"channel_id"`
  307. GuildID string `json:"guild_id"`
  308. Code string `json:"code"`
  309. }