structs.go 35 KB

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