structs.go 32 KB

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