structs.go 32 KB

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