structs.go 31 KB

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