structs.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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://discordapp.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. Nick string `json:"nick"`
  469. Roles []string `json:"roles"`
  470. Since *int `json:"since"`
  471. }
  472. // GameType is the type of "game" (see GameType* consts) in the Game struct
  473. type GameType int
  474. // Valid GameType values
  475. const (
  476. GameTypeGame GameType = iota
  477. GameTypeStreaming
  478. GameTypeListening
  479. GameTypeWatching
  480. )
  481. // A Game struct holds the name of the "playing .." game for a user
  482. type Game struct {
  483. Name string `json:"name"`
  484. Type GameType `json:"type"`
  485. URL string `json:"url,omitempty"`
  486. Details string `json:"details,omitempty"`
  487. State string `json:"state,omitempty"`
  488. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  489. Assets Assets `json:"assets,omitempty"`
  490. ApplicationID string `json:"application_id,omitempty"`
  491. Instance int8 `json:"instance,omitempty"`
  492. // TODO: Party and Secrets (unknown structure)
  493. }
  494. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  495. type TimeStamps struct {
  496. EndTimestamp int64 `json:"end,omitempty"`
  497. StartTimestamp int64 `json:"start,omitempty"`
  498. }
  499. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  500. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  501. temp := struct {
  502. End float64 `json:"end,omitempty"`
  503. Start float64 `json:"start,omitempty"`
  504. }{}
  505. err := json.Unmarshal(b, &temp)
  506. if err != nil {
  507. return err
  508. }
  509. t.EndTimestamp = int64(temp.End)
  510. t.StartTimestamp = int64(temp.Start)
  511. return nil
  512. }
  513. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  514. type Assets struct {
  515. LargeImageID string `json:"large_image,omitempty"`
  516. SmallImageID string `json:"small_image,omitempty"`
  517. LargeText string `json:"large_text,omitempty"`
  518. SmallText string `json:"small_text,omitempty"`
  519. }
  520. // A Member stores user information for Guild members. A guild
  521. // member represents a certain user's presence in a guild.
  522. type Member struct {
  523. // The guild ID on which the member exists.
  524. GuildID string `json:"guild_id"`
  525. // The time at which the member joined the guild, in ISO8601.
  526. JoinedAt Timestamp `json:"joined_at"`
  527. // The nickname of the member, if they have one.
  528. Nick string `json:"nick"`
  529. // Whether the member is deafened at a guild level.
  530. Deaf bool `json:"deaf"`
  531. // Whether the member is muted at a guild level.
  532. Mute bool `json:"mute"`
  533. // The underlying user on which the member is based.
  534. User *User `json:"user"`
  535. // A list of IDs of the roles which are possessed by the member.
  536. Roles []string `json:"roles"`
  537. // When the user used their Nitro boost on the server
  538. PremiumSince Timestamp `json:"premium_since"`
  539. }
  540. // Mention creates a member mention
  541. func (m *Member) Mention() string {
  542. return "<@!" + m.User.ID + ">"
  543. }
  544. // A Settings stores data for a specific users Discord client settings.
  545. type Settings struct {
  546. RenderEmbeds bool `json:"render_embeds"`
  547. InlineEmbedMedia bool `json:"inline_embed_media"`
  548. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  549. EnableTTSCommand bool `json:"enable_tts_command"`
  550. MessageDisplayCompact bool `json:"message_display_compact"`
  551. ShowCurrentGame bool `json:"show_current_game"`
  552. ConvertEmoticons bool `json:"convert_emoticons"`
  553. Locale string `json:"locale"`
  554. Theme string `json:"theme"`
  555. GuildPositions []string `json:"guild_positions"`
  556. RestrictedGuilds []string `json:"restricted_guilds"`
  557. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  558. Status Status `json:"status"`
  559. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  560. DeveloperMode bool `json:"developer_mode"`
  561. }
  562. // Status type definition
  563. type Status string
  564. // Constants for Status with the different current available status
  565. const (
  566. StatusOnline Status = "online"
  567. StatusIdle Status = "idle"
  568. StatusDoNotDisturb Status = "dnd"
  569. StatusInvisible Status = "invisible"
  570. StatusOffline Status = "offline"
  571. )
  572. // FriendSourceFlags stores ... TODO :)
  573. type FriendSourceFlags struct {
  574. All bool `json:"all"`
  575. MutualGuilds bool `json:"mutual_guilds"`
  576. MutualFriends bool `json:"mutual_friends"`
  577. }
  578. // A Relationship between the logged in user and Relationship.User
  579. type Relationship struct {
  580. User *User `json:"user"`
  581. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  582. ID string `json:"id"`
  583. }
  584. // A TooManyRequests struct holds information received from Discord
  585. // when receiving a HTTP 429 response.
  586. type TooManyRequests struct {
  587. Bucket string `json:"bucket"`
  588. Message string `json:"message"`
  589. RetryAfter time.Duration `json:"retry_after"`
  590. }
  591. // A ReadState stores data on the read state of channels.
  592. type ReadState struct {
  593. MentionCount int `json:"mention_count"`
  594. LastMessageID string `json:"last_message_id"`
  595. ID string `json:"id"`
  596. }
  597. // An Ack is used to ack messages
  598. type Ack struct {
  599. Token string `json:"token"`
  600. }
  601. // A GuildRole stores data for guild roles.
  602. type GuildRole struct {
  603. Role *Role `json:"role"`
  604. GuildID string `json:"guild_id"`
  605. }
  606. // A GuildBan stores data for a guild ban.
  607. type GuildBan struct {
  608. Reason string `json:"reason"`
  609. User *User `json:"user"`
  610. }
  611. // A GuildEmbed stores data for a guild embed.
  612. type GuildEmbed struct {
  613. Enabled bool `json:"enabled"`
  614. ChannelID string `json:"channel_id"`
  615. }
  616. // A GuildAuditLog stores data for a guild audit log.
  617. type GuildAuditLog struct {
  618. Webhooks []struct {
  619. ChannelID string `json:"channel_id"`
  620. GuildID string `json:"guild_id"`
  621. ID string `json:"id"`
  622. Avatar string `json:"avatar"`
  623. Name string `json:"name"`
  624. } `json:"webhooks,omitempty"`
  625. Users []struct {
  626. Username string `json:"username"`
  627. Discriminator string `json:"discriminator"`
  628. Bot bool `json:"bot"`
  629. ID string `json:"id"`
  630. Avatar string `json:"avatar"`
  631. } `json:"users,omitempty"`
  632. AuditLogEntries []struct {
  633. TargetID string `json:"target_id"`
  634. Changes []struct {
  635. NewValue interface{} `json:"new_value"`
  636. OldValue interface{} `json:"old_value"`
  637. Key string `json:"key"`
  638. } `json:"changes,omitempty"`
  639. UserID string `json:"user_id"`
  640. ID string `json:"id"`
  641. ActionType int `json:"action_type"`
  642. Options struct {
  643. DeleteMembersDay string `json:"delete_member_days"`
  644. MembersRemoved string `json:"members_removed"`
  645. ChannelID string `json:"channel_id"`
  646. Count string `json:"count"`
  647. ID string `json:"id"`
  648. Type string `json:"type"`
  649. RoleName string `json:"role_name"`
  650. } `json:"options,omitempty"`
  651. Reason string `json:"reason"`
  652. } `json:"audit_log_entries"`
  653. }
  654. // Block contains Discord Audit Log Action Types
  655. const (
  656. AuditLogActionGuildUpdate = 1
  657. AuditLogActionChannelCreate = 10
  658. AuditLogActionChannelUpdate = 11
  659. AuditLogActionChannelDelete = 12
  660. AuditLogActionChannelOverwriteCreate = 13
  661. AuditLogActionChannelOverwriteUpdate = 14
  662. AuditLogActionChannelOverwriteDelete = 15
  663. AuditLogActionMemberKick = 20
  664. AuditLogActionMemberPrune = 21
  665. AuditLogActionMemberBanAdd = 22
  666. AuditLogActionMemberBanRemove = 23
  667. AuditLogActionMemberUpdate = 24
  668. AuditLogActionMemberRoleUpdate = 25
  669. AuditLogActionRoleCreate = 30
  670. AuditLogActionRoleUpdate = 31
  671. AuditLogActionRoleDelete = 32
  672. AuditLogActionInviteCreate = 40
  673. AuditLogActionInviteUpdate = 41
  674. AuditLogActionInviteDelete = 42
  675. AuditLogActionWebhookCreate = 50
  676. AuditLogActionWebhookUpdate = 51
  677. AuditLogActionWebhookDelete = 52
  678. AuditLogActionEmojiCreate = 60
  679. AuditLogActionEmojiUpdate = 61
  680. AuditLogActionEmojiDelete = 62
  681. AuditLogActionMessageDelete = 72
  682. )
  683. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  684. type UserGuildSettingsChannelOverride struct {
  685. Muted bool `json:"muted"`
  686. MessageNotifications int `json:"message_notifications"`
  687. ChannelID string `json:"channel_id"`
  688. }
  689. // A UserGuildSettings stores data for a users guild settings.
  690. type UserGuildSettings 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. GuildID string `json:"guild_id"`
  696. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  697. }
  698. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  699. type UserGuildSettingsEdit struct {
  700. SupressEveryone bool `json:"suppress_everyone"`
  701. Muted bool `json:"muted"`
  702. MobilePush bool `json:"mobile_push"`
  703. MessageNotifications int `json:"message_notifications"`
  704. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  705. }
  706. // An APIErrorMessage is an api error message returned from discord
  707. type APIErrorMessage struct {
  708. Code int `json:"code"`
  709. Message string `json:"message"`
  710. }
  711. // Webhook stores the data for a webhook.
  712. type Webhook struct {
  713. ID string `json:"id"`
  714. GuildID string `json:"guild_id"`
  715. ChannelID string `json:"channel_id"`
  716. User *User `json:"user"`
  717. Name string `json:"name"`
  718. Avatar string `json:"avatar"`
  719. Token string `json:"token"`
  720. }
  721. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  722. type WebhookParams struct {
  723. Content string `json:"content,omitempty"`
  724. Username string `json:"username,omitempty"`
  725. AvatarURL string `json:"avatar_url,omitempty"`
  726. TTS bool `json:"tts,omitempty"`
  727. File string `json:"file,omitempty"`
  728. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  729. }
  730. // MessageReaction stores the data for a message reaction.
  731. type MessageReaction struct {
  732. UserID string `json:"user_id"`
  733. MessageID string `json:"message_id"`
  734. Emoji Emoji `json:"emoji"`
  735. ChannelID string `json:"channel_id"`
  736. GuildID string `json:"guild_id,omitempty"`
  737. }
  738. // GatewayBotResponse stores the data for the gateway/bot response
  739. type GatewayBotResponse struct {
  740. URL string `json:"url"`
  741. Shards int `json:"shards"`
  742. }
  743. // Gateway Status Update is sent by the client to indicate a presence or status update
  744. // https://discordapp.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  745. type GatewayStatusUpdate struct {
  746. Since int `json:"since"`
  747. Game Activity `json:"game"`
  748. Status string `json:"status"`
  749. AFK bool `json:"afk"`
  750. }
  751. type Activity struct {
  752. Name string
  753. Type ActivityType
  754. URL string
  755. }
  756. // GameType is the type of "game" (see GameType* consts) in the Game struct
  757. // https://discordapp.com/developers/docs/topics/gateway#activity-object-activity-types
  758. type ActivityType int
  759. // Valid GameType values
  760. const (
  761. ActivityTypeGame GameType = iota
  762. ActivityTypeStreaming
  763. ActivityTypeListening
  764. // ActivityTypeWatching // not valid in the use?
  765. ActivityTypeCustom = 4
  766. )
  767. // Identify is sent during initial handshake with the discord gateway.
  768. // https://discordapp.com/developers/docs/topics/gateway#identify
  769. type Identify struct {
  770. Token string `json:"token"`
  771. Properties IdentifyProperties `json:"properties"`
  772. Compress bool `json:"compress"`
  773. LargeThreshold int `json:"large_threshold"`
  774. Shard *[2]int `json:"shard,omitempty"`
  775. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  776. GuildSubscriptions bool `json:"guild_subscriptions"`
  777. }
  778. type IdentifyProperties struct {
  779. OS string `json:"$os"`
  780. Browser string `json:"$browser"`
  781. Device string `json:"$device"`
  782. Referer string `json:"$referer"`
  783. ReferringDomain string `json:"$referring_domain"`
  784. }
  785. // Constants for the different bit offsets of text channel permissions
  786. const (
  787. PermissionReadMessages = 1 << (iota + 10)
  788. PermissionSendMessages
  789. PermissionSendTTSMessages
  790. PermissionManageMessages
  791. PermissionEmbedLinks
  792. PermissionAttachFiles
  793. PermissionReadMessageHistory
  794. PermissionMentionEveryone
  795. PermissionUseExternalEmojis
  796. )
  797. // Constants for the different bit offsets of voice permissions
  798. const (
  799. PermissionVoiceConnect = 1 << (iota + 20)
  800. PermissionVoiceSpeak
  801. PermissionVoiceMuteMembers
  802. PermissionVoiceDeafenMembers
  803. PermissionVoiceMoveMembers
  804. PermissionVoiceUseVAD
  805. PermissionVoicePrioritySpeaker = 1 << (iota + 2)
  806. )
  807. // Constants for general management.
  808. const (
  809. PermissionChangeNickname = 1 << (iota + 26)
  810. PermissionManageNicknames
  811. PermissionManageRoles
  812. PermissionManageWebhooks
  813. PermissionManageEmojis
  814. )
  815. // Constants for the different bit offsets of general permissions
  816. const (
  817. PermissionCreateInstantInvite = 1 << iota
  818. PermissionKickMembers
  819. PermissionBanMembers
  820. PermissionAdministrator
  821. PermissionManageChannels
  822. PermissionManageServer
  823. PermissionAddReactions
  824. PermissionViewAuditLogs
  825. PermissionAllText = PermissionReadMessages |
  826. PermissionSendMessages |
  827. PermissionSendTTSMessages |
  828. PermissionManageMessages |
  829. PermissionEmbedLinks |
  830. PermissionAttachFiles |
  831. PermissionReadMessageHistory |
  832. PermissionMentionEveryone
  833. PermissionAllVoice = PermissionVoiceConnect |
  834. PermissionVoiceSpeak |
  835. PermissionVoiceMuteMembers |
  836. PermissionVoiceDeafenMembers |
  837. PermissionVoiceMoveMembers |
  838. PermissionVoiceUseVAD |
  839. PermissionVoicePrioritySpeaker
  840. PermissionAllChannel = PermissionAllText |
  841. PermissionAllVoice |
  842. PermissionCreateInstantInvite |
  843. PermissionManageRoles |
  844. PermissionManageChannels |
  845. PermissionAddReactions |
  846. PermissionViewAuditLogs
  847. PermissionAll = PermissionAllChannel |
  848. PermissionKickMembers |
  849. PermissionBanMembers |
  850. PermissionManageServer |
  851. PermissionAdministrator |
  852. PermissionManageWebhooks |
  853. PermissionManageEmojis
  854. )
  855. // Block contains Discord JSON Error Response codes
  856. const (
  857. ErrCodeUnknownAccount = 10001
  858. ErrCodeUnknownApplication = 10002
  859. ErrCodeUnknownChannel = 10003
  860. ErrCodeUnknownGuild = 10004
  861. ErrCodeUnknownIntegration = 10005
  862. ErrCodeUnknownInvite = 10006
  863. ErrCodeUnknownMember = 10007
  864. ErrCodeUnknownMessage = 10008
  865. ErrCodeUnknownOverwrite = 10009
  866. ErrCodeUnknownProvider = 10010
  867. ErrCodeUnknownRole = 10011
  868. ErrCodeUnknownToken = 10012
  869. ErrCodeUnknownUser = 10013
  870. ErrCodeUnknownEmoji = 10014
  871. ErrCodeUnknownWebhook = 10015
  872. ErrCodeBotsCannotUseEndpoint = 20001
  873. ErrCodeOnlyBotsCanUseEndpoint = 20002
  874. ErrCodeMaximumGuildsReached = 30001
  875. ErrCodeMaximumFriendsReached = 30002
  876. ErrCodeMaximumPinsReached = 30003
  877. ErrCodeMaximumGuildRolesReached = 30005
  878. ErrCodeTooManyReactions = 30010
  879. ErrCodeUnauthorized = 40001
  880. ErrCodeMissingAccess = 50001
  881. ErrCodeInvalidAccountType = 50002
  882. ErrCodeCannotExecuteActionOnDMChannel = 50003
  883. ErrCodeEmbedDisabled = 50004
  884. ErrCodeCannotEditFromAnotherUser = 50005
  885. ErrCodeCannotSendEmptyMessage = 50006
  886. ErrCodeCannotSendMessagesToThisUser = 50007
  887. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  888. ErrCodeChannelVerificationLevelTooHigh = 50009
  889. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  890. ErrCodeOAuth2ApplicationLimitReached = 50011
  891. ErrCodeInvalidOAuthState = 50012
  892. ErrCodeMissingPermissions = 50013
  893. ErrCodeInvalidAuthenticationToken = 50014
  894. ErrCodeNoteTooLong = 50015
  895. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  896. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  897. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  898. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  899. ErrCodeInvalidFormBody = 50035
  900. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  901. ErrCodeReactionBlocked = 90001
  902. )