structs.go 30 KB

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