structs.go 31 KB

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