structs.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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. Intents *Intent `json:"intents,omitempty"`
  783. }
  784. // IdentifyProperties contains the "properties" portion of an Identify packet
  785. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  786. type IdentifyProperties struct {
  787. OS string `json:"$os"`
  788. Browser string `json:"$browser"`
  789. Device string `json:"$device"`
  790. Referer string `json:"$referer"`
  791. ReferringDomain string `json:"$referring_domain"`
  792. }
  793. // Constants for the different bit offsets of text channel permissions
  794. const (
  795. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  796. PermissionReadMessages = 1 << (iota + 10)
  797. PermissionSendMessages
  798. PermissionSendTTSMessages
  799. PermissionManageMessages
  800. PermissionEmbedLinks
  801. PermissionAttachFiles
  802. PermissionReadMessageHistory
  803. PermissionMentionEveryone
  804. PermissionUseExternalEmojis
  805. )
  806. // Constants for the different bit offsets of voice permissions
  807. const (
  808. PermissionVoiceConnect = 1 << (iota + 20)
  809. PermissionVoiceSpeak
  810. PermissionVoiceMuteMembers
  811. PermissionVoiceDeafenMembers
  812. PermissionVoiceMoveMembers
  813. PermissionVoiceUseVAD
  814. PermissionVoicePrioritySpeaker = 1 << (iota + 2)
  815. )
  816. // Constants for general management.
  817. const (
  818. PermissionChangeNickname = 1 << (iota + 26)
  819. PermissionManageNicknames
  820. PermissionManageRoles
  821. PermissionManageWebhooks
  822. PermissionManageEmojis
  823. )
  824. // Constants for the different bit offsets of general permissions
  825. const (
  826. PermissionCreateInstantInvite = 1 << iota
  827. PermissionKickMembers
  828. PermissionBanMembers
  829. PermissionAdministrator
  830. PermissionManageChannels
  831. PermissionManageServer
  832. PermissionAddReactions
  833. PermissionViewAuditLogs
  834. PermissionViewChannel = 1 << (iota + 2)
  835. PermissionAllText = PermissionViewChannel |
  836. PermissionSendMessages |
  837. PermissionSendTTSMessages |
  838. PermissionManageMessages |
  839. PermissionEmbedLinks |
  840. PermissionAttachFiles |
  841. PermissionReadMessageHistory |
  842. PermissionMentionEveryone
  843. PermissionAllVoice = PermissionViewChannel |
  844. PermissionVoiceConnect |
  845. PermissionVoiceSpeak |
  846. PermissionVoiceMuteMembers |
  847. PermissionVoiceDeafenMembers |
  848. PermissionVoiceMoveMembers |
  849. PermissionVoiceUseVAD |
  850. PermissionVoicePrioritySpeaker
  851. PermissionAllChannel = PermissionAllText |
  852. PermissionAllVoice |
  853. PermissionCreateInstantInvite |
  854. PermissionManageRoles |
  855. PermissionManageChannels |
  856. PermissionAddReactions |
  857. PermissionViewAuditLogs
  858. PermissionAll = PermissionAllChannel |
  859. PermissionKickMembers |
  860. PermissionBanMembers |
  861. PermissionManageServer |
  862. PermissionAdministrator |
  863. PermissionManageWebhooks |
  864. PermissionManageEmojis
  865. )
  866. // Block contains Discord JSON Error Response codes
  867. const (
  868. ErrCodeUnknownAccount = 10001
  869. ErrCodeUnknownApplication = 10002
  870. ErrCodeUnknownChannel = 10003
  871. ErrCodeUnknownGuild = 10004
  872. ErrCodeUnknownIntegration = 10005
  873. ErrCodeUnknownInvite = 10006
  874. ErrCodeUnknownMember = 10007
  875. ErrCodeUnknownMessage = 10008
  876. ErrCodeUnknownOverwrite = 10009
  877. ErrCodeUnknownProvider = 10010
  878. ErrCodeUnknownRole = 10011
  879. ErrCodeUnknownToken = 10012
  880. ErrCodeUnknownUser = 10013
  881. ErrCodeUnknownEmoji = 10014
  882. ErrCodeUnknownWebhook = 10015
  883. ErrCodeBotsCannotUseEndpoint = 20001
  884. ErrCodeOnlyBotsCanUseEndpoint = 20002
  885. ErrCodeMaximumGuildsReached = 30001
  886. ErrCodeMaximumFriendsReached = 30002
  887. ErrCodeMaximumPinsReached = 30003
  888. ErrCodeMaximumGuildRolesReached = 30005
  889. ErrCodeTooManyReactions = 30010
  890. ErrCodeUnauthorized = 40001
  891. ErrCodeMissingAccess = 50001
  892. ErrCodeInvalidAccountType = 50002
  893. ErrCodeCannotExecuteActionOnDMChannel = 50003
  894. ErrCodeEmbedDisabled = 50004
  895. ErrCodeCannotEditFromAnotherUser = 50005
  896. ErrCodeCannotSendEmptyMessage = 50006
  897. ErrCodeCannotSendMessagesToThisUser = 50007
  898. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  899. ErrCodeChannelVerificationLevelTooHigh = 50009
  900. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  901. ErrCodeOAuth2ApplicationLimitReached = 50011
  902. ErrCodeInvalidOAuthState = 50012
  903. ErrCodeMissingPermissions = 50013
  904. ErrCodeInvalidAuthenticationToken = 50014
  905. ErrCodeNoteTooLong = 50015
  906. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  907. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  908. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  909. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  910. ErrCodeInvalidFormBody = 50035
  911. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  912. ErrCodeReactionBlocked = 90001
  913. )
  914. // Intent is the type of a Gateway Intent
  915. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  916. type Intent int
  917. // Constants for the different bit offsets of intents
  918. const (
  919. IntentsGuilds Intent = 1 << iota
  920. IntentsGuildMembers
  921. IntentsGuildBans
  922. IntentsGuildEmojis
  923. IntentsGuildIntegrations
  924. IntentsGuildWebhooks
  925. IntentsGuildInvites
  926. IntentsGuildVoiceStates
  927. IntentsGuildPresences
  928. IntentsGuildMessages
  929. IntentsGuildMessageReactions
  930. IntentsGuildMessageTyping
  931. IntentsDirectMessages
  932. IntentsDirectMessageReactions
  933. IntentsDirectMessageTyping
  934. IntentsAllWithoutPrivileged = IntentsGuilds |
  935. IntentsGuildBans |
  936. IntentsGuildEmojis |
  937. IntentsGuildIntegrations |
  938. IntentsGuildWebhooks |
  939. IntentsGuildInvites |
  940. IntentsGuildVoiceStates |
  941. IntentsGuildMessages |
  942. IntentsGuildMessageReactions |
  943. IntentsGuildMessageTyping |
  944. IntentsDirectMessages |
  945. IntentsDirectMessageReactions |
  946. IntentsDirectMessageTyping
  947. IntentsAll = IntentsAllWithoutPrivileged |
  948. IntentsGuildMembers |
  949. IntentsGuildPresences
  950. IntentsNone Intent = 0
  951. )
  952. // MakeIntent helps convert a gateway intent value for use in the Identify structure.
  953. func MakeIntent(intents Intent) *Intent {
  954. return &intents
  955. }