structs.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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. // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
  223. func (e *Emoji) MessageFormat() string {
  224. if e.ID != "" && e.Name != "" {
  225. if e.Animated {
  226. return "<a:" + e.APIName() + ">"
  227. }
  228. return "<:" + e.APIName() + ">"
  229. }
  230. return e.APIName()
  231. }
  232. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  233. func (e *Emoji) APIName() string {
  234. if e.ID != "" && e.Name != "" {
  235. return e.Name + ":" + e.ID
  236. }
  237. if e.Name != "" {
  238. return e.Name
  239. }
  240. return e.ID
  241. }
  242. // VerificationLevel type definition
  243. type VerificationLevel int
  244. // Constants for VerificationLevel levels from 0 to 3 inclusive
  245. const (
  246. VerificationLevelNone VerificationLevel = iota
  247. VerificationLevelLow
  248. VerificationLevelMedium
  249. VerificationLevelHigh
  250. )
  251. // ExplicitContentFilterLevel type definition
  252. type ExplicitContentFilterLevel int
  253. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  254. const (
  255. ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
  256. ExplicitContentFilterMembersWithoutRoles
  257. ExplicitContentFilterAllMembers
  258. )
  259. // MfaLevel type definition
  260. type MfaLevel int
  261. // Constants for MfaLevel levels from 0 to 1 inclusive
  262. const (
  263. MfaLevelNone MfaLevel = iota
  264. MfaLevelElevated
  265. )
  266. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  267. // sometimes referred to as Servers in the Discord client.
  268. type Guild struct {
  269. // The ID of the guild.
  270. ID string `json:"id"`
  271. // The name of the guild. (2–100 characters)
  272. Name string `json:"name"`
  273. // The hash of the guild's icon. Use Session.GuildIcon
  274. // to retrieve the icon itself.
  275. Icon string `json:"icon"`
  276. // The voice region of the guild.
  277. Region string `json:"region"`
  278. // The ID of the AFK voice channel.
  279. AfkChannelID string `json:"afk_channel_id"`
  280. // The ID of the embed channel ID, used for embed widgets.
  281. EmbedChannelID string `json:"embed_channel_id"`
  282. // The user ID of the owner of the guild.
  283. OwnerID string `json:"owner_id"`
  284. // The time at which the current user joined the guild.
  285. // This field is only present in GUILD_CREATE events and websocket
  286. // update events, and thus is only present in state-cached guilds.
  287. JoinedAt Timestamp `json:"joined_at"`
  288. // The hash of the guild's splash.
  289. Splash string `json:"splash"`
  290. // The timeout, in seconds, before a user is considered AFK in voice.
  291. AfkTimeout int `json:"afk_timeout"`
  292. // The number of members in the guild.
  293. // This field is only present in GUILD_CREATE events and websocket
  294. // update events, and thus is only present in state-cached guilds.
  295. MemberCount int `json:"member_count"`
  296. // The verification level required for the guild.
  297. VerificationLevel VerificationLevel `json:"verification_level"`
  298. // Whether the guild has embedding enabled.
  299. EmbedEnabled bool `json:"embed_enabled"`
  300. // Whether the guild is considered large. This is
  301. // determined by a member threshold in the identify packet,
  302. // and is currently hard-coded at 250 members in the library.
  303. Large bool `json:"large"`
  304. // The default message notification setting for the guild.
  305. // 0 == all messages, 1 == mentions only.
  306. DefaultMessageNotifications int `json:"default_message_notifications"`
  307. // A list of roles in the guild.
  308. Roles []*Role `json:"roles"`
  309. // A list of the custom emojis present in the guild.
  310. Emojis []*Emoji `json:"emojis"`
  311. // A list of the members in the guild.
  312. // This field is only present in GUILD_CREATE events and websocket
  313. // update events, and thus is only present in state-cached guilds.
  314. Members []*Member `json:"members"`
  315. // A list of partial presence objects for members in the guild.
  316. // This field is only present in GUILD_CREATE events and websocket
  317. // update events, and thus is only present in state-cached guilds.
  318. Presences []*Presence `json:"presences"`
  319. // A list of channels in the guild.
  320. // This field is only present in GUILD_CREATE events and websocket
  321. // update events, and thus is only present in state-cached guilds.
  322. Channels []*Channel `json:"channels"`
  323. // A list of voice states for the guild.
  324. // This field is only present in GUILD_CREATE events and websocket
  325. // update events, and thus is only present in state-cached guilds.
  326. VoiceStates []*VoiceState `json:"voice_states"`
  327. // Whether this guild is currently unavailable (most likely due to outage).
  328. // This field is only present in GUILD_CREATE events and websocket
  329. // update events, and thus is only present in state-cached guilds.
  330. Unavailable bool `json:"unavailable"`
  331. // The explicit content filter level
  332. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  333. // The list of enabled guild features
  334. Features []string `json:"features"`
  335. // Required MFA level for the guild
  336. MfaLevel MfaLevel `json:"mfa_level"`
  337. // Whether or not the Server Widget is enabled
  338. WidgetEnabled bool `json:"widget_enabled"`
  339. // The Channel ID for the Server Widget
  340. WidgetChannelID string `json:"widget_channel_id"`
  341. // The Channel ID to which system messages are sent (eg join and leave messages)
  342. SystemChannelID string `json:"system_channel_id"`
  343. }
  344. // A UserGuild holds a brief version of a Guild
  345. type UserGuild struct {
  346. ID string `json:"id"`
  347. Name string `json:"name"`
  348. Icon string `json:"icon"`
  349. Owner bool `json:"owner"`
  350. Permissions int `json:"permissions"`
  351. }
  352. // A GuildParams stores all the data needed to update discord guild settings
  353. type GuildParams struct {
  354. Name string `json:"name,omitempty"`
  355. Region string `json:"region,omitempty"`
  356. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  357. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  358. AfkChannelID string `json:"afk_channel_id,omitempty"`
  359. AfkTimeout int `json:"afk_timeout,omitempty"`
  360. Icon string `json:"icon,omitempty"`
  361. OwnerID string `json:"owner_id,omitempty"`
  362. Splash string `json:"splash,omitempty"`
  363. }
  364. // A Role stores information about Discord guild member roles.
  365. type Role struct {
  366. // The ID of the role.
  367. ID string `json:"id"`
  368. // The name of the role.
  369. Name string `json:"name"`
  370. // Whether this role is managed by an integration, and
  371. // thus cannot be manually added to, or taken from, members.
  372. Managed bool `json:"managed"`
  373. // Whether this role is mentionable.
  374. Mentionable bool `json:"mentionable"`
  375. // Whether this role is hoisted (shows up separately in member list).
  376. Hoist bool `json:"hoist"`
  377. // The hex color of this role.
  378. Color int `json:"color"`
  379. // The position of this role in the guild's role hierarchy.
  380. Position int `json:"position"`
  381. // The permissions of the role on the guild (doesn't include channel overrides).
  382. // This is a combination of bit masks; the presence of a certain permission can
  383. // be checked by performing a bitwise AND between this int and the permission.
  384. Permissions int `json:"permissions"`
  385. }
  386. // Mention returns a string which mentions the role
  387. func (r *Role) Mention() string {
  388. return fmt.Sprintf("<@&%s>", r.ID)
  389. }
  390. // Roles are a collection of Role
  391. type Roles []*Role
  392. func (r Roles) Len() int {
  393. return len(r)
  394. }
  395. func (r Roles) Less(i, j int) bool {
  396. return r[i].Position > r[j].Position
  397. }
  398. func (r Roles) Swap(i, j int) {
  399. r[i], r[j] = r[j], r[i]
  400. }
  401. // A VoiceState stores the voice states of Guilds
  402. type VoiceState struct {
  403. UserID string `json:"user_id"`
  404. SessionID string `json:"session_id"`
  405. ChannelID string `json:"channel_id"`
  406. GuildID string `json:"guild_id"`
  407. Suppress bool `json:"suppress"`
  408. SelfMute bool `json:"self_mute"`
  409. SelfDeaf bool `json:"self_deaf"`
  410. Mute bool `json:"mute"`
  411. Deaf bool `json:"deaf"`
  412. }
  413. // A Presence stores the online, offline, or idle and game status of Guild members.
  414. type Presence struct {
  415. User *User `json:"user"`
  416. Status Status `json:"status"`
  417. Game *Game `json:"game"`
  418. Nick string `json:"nick"`
  419. Roles []string `json:"roles"`
  420. Since *int `json:"since"`
  421. }
  422. // GameType is the type of "game" (see GameType* consts) in the Game struct
  423. type GameType int
  424. // Valid GameType values
  425. const (
  426. GameTypeGame GameType = iota
  427. GameTypeStreaming
  428. GameTypeListening
  429. GameTypeWatching
  430. )
  431. // A Game struct holds the name of the "playing .." game for a user
  432. type Game struct {
  433. Name string `json:"name"`
  434. Type GameType `json:"type"`
  435. URL string `json:"url,omitempty"`
  436. Details string `json:"details,omitempty"`
  437. State string `json:"state,omitempty"`
  438. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  439. Assets Assets `json:"assets,omitempty"`
  440. ApplicationID string `json:"application_id,omitempty"`
  441. Instance int8 `json:"instance,omitempty"`
  442. // TODO: Party and Secrets (unknown structure)
  443. }
  444. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  445. type TimeStamps struct {
  446. EndTimestamp int64 `json:"end,omitempty"`
  447. StartTimestamp int64 `json:"start,omitempty"`
  448. }
  449. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  450. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  451. temp := struct {
  452. End float64 `json:"end,omitempty"`
  453. Start float64 `json:"start,omitempty"`
  454. }{}
  455. err := json.Unmarshal(b, &temp)
  456. if err != nil {
  457. return err
  458. }
  459. t.EndTimestamp = int64(temp.End)
  460. t.StartTimestamp = int64(temp.Start)
  461. return nil
  462. }
  463. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  464. type Assets struct {
  465. LargeImageID string `json:"large_image,omitempty"`
  466. SmallImageID string `json:"small_image,omitempty"`
  467. LargeText string `json:"large_text,omitempty"`
  468. SmallText string `json:"small_text,omitempty"`
  469. }
  470. // A Member stores user information for Guild members. A guild
  471. // member represents a certain user's presence in a guild.
  472. type Member struct {
  473. // The guild ID on which the member exists.
  474. GuildID string `json:"guild_id"`
  475. // The time at which the member joined the guild, in ISO8601.
  476. JoinedAt Timestamp `json:"joined_at"`
  477. // The nickname of the member, if they have one.
  478. Nick string `json:"nick"`
  479. // Whether the member is deafened at a guild level.
  480. Deaf bool `json:"deaf"`
  481. // Whether the member is muted at a guild level.
  482. Mute bool `json:"mute"`
  483. // The underlying user on which the member is based.
  484. User *User `json:"user"`
  485. // A list of IDs of the roles which are possessed by the member.
  486. Roles []string `json:"roles"`
  487. }
  488. // A Settings stores data for a specific users Discord client settings.
  489. type Settings struct {
  490. RenderEmbeds bool `json:"render_embeds"`
  491. InlineEmbedMedia bool `json:"inline_embed_media"`
  492. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  493. EnableTtsCommand bool `json:"enable_tts_command"`
  494. MessageDisplayCompact bool `json:"message_display_compact"`
  495. ShowCurrentGame bool `json:"show_current_game"`
  496. ConvertEmoticons bool `json:"convert_emoticons"`
  497. Locale string `json:"locale"`
  498. Theme string `json:"theme"`
  499. GuildPositions []string `json:"guild_positions"`
  500. RestrictedGuilds []string `json:"restricted_guilds"`
  501. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  502. Status Status `json:"status"`
  503. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  504. DeveloperMode bool `json:"developer_mode"`
  505. }
  506. // Status type definition
  507. type Status string
  508. // Constants for Status with the different current available status
  509. const (
  510. StatusOnline Status = "online"
  511. StatusIdle Status = "idle"
  512. StatusDoNotDisturb Status = "dnd"
  513. StatusInvisible Status = "invisible"
  514. StatusOffline Status = "offline"
  515. )
  516. // FriendSourceFlags stores ... TODO :)
  517. type FriendSourceFlags struct {
  518. All bool `json:"all"`
  519. MutualGuilds bool `json:"mutual_guilds"`
  520. MutualFriends bool `json:"mutual_friends"`
  521. }
  522. // A Relationship between the logged in user and Relationship.User
  523. type Relationship struct {
  524. User *User `json:"user"`
  525. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  526. ID string `json:"id"`
  527. }
  528. // A TooManyRequests struct holds information received from Discord
  529. // when receiving a HTTP 429 response.
  530. type TooManyRequests struct {
  531. Bucket string `json:"bucket"`
  532. Message string `json:"message"`
  533. RetryAfter time.Duration `json:"retry_after"`
  534. }
  535. // A ReadState stores data on the read state of channels.
  536. type ReadState struct {
  537. MentionCount int `json:"mention_count"`
  538. LastMessageID string `json:"last_message_id"`
  539. ID string `json:"id"`
  540. }
  541. // An Ack is used to ack messages
  542. type Ack struct {
  543. Token string `json:"token"`
  544. }
  545. // A GuildRole stores data for guild roles.
  546. type GuildRole struct {
  547. Role *Role `json:"role"`
  548. GuildID string `json:"guild_id"`
  549. }
  550. // A GuildBan stores data for a guild ban.
  551. type GuildBan struct {
  552. Reason string `json:"reason"`
  553. User *User `json:"user"`
  554. }
  555. // A GuildEmbed stores data for a guild embed.
  556. type GuildEmbed struct {
  557. Enabled bool `json:"enabled"`
  558. ChannelID string `json:"channel_id"`
  559. }
  560. // A GuildAuditLog stores data for a guild audit log.
  561. type GuildAuditLog struct {
  562. Webhooks []struct {
  563. ChannelID string `json:"channel_id"`
  564. GuildID string `json:"guild_id"`
  565. ID string `json:"id"`
  566. Avatar string `json:"avatar"`
  567. Name string `json:"name"`
  568. } `json:"webhooks,omitempty"`
  569. Users []struct {
  570. Username string `json:"username"`
  571. Discriminator string `json:"discriminator"`
  572. Bot bool `json:"bot"`
  573. ID string `json:"id"`
  574. Avatar string `json:"avatar"`
  575. } `json:"users,omitempty"`
  576. AuditLogEntries []struct {
  577. TargetID string `json:"target_id"`
  578. Changes []struct {
  579. NewValue interface{} `json:"new_value"`
  580. OldValue interface{} `json:"old_value"`
  581. Key string `json:"key"`
  582. } `json:"changes,omitempty"`
  583. UserID string `json:"user_id"`
  584. ID string `json:"id"`
  585. ActionType int `json:"action_type"`
  586. Options struct {
  587. DeleteMembersDay string `json:"delete_member_days"`
  588. MembersRemoved string `json:"members_removed"`
  589. ChannelID string `json:"channel_id"`
  590. Count string `json:"count"`
  591. ID string `json:"id"`
  592. Type string `json:"type"`
  593. RoleName string `json:"role_name"`
  594. } `json:"options,omitempty"`
  595. Reason string `json:"reason"`
  596. } `json:"audit_log_entries"`
  597. }
  598. // Block contains Discord Audit Log Action Types
  599. const (
  600. AuditLogActionGuildUpdate = 1
  601. AuditLogActionChannelCreate = 10
  602. AuditLogActionChannelUpdate = 11
  603. AuditLogActionChannelDelete = 12
  604. AuditLogActionChannelOverwriteCreate = 13
  605. AuditLogActionChannelOverwriteUpdate = 14
  606. AuditLogActionChannelOverwriteDelete = 15
  607. AuditLogActionMemberKick = 20
  608. AuditLogActionMemberPrune = 21
  609. AuditLogActionMemberBanAdd = 22
  610. AuditLogActionMemberBanRemove = 23
  611. AuditLogActionMemberUpdate = 24
  612. AuditLogActionMemberRoleUpdate = 25
  613. AuditLogActionRoleCreate = 30
  614. AuditLogActionRoleUpdate = 31
  615. AuditLogActionRoleDelete = 32
  616. AuditLogActionInviteCreate = 40
  617. AuditLogActionInviteUpdate = 41
  618. AuditLogActionInviteDelete = 42
  619. AuditLogActionWebhookCreate = 50
  620. AuditLogActionWebhookUpdate = 51
  621. AuditLogActionWebhookDelete = 52
  622. AuditLogActionEmojiCreate = 60
  623. AuditLogActionEmojiUpdate = 61
  624. AuditLogActionEmojiDelete = 62
  625. AuditLogActionMessageDelete = 72
  626. )
  627. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  628. type UserGuildSettingsChannelOverride struct {
  629. Muted bool `json:"muted"`
  630. MessageNotifications int `json:"message_notifications"`
  631. ChannelID string `json:"channel_id"`
  632. }
  633. // A UserGuildSettings stores data for a users guild settings.
  634. type UserGuildSettings struct {
  635. SupressEveryone bool `json:"suppress_everyone"`
  636. Muted bool `json:"muted"`
  637. MobilePush bool `json:"mobile_push"`
  638. MessageNotifications int `json:"message_notifications"`
  639. GuildID string `json:"guild_id"`
  640. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  641. }
  642. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  643. type UserGuildSettingsEdit struct {
  644. SupressEveryone bool `json:"suppress_everyone"`
  645. Muted bool `json:"muted"`
  646. MobilePush bool `json:"mobile_push"`
  647. MessageNotifications int `json:"message_notifications"`
  648. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  649. }
  650. // An APIErrorMessage is an api error message returned from discord
  651. type APIErrorMessage struct {
  652. Code int `json:"code"`
  653. Message string `json:"message"`
  654. }
  655. // Webhook stores the data for a webhook.
  656. type Webhook struct {
  657. ID string `json:"id"`
  658. GuildID string `json:"guild_id"`
  659. ChannelID string `json:"channel_id"`
  660. User *User `json:"user"`
  661. Name string `json:"name"`
  662. Avatar string `json:"avatar"`
  663. Token string `json:"token"`
  664. }
  665. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  666. type WebhookParams struct {
  667. Content string `json:"content,omitempty"`
  668. Username string `json:"username,omitempty"`
  669. AvatarURL string `json:"avatar_url,omitempty"`
  670. TTS bool `json:"tts,omitempty"`
  671. File string `json:"file,omitempty"`
  672. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  673. }
  674. // MessageReaction stores the data for a message reaction.
  675. type MessageReaction struct {
  676. UserID string `json:"user_id"`
  677. MessageID string `json:"message_id"`
  678. Emoji Emoji `json:"emoji"`
  679. ChannelID string `json:"channel_id"`
  680. GuildID string `json:"guild_id,omitempty"`
  681. }
  682. // GatewayBotResponse stores the data for the gateway/bot response
  683. type GatewayBotResponse struct {
  684. URL string `json:"url"`
  685. Shards int `json:"shards"`
  686. }
  687. // Constants for the different bit offsets of text channel permissions
  688. const (
  689. PermissionReadMessages = 1 << (iota + 10)
  690. PermissionSendMessages
  691. PermissionSendTTSMessages
  692. PermissionManageMessages
  693. PermissionEmbedLinks
  694. PermissionAttachFiles
  695. PermissionReadMessageHistory
  696. PermissionMentionEveryone
  697. PermissionUseExternalEmojis
  698. )
  699. // Constants for the different bit offsets of voice permissions
  700. const (
  701. PermissionVoiceConnect = 1 << (iota + 20)
  702. PermissionVoiceSpeak
  703. PermissionVoiceMuteMembers
  704. PermissionVoiceDeafenMembers
  705. PermissionVoiceMoveMembers
  706. PermissionVoiceUseVAD
  707. )
  708. // Constants for general management.
  709. const (
  710. PermissionChangeNickname = 1 << (iota + 26)
  711. PermissionManageNicknames
  712. PermissionManageRoles
  713. PermissionManageWebhooks
  714. PermissionManageEmojis
  715. )
  716. // Constants for the different bit offsets of general permissions
  717. const (
  718. PermissionCreateInstantInvite = 1 << iota
  719. PermissionKickMembers
  720. PermissionBanMembers
  721. PermissionAdministrator
  722. PermissionManageChannels
  723. PermissionManageServer
  724. PermissionAddReactions
  725. PermissionViewAuditLogs
  726. PermissionAllText = PermissionReadMessages |
  727. PermissionSendMessages |
  728. PermissionSendTTSMessages |
  729. PermissionManageMessages |
  730. PermissionEmbedLinks |
  731. PermissionAttachFiles |
  732. PermissionReadMessageHistory |
  733. PermissionMentionEveryone
  734. PermissionAllVoice = PermissionVoiceConnect |
  735. PermissionVoiceSpeak |
  736. PermissionVoiceMuteMembers |
  737. PermissionVoiceDeafenMembers |
  738. PermissionVoiceMoveMembers |
  739. PermissionVoiceUseVAD
  740. PermissionAllChannel = PermissionAllText |
  741. PermissionAllVoice |
  742. PermissionCreateInstantInvite |
  743. PermissionManageRoles |
  744. PermissionManageChannels |
  745. PermissionAddReactions |
  746. PermissionViewAuditLogs
  747. PermissionAll = PermissionAllChannel |
  748. PermissionKickMembers |
  749. PermissionBanMembers |
  750. PermissionManageServer |
  751. PermissionAdministrator
  752. )
  753. // Block contains Discord JSON Error Response codes
  754. const (
  755. ErrCodeUnknownAccount = 10001
  756. ErrCodeUnknownApplication = 10002
  757. ErrCodeUnknownChannel = 10003
  758. ErrCodeUnknownGuild = 10004
  759. ErrCodeUnknownIntegration = 10005
  760. ErrCodeUnknownInvite = 10006
  761. ErrCodeUnknownMember = 10007
  762. ErrCodeUnknownMessage = 10008
  763. ErrCodeUnknownOverwrite = 10009
  764. ErrCodeUnknownProvider = 10010
  765. ErrCodeUnknownRole = 10011
  766. ErrCodeUnknownToken = 10012
  767. ErrCodeUnknownUser = 10013
  768. ErrCodeUnknownEmoji = 10014
  769. ErrCodeBotsCannotUseEndpoint = 20001
  770. ErrCodeOnlyBotsCanUseEndpoint = 20002
  771. ErrCodeMaximumGuildsReached = 30001
  772. ErrCodeMaximumFriendsReached = 30002
  773. ErrCodeMaximumPinsReached = 30003
  774. ErrCodeMaximumGuildRolesReached = 30005
  775. ErrCodeTooManyReactions = 30010
  776. ErrCodeUnauthorized = 40001
  777. ErrCodeMissingAccess = 50001
  778. ErrCodeInvalidAccountType = 50002
  779. ErrCodeCannotExecuteActionOnDMChannel = 50003
  780. ErrCodeEmbedCisabled = 50004
  781. ErrCodeCannotEditFromAnotherUser = 50005
  782. ErrCodeCannotSendEmptyMessage = 50006
  783. ErrCodeCannotSendMessagesToThisUser = 50007
  784. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  785. ErrCodeChannelVerificationLevelTooHigh = 50009
  786. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  787. ErrCodeOAuth2ApplicationLimitReached = 50011
  788. ErrCodeInvalidOAuthState = 50012
  789. ErrCodeMissingPermissions = 50013
  790. ErrCodeInvalidAuthenticationToken = 50014
  791. ErrCodeNoteTooLong = 50015
  792. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  793. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  794. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  795. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  796. ErrCodeInvalidFormBody = 50035
  797. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  798. ErrCodeReactionBlocked = 90001
  799. )