structs.go 32 KB

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