structs.go 31 KB

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