structs.go 32 KB

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