structs.go 32 KB

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