structs.go 31 KB

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