structs.go 32 KB

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