structs.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains all structures for the discordgo package. These
  7. // may be moved about later into separate files but I find it easier to have
  8. // them all located together.
  9. package discordgo
  10. import (
  11. "encoding/json"
  12. "fmt"
  13. "net/http"
  14. "sync"
  15. "time"
  16. "github.com/gorilla/websocket"
  17. )
  18. // A Session represents a connection to the Discord API.
  19. type Session struct {
  20. sync.RWMutex
  21. // General configurable settings.
  22. // Authentication token for this session
  23. Token string
  24. MFA bool
  25. // Debug for printing JSON request/responses
  26. Debug bool // Deprecated, will be removed.
  27. LogLevel int
  28. // Should the session reconnect the websocket on errors.
  29. ShouldReconnectOnError bool
  30. // Should the session request compressed websocket data.
  31. Compress bool
  32. // Sharding
  33. ShardID int
  34. ShardCount int
  35. // Should state tracking be enabled.
  36. // State tracking is the best way for getting the the users
  37. // active guilds and the members of the guilds.
  38. StateEnabled bool
  39. // Whether or not to call event handlers synchronously.
  40. // e.g false = launch event handlers in their own goroutines.
  41. SyncEvents bool
  42. // Exposed but should not be modified by User.
  43. // Whether the Data Websocket is ready
  44. DataReady bool // NOTE: Maye be deprecated soon
  45. // Max number of REST API retries
  46. MaxRestRetries int
  47. // Status stores the currect status of the websocket connection
  48. // this is being tested, may stay, may go away.
  49. status int32
  50. // Whether the Voice Websocket is ready
  51. VoiceReady bool // NOTE: Deprecated.
  52. // Whether the UDP Connection is ready
  53. UDPReady bool // NOTE: Deprecated
  54. // Stores a mapping of guild id's to VoiceConnections
  55. VoiceConnections map[string]*VoiceConnection
  56. // Managed state object, updated internally with events when
  57. // StateEnabled is true.
  58. State *State
  59. // The http client used for REST requests
  60. Client *http.Client
  61. // Stores the last HeartbeatAck that was recieved (in UTC)
  62. LastHeartbeatAck time.Time
  63. // used to deal with rate limits
  64. Ratelimiter *RateLimiter
  65. // Event handlers
  66. handlersMu sync.RWMutex
  67. handlers map[string][]*eventHandlerInstance
  68. onceHandlers map[string][]*eventHandlerInstance
  69. // The websocket connection.
  70. wsConn *websocket.Conn
  71. // When nil, the session is not listening.
  72. listening chan interface{}
  73. // sequence tracks the current gateway api websocket sequence number
  74. sequence *int64
  75. // stores sessions current Discord Gateway
  76. gateway string
  77. // stores session ID of current Gateway connection
  78. sessionID string
  79. // used to make sure gateway websocket writes do not happen concurrently
  80. wsMutex sync.Mutex
  81. }
  82. // UserConnection is a Connection returned from the UserConnections endpoint
  83. type UserConnection struct {
  84. ID string `json:"id"`
  85. Name string `json:"name"`
  86. Type string `json:"type"`
  87. Revoked bool `json:"revoked"`
  88. Integrations []*Integration `json:"integrations"`
  89. }
  90. // Integration stores integration information
  91. type Integration struct {
  92. ID string `json:"id"`
  93. Name string `json:"name"`
  94. Type string `json:"type"`
  95. Enabled bool `json:"enabled"`
  96. Syncing bool `json:"syncing"`
  97. RoleID string `json:"role_id"`
  98. ExpireBehavior int `json:"expire_behavior"`
  99. ExpireGracePeriod int `json:"expire_grace_period"`
  100. User *User `json:"user"`
  101. Account IntegrationAccount `json:"account"`
  102. SyncedAt Timestamp `json:"synced_at"`
  103. }
  104. // IntegrationAccount is integration account information
  105. // sent by the UserConnections endpoint
  106. type IntegrationAccount struct {
  107. ID string `json:"id"`
  108. Name string `json:"name"`
  109. }
  110. // A VoiceRegion stores data for a specific voice region server.
  111. type VoiceRegion struct {
  112. ID string `json:"id"`
  113. Name string `json:"name"`
  114. Hostname string `json:"sample_hostname"`
  115. Port int `json:"sample_port"`
  116. }
  117. // A VoiceICE stores data for voice ICE servers.
  118. type VoiceICE struct {
  119. TTL string `json:"ttl"`
  120. Servers []*ICEServer `json:"servers"`
  121. }
  122. // A ICEServer stores data for a specific voice ICE server.
  123. type ICEServer struct {
  124. URL string `json:"url"`
  125. Username string `json:"username"`
  126. Credential string `json:"credential"`
  127. }
  128. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  129. type Invite struct {
  130. Guild *Guild `json:"guild"`
  131. Channel *Channel `json:"channel"`
  132. Inviter *User `json:"inviter"`
  133. Code string `json:"code"`
  134. CreatedAt Timestamp `json:"created_at"`
  135. MaxAge int `json:"max_age"`
  136. Uses int `json:"uses"`
  137. MaxUses int `json:"max_uses"`
  138. Revoked bool `json:"revoked"`
  139. Temporary bool `json:"temporary"`
  140. Unique bool `json:"unique"`
  141. // will only be filled when using InviteWithCounts
  142. ApproximatePresenceCount int `json:"approximate_presence_count"`
  143. ApproximateMemberCount int `json:"approximate_member_count"`
  144. }
  145. // ChannelType is the type of a Channel
  146. type ChannelType int
  147. // Block contains known ChannelType values
  148. const (
  149. ChannelTypeGuildText ChannelType = iota
  150. ChannelTypeDM
  151. ChannelTypeGuildVoice
  152. ChannelTypeGroupDM
  153. ChannelTypeGuildCategory
  154. )
  155. // A Channel holds all data related to an individual Discord channel.
  156. type Channel struct {
  157. // The ID of the channel.
  158. ID string `json:"id"`
  159. // The ID of the guild to which the channel belongs, if it is in a guild.
  160. // Else, this ID is empty (e.g. DM channels).
  161. GuildID string `json:"guild_id"`
  162. // The name of the channel.
  163. Name string `json:"name"`
  164. // The topic of the channel.
  165. Topic string `json:"topic"`
  166. // The type of the channel.
  167. Type ChannelType `json:"type"`
  168. // The ID of the last message sent in the channel. This is not
  169. // guaranteed to be an ID of a valid message.
  170. LastMessageID string `json:"last_message_id"`
  171. // Whether the channel is marked as NSFW.
  172. NSFW bool `json:"nsfw"`
  173. // Icon of the group DM channel.
  174. Icon string `json:"icon"`
  175. // The position of the channel, used for sorting in client.
  176. Position int `json:"position"`
  177. // The bitrate of the channel, if it is a voice channel.
  178. Bitrate int `json:"bitrate"`
  179. // The recipients of the channel. This is only populated in DM channels.
  180. Recipients []*User `json:"recipients"`
  181. // The messages in the channel. This is only present in state-cached channels,
  182. // and State.MaxMessageCount must be non-zero.
  183. Messages []*Message `json:"-"`
  184. // A list of permission overwrites present for the channel.
  185. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  186. // The user limit of the voice channel.
  187. UserLimit int `json:"user_limit"`
  188. // The ID of the parent channel, if the channel is under a category
  189. ParentID string `json:"parent_id"`
  190. }
  191. // Mention returns a string which mentions the channel
  192. func (c *Channel) Mention() string {
  193. return fmt.Sprintf("<#%s>", c.ID)
  194. }
  195. // A ChannelEdit holds Channel Feild data for a channel edit.
  196. type ChannelEdit struct {
  197. Name string `json:"name,omitempty"`
  198. Topic string `json:"topic,omitempty"`
  199. NSFW bool `json:"nsfw,omitempty"`
  200. Position int `json:"position"`
  201. Bitrate int `json:"bitrate,omitempty"`
  202. UserLimit int `json:"user_limit,omitempty"`
  203. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  204. ParentID string `json:"parent_id,omitempty"`
  205. }
  206. // A PermissionOverwrite holds permission overwrite data for a Channel
  207. type PermissionOverwrite struct {
  208. ID string `json:"id"`
  209. Type string `json:"type"`
  210. Deny int `json:"deny"`
  211. Allow int `json:"allow"`
  212. }
  213. // Emoji struct holds data related to Emoji's
  214. type Emoji struct {
  215. ID string `json:"id"`
  216. Name string `json:"name"`
  217. Roles []string `json:"roles"`
  218. Managed bool `json:"managed"`
  219. RequireColons bool `json:"require_colons"`
  220. Animated bool `json:"animated"`
  221. }
  222. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  223. func (e *Emoji) APIName() string {
  224. if e.ID != "" && e.Name != "" {
  225. return e.Name + ":" + e.ID
  226. }
  227. if e.Name != "" {
  228. return e.Name
  229. }
  230. return e.ID
  231. }
  232. // VerificationLevel type definition
  233. type VerificationLevel int
  234. // Constants for VerificationLevel levels from 0 to 3 inclusive
  235. const (
  236. VerificationLevelNone VerificationLevel = iota
  237. VerificationLevelLow
  238. VerificationLevelMedium
  239. VerificationLevelHigh
  240. )
  241. // ExplicitContentFilterLevel type definition
  242. type ExplicitContentFilterLevel int
  243. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  244. const (
  245. ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
  246. ExplicitContentFilterMembersWithoutRoles
  247. ExplicitContentFilterAllMembers
  248. )
  249. // MfaLevel type definition
  250. type MfaLevel int
  251. // Constants for MfaLevel levels from 0 to 1 inclusive
  252. const (
  253. MfaLevelNone MfaLevel = iota
  254. MfaLevelElevated
  255. )
  256. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  257. // sometimes referred to as Servers in the Discord client.
  258. type Guild struct {
  259. // The ID of the guild.
  260. ID string `json:"id"`
  261. // The name of the guild. (2–100 characters)
  262. Name string `json:"name"`
  263. // The hash of the guild's icon. Use Session.GuildIcon
  264. // to retrieve the icon itself.
  265. Icon string `json:"icon"`
  266. // The voice region of the guild.
  267. Region string `json:"region"`
  268. // The ID of the AFK voice channel.
  269. AfkChannelID string `json:"afk_channel_id"`
  270. // The ID of the embed channel ID, used for embed widgets.
  271. EmbedChannelID string `json:"embed_channel_id"`
  272. // The user ID of the owner of the guild.
  273. OwnerID string `json:"owner_id"`
  274. // The time at which the current user joined the guild.
  275. // This field is only present in GUILD_CREATE events and websocket
  276. // update events, and thus is only present in state-cached guilds.
  277. JoinedAt Timestamp `json:"joined_at"`
  278. // The hash of the guild's splash.
  279. Splash string `json:"splash"`
  280. // The timeout, in seconds, before a user is considered AFK in voice.
  281. AfkTimeout int `json:"afk_timeout"`
  282. // The number of members in the guild.
  283. // This field is only present in GUILD_CREATE events and websocket
  284. // update events, and thus is only present in state-cached guilds.
  285. MemberCount int `json:"member_count"`
  286. // The verification level required for the guild.
  287. VerificationLevel VerificationLevel `json:"verification_level"`
  288. // Whether the guild has embedding enabled.
  289. EmbedEnabled bool `json:"embed_enabled"`
  290. // Whether the guild is considered large. This is
  291. // determined by a member threshold in the identify packet,
  292. // and is currently hard-coded at 250 members in the library.
  293. Large bool `json:"large"`
  294. // The default message notification setting for the guild.
  295. // 0 == all messages, 1 == mentions only.
  296. DefaultMessageNotifications int `json:"default_message_notifications"`
  297. // A list of roles in the guild.
  298. Roles []*Role `json:"roles"`
  299. // A list of the custom emojis present in the guild.
  300. Emojis []*Emoji `json:"emojis"`
  301. // A list of the members in the guild.
  302. // This field is only present in GUILD_CREATE events and websocket
  303. // update events, and thus is only present in state-cached guilds.
  304. Members []*Member `json:"members"`
  305. // A list of partial presence objects for members in the guild.
  306. // This field is only present in GUILD_CREATE events and websocket
  307. // update events, and thus is only present in state-cached guilds.
  308. Presences []*Presence `json:"presences"`
  309. // A list of channels in the guild.
  310. // This field is only present in GUILD_CREATE events and websocket
  311. // update events, and thus is only present in state-cached guilds.
  312. Channels []*Channel `json:"channels"`
  313. // A list of voice states for the guild.
  314. // This field is only present in GUILD_CREATE events and websocket
  315. // update events, and thus is only present in state-cached guilds.
  316. VoiceStates []*VoiceState `json:"voice_states"`
  317. // Whether this guild is currently unavailable (most likely due to outage).
  318. // This field is only present in GUILD_CREATE events and websocket
  319. // update events, and thus is only present in state-cached guilds.
  320. Unavailable bool `json:"unavailable"`
  321. // The explicit content filter level
  322. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  323. // The list of enabled guild features
  324. Features []string `json:"features"`
  325. // Required MFA level for the guild
  326. MfaLevel MfaLevel `json:"mfa_level"`
  327. // Whether or not the Server Widget is enabled
  328. WidgetEnabled bool `json:"widget_enabled"`
  329. // The Channel ID for the Server Widget
  330. WidgetChannelID string `json:"widget_channel_id"`
  331. // The Channel ID to which system messages are sent (eg join and leave messages)
  332. SystemChannelID string `json:"system_channel_id"`
  333. }
  334. // A UserGuild holds a brief version of a Guild
  335. type UserGuild struct {
  336. ID string `json:"id"`
  337. Name string `json:"name"`
  338. Icon string `json:"icon"`
  339. Owner bool `json:"owner"`
  340. Permissions int `json:"permissions"`
  341. }
  342. // A GuildParams stores all the data needed to update discord guild settings
  343. type GuildParams struct {
  344. Name string `json:"name,omitempty"`
  345. Region string `json:"region,omitempty"`
  346. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  347. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  348. AfkChannelID string `json:"afk_channel_id,omitempty"`
  349. AfkTimeout int `json:"afk_timeout,omitempty"`
  350. Icon string `json:"icon,omitempty"`
  351. OwnerID string `json:"owner_id,omitempty"`
  352. Splash string `json:"splash,omitempty"`
  353. }
  354. // A Role stores information about Discord guild member roles.
  355. type Role struct {
  356. // The ID of the role.
  357. ID string `json:"id"`
  358. // The name of the role.
  359. Name string `json:"name"`
  360. // Whether this role is managed by an integration, and
  361. // thus cannot be manually added to, or taken from, members.
  362. Managed bool `json:"managed"`
  363. // Whether this role is mentionable.
  364. Mentionable bool `json:"mentionable"`
  365. // Whether this role is hoisted (shows up separately in member list).
  366. Hoist bool `json:"hoist"`
  367. // The hex color of this role.
  368. Color int `json:"color"`
  369. // The position of this role in the guild's role hierarchy.
  370. Position int `json:"position"`
  371. // The permissions of the role on the guild (doesn't include channel overrides).
  372. // This is a combination of bit masks; the presence of a certain permission can
  373. // be checked by performing a bitwise AND between this int and the permission.
  374. Permissions int `json:"permissions"`
  375. }
  376. // Mention returns a string which mentions the role
  377. func (r *Role) Mention() string {
  378. return fmt.Sprintf("<@&%s>", r.ID)
  379. }
  380. // Roles are a collection of Role
  381. type Roles []*Role
  382. func (r Roles) Len() int {
  383. return len(r)
  384. }
  385. func (r Roles) Less(i, j int) bool {
  386. return r[i].Position > r[j].Position
  387. }
  388. func (r Roles) Swap(i, j int) {
  389. r[i], r[j] = r[j], r[i]
  390. }
  391. // A VoiceState stores the voice states of Guilds
  392. type VoiceState struct {
  393. UserID string `json:"user_id"`
  394. SessionID string `json:"session_id"`
  395. ChannelID string `json:"channel_id"`
  396. GuildID string `json:"guild_id"`
  397. Suppress bool `json:"suppress"`
  398. SelfMute bool `json:"self_mute"`
  399. SelfDeaf bool `json:"self_deaf"`
  400. Mute bool `json:"mute"`
  401. Deaf bool `json:"deaf"`
  402. }
  403. // A Presence stores the online, offline, or idle and game status of Guild members.
  404. type Presence struct {
  405. User *User `json:"user"`
  406. Status Status `json:"status"`
  407. Game *Game `json:"game"`
  408. Nick string `json:"nick"`
  409. Roles []string `json:"roles"`
  410. Since *int `json:"since"`
  411. }
  412. // GameType is the type of "game" (see GameType* consts) in the Game struct
  413. type GameType int
  414. // Valid GameType values
  415. const (
  416. GameTypeGame GameType = iota
  417. GameTypeStreaming
  418. GameTypeListening
  419. GameTypeWatching
  420. )
  421. // A Game struct holds the name of the "playing .." game for a user
  422. type Game struct {
  423. Name string `json:"name"`
  424. Type GameType `json:"type"`
  425. URL string `json:"url,omitempty"`
  426. Details string `json:"details,omitempty"`
  427. State string `json:"state,omitempty"`
  428. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  429. Assets Assets `json:"assets,omitempty"`
  430. ApplicationID string `json:"application_id,omitempty"`
  431. Instance int8 `json:"instance,omitempty"`
  432. // TODO: Party and Secrets (unknown structure)
  433. }
  434. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  435. type TimeStamps struct {
  436. EndTimestamp int64 `json:"end,omitempty"`
  437. StartTimestamp int64 `json:"start,omitempty"`
  438. }
  439. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  440. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  441. temp := struct {
  442. End float64 `json:"end,omitempty"`
  443. Start float64 `json:"start,omitempty"`
  444. }{}
  445. err := json.Unmarshal(b, &temp)
  446. if err != nil {
  447. return err
  448. }
  449. t.EndTimestamp = int64(temp.End)
  450. t.StartTimestamp = int64(temp.Start)
  451. return nil
  452. }
  453. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  454. type Assets struct {
  455. LargeImageID string `json:"large_image,omitempty"`
  456. SmallImageID string `json:"small_image,omitempty"`
  457. LargeText string `json:"large_text,omitempty"`
  458. SmallText string `json:"small_text,omitempty"`
  459. }
  460. // A Member stores user information for Guild members. A guild
  461. // member represents a certain user's presence in a guild.
  462. type Member struct {
  463. // The guild ID on which the member exists.
  464. GuildID string `json:"guild_id"`
  465. // The time at which the member joined the guild, in ISO8601.
  466. JoinedAt string `json:"joined_at"`
  467. // The nickname of the member, if they have one.
  468. Nick string `json:"nick"`
  469. // Whether the member is deafened at a guild level.
  470. Deaf bool `json:"deaf"`
  471. // Whether the member is muted at a guild level.
  472. Mute bool `json:"mute"`
  473. // The underlying user on which the member is based.
  474. User *User `json:"user"`
  475. // A list of IDs of the roles which are possessed by the member.
  476. Roles []string `json:"roles"`
  477. }
  478. // A Settings stores data for a specific users Discord client settings.
  479. type Settings struct {
  480. RenderEmbeds bool `json:"render_embeds"`
  481. InlineEmbedMedia bool `json:"inline_embed_media"`
  482. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  483. EnableTtsCommand bool `json:"enable_tts_command"`
  484. MessageDisplayCompact bool `json:"message_display_compact"`
  485. ShowCurrentGame bool `json:"show_current_game"`
  486. ConvertEmoticons bool `json:"convert_emoticons"`
  487. Locale string `json:"locale"`
  488. Theme string `json:"theme"`
  489. GuildPositions []string `json:"guild_positions"`
  490. RestrictedGuilds []string `json:"restricted_guilds"`
  491. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  492. Status Status `json:"status"`
  493. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  494. DeveloperMode bool `json:"developer_mode"`
  495. }
  496. // Status type definition
  497. type Status string
  498. // Constants for Status with the different current available status
  499. const (
  500. StatusOnline Status = "online"
  501. StatusIdle Status = "idle"
  502. StatusDoNotDisturb Status = "dnd"
  503. StatusInvisible Status = "invisible"
  504. StatusOffline Status = "offline"
  505. )
  506. // FriendSourceFlags stores ... TODO :)
  507. type FriendSourceFlags struct {
  508. All bool `json:"all"`
  509. MutualGuilds bool `json:"mutual_guilds"`
  510. MutualFriends bool `json:"mutual_friends"`
  511. }
  512. // A Relationship between the logged in user and Relationship.User
  513. type Relationship struct {
  514. User *User `json:"user"`
  515. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  516. ID string `json:"id"`
  517. }
  518. // A TooManyRequests struct holds information received from Discord
  519. // when receiving a HTTP 429 response.
  520. type TooManyRequests struct {
  521. Bucket string `json:"bucket"`
  522. Message string `json:"message"`
  523. RetryAfter time.Duration `json:"retry_after"`
  524. }
  525. // A ReadState stores data on the read state of channels.
  526. type ReadState struct {
  527. MentionCount int `json:"mention_count"`
  528. LastMessageID string `json:"last_message_id"`
  529. ID string `json:"id"`
  530. }
  531. // An Ack is used to ack messages
  532. type Ack struct {
  533. Token string `json:"token"`
  534. }
  535. // A GuildRole stores data for guild roles.
  536. type GuildRole struct {
  537. Role *Role `json:"role"`
  538. GuildID string `json:"guild_id"`
  539. }
  540. // A GuildBan stores data for a guild ban.
  541. type GuildBan struct {
  542. Reason string `json:"reason"`
  543. User *User `json:"user"`
  544. }
  545. // A GuildEmbed stores data for a guild embed.
  546. type GuildEmbed struct {
  547. Enabled bool `json:"enabled"`
  548. ChannelID string `json:"channel_id"`
  549. }
  550. // A GuildAuditLog stores data for a guild audit log.
  551. type GuildAuditLog struct {
  552. Webhooks []struct {
  553. ChannelID string `json:"channel_id"`
  554. GuildID string `json:"guild_id"`
  555. ID string `json:"id"`
  556. Avatar string `json:"avatar"`
  557. Name string `json:"name"`
  558. } `json:"webhooks,omitempty"`
  559. Users []struct {
  560. Username string `json:"username"`
  561. Discriminator string `json:"discriminator"`
  562. Bot bool `json:"bot"`
  563. ID string `json:"id"`
  564. Avatar string `json:"avatar"`
  565. } `json:"users,omitempty"`
  566. AuditLogEntries []struct {
  567. TargetID string `json:"target_id"`
  568. Changes []struct {
  569. NewValue interface{} `json:"new_value"`
  570. OldValue interface{} `json:"old_value"`
  571. Key string `json:"key"`
  572. } `json:"changes,omitempty"`
  573. UserID string `json:"user_id"`
  574. ID string `json:"id"`
  575. ActionType int `json:"action_type"`
  576. Options struct {
  577. DeleteMembersDay string `json:"delete_member_days"`
  578. MembersRemoved string `json:"members_removed"`
  579. ChannelID string `json:"channel_id"`
  580. Count string `json:"count"`
  581. ID string `json:"id"`
  582. Type string `json:"type"`
  583. RoleName string `json:"role_name"`
  584. } `json:"options,omitempty"`
  585. Reason string `json:"reason"`
  586. } `json:"audit_log_entries"`
  587. }
  588. // Block contains Discord Audit Log Action Types
  589. const (
  590. AuditLogActionGuildUpdate = 1
  591. AuditLogActionChannelCreate = 10
  592. AuditLogActionChannelUpdate = 11
  593. AuditLogActionChannelDelete = 12
  594. AuditLogActionChannelOverwriteCreate = 13
  595. AuditLogActionChannelOverwriteUpdate = 14
  596. AuditLogActionChannelOverwriteDelete = 15
  597. AuditLogActionMemberKick = 20
  598. AuditLogActionMemberPrune = 21
  599. AuditLogActionMemberBanAdd = 22
  600. AuditLogActionMemberBanRemove = 23
  601. AuditLogActionMemberUpdate = 24
  602. AuditLogActionMemberRoleUpdate = 25
  603. AuditLogActionRoleCreate = 30
  604. AuditLogActionRoleUpdate = 31
  605. AuditLogActionRoleDelete = 32
  606. AuditLogActionInviteCreate = 40
  607. AuditLogActionInviteUpdate = 41
  608. AuditLogActionInviteDelete = 42
  609. AuditLogActionWebhookCreate = 50
  610. AuditLogActionWebhookUpdate = 51
  611. AuditLogActionWebhookDelete = 52
  612. AuditLogActionEmojiCreate = 60
  613. AuditLogActionEmojiUpdate = 61
  614. AuditLogActionEmojiDelete = 62
  615. AuditLogActionMessageDelete = 72
  616. )
  617. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  618. type UserGuildSettingsChannelOverride struct {
  619. Muted bool `json:"muted"`
  620. MessageNotifications int `json:"message_notifications"`
  621. ChannelID string `json:"channel_id"`
  622. }
  623. // A UserGuildSettings stores data for a users guild settings.
  624. type UserGuildSettings struct {
  625. SupressEveryone bool `json:"suppress_everyone"`
  626. Muted bool `json:"muted"`
  627. MobilePush bool `json:"mobile_push"`
  628. MessageNotifications int `json:"message_notifications"`
  629. GuildID string `json:"guild_id"`
  630. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  631. }
  632. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  633. type UserGuildSettingsEdit struct {
  634. SupressEveryone bool `json:"suppress_everyone"`
  635. Muted bool `json:"muted"`
  636. MobilePush bool `json:"mobile_push"`
  637. MessageNotifications int `json:"message_notifications"`
  638. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  639. }
  640. // An APIErrorMessage is an api error message returned from discord
  641. type APIErrorMessage struct {
  642. Code int `json:"code"`
  643. Message string `json:"message"`
  644. }
  645. // Webhook stores the data for a webhook.
  646. type Webhook struct {
  647. ID string `json:"id"`
  648. GuildID string `json:"guild_id"`
  649. ChannelID string `json:"channel_id"`
  650. User *User `json:"user"`
  651. Name string `json:"name"`
  652. Avatar string `json:"avatar"`
  653. Token string `json:"token"`
  654. }
  655. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  656. type WebhookParams struct {
  657. Content string `json:"content,omitempty"`
  658. Username string `json:"username,omitempty"`
  659. AvatarURL string `json:"avatar_url,omitempty"`
  660. TTS bool `json:"tts,omitempty"`
  661. File string `json:"file,omitempty"`
  662. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  663. }
  664. // MessageReaction stores the data for a message reaction.
  665. type MessageReaction struct {
  666. UserID string `json:"user_id"`
  667. MessageID string `json:"message_id"`
  668. Emoji Emoji `json:"emoji"`
  669. ChannelID string `json:"channel_id"`
  670. GuildID string `json:"guild_id,omitempty"`
  671. }
  672. // GatewayBotResponse stores the data for the gateway/bot response
  673. type GatewayBotResponse struct {
  674. URL string `json:"url"`
  675. Shards int `json:"shards"`
  676. }
  677. // Constants for the different bit offsets of text channel permissions
  678. const (
  679. PermissionReadMessages = 1 << (iota + 10)
  680. PermissionSendMessages
  681. PermissionSendTTSMessages
  682. PermissionManageMessages
  683. PermissionEmbedLinks
  684. PermissionAttachFiles
  685. PermissionReadMessageHistory
  686. PermissionMentionEveryone
  687. PermissionUseExternalEmojis
  688. )
  689. // Constants for the different bit offsets of voice permissions
  690. const (
  691. PermissionVoiceConnect = 1 << (iota + 20)
  692. PermissionVoiceSpeak
  693. PermissionVoiceMuteMembers
  694. PermissionVoiceDeafenMembers
  695. PermissionVoiceMoveMembers
  696. PermissionVoiceUseVAD
  697. )
  698. // Constants for general management.
  699. const (
  700. PermissionChangeNickname = 1 << (iota + 26)
  701. PermissionManageNicknames
  702. PermissionManageRoles
  703. PermissionManageWebhooks
  704. PermissionManageEmojis
  705. )
  706. // Constants for the different bit offsets of general permissions
  707. const (
  708. PermissionCreateInstantInvite = 1 << iota
  709. PermissionKickMembers
  710. PermissionBanMembers
  711. PermissionAdministrator
  712. PermissionManageChannels
  713. PermissionManageServer
  714. PermissionAddReactions
  715. PermissionViewAuditLogs
  716. PermissionAllText = PermissionReadMessages |
  717. PermissionSendMessages |
  718. PermissionSendTTSMessages |
  719. PermissionManageMessages |
  720. PermissionEmbedLinks |
  721. PermissionAttachFiles |
  722. PermissionReadMessageHistory |
  723. PermissionMentionEveryone
  724. PermissionAllVoice = PermissionVoiceConnect |
  725. PermissionVoiceSpeak |
  726. PermissionVoiceMuteMembers |
  727. PermissionVoiceDeafenMembers |
  728. PermissionVoiceMoveMembers |
  729. PermissionVoiceUseVAD
  730. PermissionAllChannel = PermissionAllText |
  731. PermissionAllVoice |
  732. PermissionCreateInstantInvite |
  733. PermissionManageRoles |
  734. PermissionManageChannels |
  735. PermissionAddReactions |
  736. PermissionViewAuditLogs
  737. PermissionAll = PermissionAllChannel |
  738. PermissionKickMembers |
  739. PermissionBanMembers |
  740. PermissionManageServer |
  741. PermissionAdministrator
  742. )
  743. // Block contains Discord JSON Error Response codes
  744. const (
  745. ErrCodeUnknownAccount = 10001
  746. ErrCodeUnknownApplication = 10002
  747. ErrCodeUnknownChannel = 10003
  748. ErrCodeUnknownGuild = 10004
  749. ErrCodeUnknownIntegration = 10005
  750. ErrCodeUnknownInvite = 10006
  751. ErrCodeUnknownMember = 10007
  752. ErrCodeUnknownMessage = 10008
  753. ErrCodeUnknownOverwrite = 10009
  754. ErrCodeUnknownProvider = 10010
  755. ErrCodeUnknownRole = 10011
  756. ErrCodeUnknownToken = 10012
  757. ErrCodeUnknownUser = 10013
  758. ErrCodeUnknownEmoji = 10014
  759. ErrCodeBotsCannotUseEndpoint = 20001
  760. ErrCodeOnlyBotsCanUseEndpoint = 20002
  761. ErrCodeMaximumGuildsReached = 30001
  762. ErrCodeMaximumFriendsReached = 30002
  763. ErrCodeMaximumPinsReached = 30003
  764. ErrCodeMaximumGuildRolesReached = 30005
  765. ErrCodeTooManyReactions = 30010
  766. ErrCodeUnauthorized = 40001
  767. ErrCodeMissingAccess = 50001
  768. ErrCodeInvalidAccountType = 50002
  769. ErrCodeCannotExecuteActionOnDMChannel = 50003
  770. ErrCodeEmbedCisabled = 50004
  771. ErrCodeCannotEditFromAnotherUser = 50005
  772. ErrCodeCannotSendEmptyMessage = 50006
  773. ErrCodeCannotSendMessagesToThisUser = 50007
  774. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  775. ErrCodeChannelVerificationLevelTooHigh = 50009
  776. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  777. ErrCodeOAuth2ApplicationLimitReached = 50011
  778. ErrCodeInvalidOAuthState = 50012
  779. ErrCodeMissingPermissions = 50013
  780. ErrCodeInvalidAuthenticationToken = 50014
  781. ErrCodeNoteTooLong = 50015
  782. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  783. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  784. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  785. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  786. ErrCodeInvalidFormBody = 50035
  787. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  788. ErrCodeReactionBlocked = 90001
  789. )