structs.go 30 KB

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