structs.go 32 KB

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