structs.go 32 KB

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