structs.go 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  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. "math"
  14. "net/http"
  15. "regexp"
  16. "strings"
  17. "sync"
  18. "time"
  19. "github.com/gorilla/websocket"
  20. )
  21. // A Session represents a connection to the Discord API.
  22. type Session struct {
  23. sync.RWMutex
  24. // General configurable settings.
  25. // Authentication token for this session
  26. // TODO: Remove Below, Deprecated, Use Identify struct
  27. Token string
  28. MFA bool
  29. // Debug for printing JSON request/responses
  30. Debug bool // Deprecated, will be removed.
  31. LogLevel int
  32. // Should the session reconnect the websocket on errors.
  33. ShouldReconnectOnError bool
  34. // Identify is sent during initial handshake with the discord gateway.
  35. // https://discord.com/developers/docs/topics/gateway#identify
  36. Identify Identify
  37. // TODO: Remove Below, Deprecated, Use Identify struct
  38. // Should the session request compressed websocket data.
  39. Compress bool
  40. // Sharding
  41. ShardID int
  42. ShardCount int
  43. // Should state tracking be enabled.
  44. // State tracking is the best way for getting the the users
  45. // active guilds and the members of the guilds.
  46. StateEnabled bool
  47. // Whether or not to call event handlers synchronously.
  48. // e.g false = launch event handlers in their own goroutines.
  49. SyncEvents bool
  50. // Exposed but should not be modified by User.
  51. // Whether the Data Websocket is ready
  52. DataReady bool // NOTE: Maye be deprecated soon
  53. // Max number of REST API retries
  54. MaxRestRetries int
  55. // Status stores the currect status of the websocket connection
  56. // this is being tested, may stay, may go away.
  57. status int32
  58. // Whether the Voice Websocket is ready
  59. VoiceReady bool // NOTE: Deprecated.
  60. // Whether the UDP Connection is ready
  61. UDPReady bool // NOTE: Deprecated
  62. // Stores a mapping of guild id's to VoiceConnections
  63. VoiceConnections map[string]*VoiceConnection
  64. // Managed state object, updated internally with events when
  65. // StateEnabled is true.
  66. State *State
  67. // The http client used for REST requests
  68. Client *http.Client
  69. // The user agent used for REST APIs
  70. UserAgent string
  71. // Stores the last HeartbeatAck that was received (in UTC)
  72. LastHeartbeatAck time.Time
  73. // Stores the last Heartbeat sent (in UTC)
  74. LastHeartbeatSent time.Time
  75. // used to deal with rate limits
  76. Ratelimiter *RateLimiter
  77. // Event handlers
  78. handlersMu sync.RWMutex
  79. handlers map[string][]*eventHandlerInstance
  80. onceHandlers map[string][]*eventHandlerInstance
  81. // The websocket connection.
  82. wsConn *websocket.Conn
  83. // When nil, the session is not listening.
  84. listening chan interface{}
  85. // sequence tracks the current gateway api websocket sequence number
  86. sequence *int64
  87. // stores sessions current Discord Gateway
  88. gateway string
  89. // stores session ID of current Gateway connection
  90. sessionID string
  91. // used to make sure gateway websocket writes do not happen concurrently
  92. wsMutex sync.Mutex
  93. }
  94. // UserConnection is a Connection returned from the UserConnections endpoint
  95. type UserConnection struct {
  96. ID string `json:"id"`
  97. Name string `json:"name"`
  98. Type string `json:"type"`
  99. Revoked bool `json:"revoked"`
  100. Integrations []*Integration `json:"integrations"`
  101. }
  102. // Integration stores integration information
  103. type Integration struct {
  104. ID string `json:"id"`
  105. Name string `json:"name"`
  106. Type string `json:"type"`
  107. Enabled bool `json:"enabled"`
  108. Syncing bool `json:"syncing"`
  109. RoleID string `json:"role_id"`
  110. EnableEmoticons bool `json:"enable_emoticons"`
  111. ExpireBehavior ExpireBehavior `json:"expire_behavior"`
  112. ExpireGracePeriod int `json:"expire_grace_period"`
  113. User *User `json:"user"`
  114. Account IntegrationAccount `json:"account"`
  115. SyncedAt Timestamp `json:"synced_at"`
  116. }
  117. // ExpireBehavior of Integration
  118. // https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
  119. type ExpireBehavior int
  120. // Block of valid ExpireBehaviors
  121. const (
  122. ExpireBehaviorRemoveRole ExpireBehavior = 0
  123. ExpireBehaviorKick ExpireBehavior = 1
  124. )
  125. // IntegrationAccount is integration account information
  126. // sent by the UserConnections endpoint
  127. type IntegrationAccount struct {
  128. ID string `json:"id"`
  129. Name string `json:"name"`
  130. }
  131. // A VoiceRegion stores data for a specific voice region server.
  132. type VoiceRegion struct {
  133. ID string `json:"id"`
  134. Name string `json:"name"`
  135. Hostname string `json:"sample_hostname"`
  136. Port int `json:"sample_port"`
  137. }
  138. // A VoiceICE stores data for voice ICE servers.
  139. type VoiceICE struct {
  140. TTL string `json:"ttl"`
  141. Servers []*ICEServer `json:"servers"`
  142. }
  143. // A ICEServer stores data for a specific voice ICE server.
  144. type ICEServer struct {
  145. URL string `json:"url"`
  146. Username string `json:"username"`
  147. Credential string `json:"credential"`
  148. }
  149. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  150. type Invite struct {
  151. Guild *Guild `json:"guild"`
  152. Channel *Channel `json:"channel"`
  153. Inviter *User `json:"inviter"`
  154. Code string `json:"code"`
  155. CreatedAt Timestamp `json:"created_at"`
  156. MaxAge int `json:"max_age"`
  157. Uses int `json:"uses"`
  158. MaxUses int `json:"max_uses"`
  159. Revoked bool `json:"revoked"`
  160. Temporary bool `json:"temporary"`
  161. Unique bool `json:"unique"`
  162. TargetUser *User `json:"target_user"`
  163. TargetUserType TargetUserType `json:"target_user_type"`
  164. // will only be filled when using InviteWithCounts
  165. ApproximatePresenceCount int `json:"approximate_presence_count"`
  166. ApproximateMemberCount int `json:"approximate_member_count"`
  167. }
  168. // TargetUserType is the type of the target user
  169. // https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
  170. type TargetUserType int
  171. // Block contains known TargetUserType values
  172. const (
  173. TargetUserTypeStream TargetUserType = 1
  174. )
  175. // ChannelType is the type of a Channel
  176. type ChannelType int
  177. // Block contains known ChannelType values
  178. const (
  179. ChannelTypeGuildText ChannelType = 0
  180. ChannelTypeDM ChannelType = 1
  181. ChannelTypeGuildVoice ChannelType = 2
  182. ChannelTypeGroupDM ChannelType = 3
  183. ChannelTypeGuildCategory ChannelType = 4
  184. ChannelTypeGuildNews ChannelType = 5
  185. ChannelTypeGuildStore ChannelType = 6
  186. )
  187. // A Channel holds all data related to an individual Discord channel.
  188. type Channel struct {
  189. // The ID of the channel.
  190. ID string `json:"id"`
  191. // The ID of the guild to which the channel belongs, if it is in a guild.
  192. // Else, this ID is empty (e.g. DM channels).
  193. GuildID string `json:"guild_id"`
  194. // The name of the channel.
  195. Name string `json:"name"`
  196. // The topic of the channel.
  197. Topic string `json:"topic"`
  198. // The type of the channel.
  199. Type ChannelType `json:"type"`
  200. // The ID of the last message sent in the channel. This is not
  201. // guaranteed to be an ID of a valid message.
  202. LastMessageID string `json:"last_message_id"`
  203. // The timestamp of the last pinned message in the channel.
  204. // Empty if the channel has no pinned messages.
  205. LastPinTimestamp Timestamp `json:"last_pin_timestamp"`
  206. // Whether the channel is marked as NSFW.
  207. NSFW bool `json:"nsfw"`
  208. // Icon of the group DM channel.
  209. Icon string `json:"icon"`
  210. // The position of the channel, used for sorting in client.
  211. Position int `json:"position"`
  212. // The bitrate of the channel, if it is a voice channel.
  213. Bitrate int `json:"bitrate"`
  214. // The recipients of the channel. This is only populated in DM channels.
  215. Recipients []*User `json:"recipients"`
  216. // The messages in the channel. This is only present in state-cached channels,
  217. // and State.MaxMessageCount must be non-zero.
  218. Messages []*Message `json:"-"`
  219. // A list of permission overwrites present for the channel.
  220. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  221. // The user limit of the voice channel.
  222. UserLimit int `json:"user_limit"`
  223. // The ID of the parent channel, if the channel is under a category
  224. ParentID string `json:"parent_id"`
  225. // Amount of seconds a user has to wait before sending another message (0-21600)
  226. // bots, as well as users with the permission manage_messages or manage_channel, are unaffected
  227. RateLimitPerUser int `json:"rate_limit_per_user"`
  228. // ID of the DM creator Zeroed if guild channel
  229. OwnerID string `json:"owner_id"`
  230. // ApplicationID of the DM creator Zeroed if guild channel or not a bot user
  231. ApplicationID string `json:"application_id"`
  232. }
  233. // Mention returns a string which mentions the channel
  234. func (c *Channel) Mention() string {
  235. return fmt.Sprintf("<#%s>", c.ID)
  236. }
  237. // A ChannelEdit holds Channel Field data for a channel edit.
  238. type ChannelEdit struct {
  239. Name string `json:"name,omitempty"`
  240. Topic string `json:"topic,omitempty"`
  241. NSFW bool `json:"nsfw,omitempty"`
  242. Position int `json:"position"`
  243. Bitrate int `json:"bitrate,omitempty"`
  244. UserLimit int `json:"user_limit,omitempty"`
  245. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  246. ParentID string `json:"parent_id,omitempty"`
  247. RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
  248. }
  249. // A ChannelFollow holds data returned after following a news channel
  250. type ChannelFollow struct {
  251. ChannelID string `json:"channel_id"`
  252. WebhookID string `json:"webhook_id"`
  253. }
  254. // PermissionOverwriteType represents the type of resource on which
  255. // a permission overwrite acts.
  256. type PermissionOverwriteType int
  257. // The possible permission overwrite types.
  258. const (
  259. PermissionOverwriteTypeRole PermissionOverwriteType = 0
  260. PermissionOverwriteTypeMember PermissionOverwriteType = 1
  261. )
  262. // A PermissionOverwrite holds permission overwrite data for a Channel
  263. type PermissionOverwrite struct {
  264. ID string `json:"id"`
  265. Type PermissionOverwriteType `json:"type"`
  266. Deny int64 `json:"deny,string"`
  267. Allow int64 `json:"allow,string"`
  268. }
  269. // Emoji struct holds data related to Emoji's
  270. type Emoji struct {
  271. ID string `json:"id"`
  272. Name string `json:"name"`
  273. Roles []string `json:"roles"`
  274. User *User `json:"user"`
  275. RequireColons bool `json:"require_colons"`
  276. Managed bool `json:"managed"`
  277. Animated bool `json:"animated"`
  278. Available bool `json:"available"`
  279. }
  280. // EmojiRegex is the regex used to find and identify emojis in messages
  281. var (
  282. EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18}>`)
  283. )
  284. // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
  285. func (e *Emoji) MessageFormat() string {
  286. if e.ID != "" && e.Name != "" {
  287. if e.Animated {
  288. return "<a:" + e.APIName() + ">"
  289. }
  290. return "<:" + e.APIName() + ">"
  291. }
  292. return e.APIName()
  293. }
  294. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  295. func (e *Emoji) APIName() string {
  296. if e.ID != "" && e.Name != "" {
  297. return e.Name + ":" + e.ID
  298. }
  299. if e.Name != "" {
  300. return e.Name
  301. }
  302. return e.ID
  303. }
  304. // VerificationLevel type definition
  305. type VerificationLevel int
  306. // Constants for VerificationLevel levels from 0 to 4 inclusive
  307. const (
  308. VerificationLevelNone VerificationLevel = 0
  309. VerificationLevelLow VerificationLevel = 1
  310. VerificationLevelMedium VerificationLevel = 2
  311. VerificationLevelHigh VerificationLevel = 3
  312. VerificationLevelVeryHigh VerificationLevel = 4
  313. )
  314. // ExplicitContentFilterLevel type definition
  315. type ExplicitContentFilterLevel int
  316. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  317. const (
  318. ExplicitContentFilterDisabled ExplicitContentFilterLevel = 0
  319. ExplicitContentFilterMembersWithoutRoles ExplicitContentFilterLevel = 1
  320. ExplicitContentFilterAllMembers ExplicitContentFilterLevel = 2
  321. )
  322. // MfaLevel type definition
  323. type MfaLevel int
  324. // Constants for MfaLevel levels from 0 to 1 inclusive
  325. const (
  326. MfaLevelNone MfaLevel = 0
  327. MfaLevelElevated MfaLevel = 1
  328. )
  329. // PremiumTier type definition
  330. type PremiumTier int
  331. // Constants for PremiumTier levels from 0 to 3 inclusive
  332. const (
  333. PremiumTierNone PremiumTier = 0
  334. PremiumTier1 PremiumTier = 1
  335. PremiumTier2 PremiumTier = 2
  336. PremiumTier3 PremiumTier = 3
  337. )
  338. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  339. // sometimes referred to as Servers in the Discord client.
  340. type Guild struct {
  341. // The ID of the guild.
  342. ID string `json:"id"`
  343. // The name of the guild. (2–100 characters)
  344. Name string `json:"name"`
  345. // The hash of the guild's icon. Use Session.GuildIcon
  346. // to retrieve the icon itself.
  347. Icon string `json:"icon"`
  348. // The voice region of the guild.
  349. Region string `json:"region"`
  350. // The ID of the AFK voice channel.
  351. AfkChannelID string `json:"afk_channel_id"`
  352. // The user ID of the owner of the guild.
  353. OwnerID string `json:"owner_id"`
  354. // If we are the owner of the guild
  355. Owner bool `json:"owner"`
  356. // The time at which the current user joined the guild.
  357. // This field is only present in GUILD_CREATE events and websocket
  358. // update events, and thus is only present in state-cached guilds.
  359. JoinedAt Timestamp `json:"joined_at"`
  360. // The hash of the guild's discovery splash.
  361. DiscoverySplash string `json:"discovery_splash"`
  362. // The hash of the guild's splash.
  363. Splash string `json:"splash"`
  364. // The timeout, in seconds, before a user is considered AFK in voice.
  365. AfkTimeout int `json:"afk_timeout"`
  366. // The number of members in the guild.
  367. // This field is only present in GUILD_CREATE events and websocket
  368. // update events, and thus is only present in state-cached guilds.
  369. MemberCount int `json:"member_count"`
  370. // The verification level required for the guild.
  371. VerificationLevel VerificationLevel `json:"verification_level"`
  372. // Whether the guild is considered large. This is
  373. // determined by a member threshold in the identify packet,
  374. // and is currently hard-coded at 250 members in the library.
  375. Large bool `json:"large"`
  376. // The default message notification setting for the guild.
  377. DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
  378. // A list of roles in the guild.
  379. Roles []*Role `json:"roles"`
  380. // A list of the custom emojis present in the guild.
  381. Emojis []*Emoji `json:"emojis"`
  382. // A list of the members in the guild.
  383. // This field is only present in GUILD_CREATE events and websocket
  384. // update events, and thus is only present in state-cached guilds.
  385. Members []*Member `json:"members"`
  386. // A list of partial presence objects for members in the guild.
  387. // This field is only present in GUILD_CREATE events and websocket
  388. // update events, and thus is only present in state-cached guilds.
  389. Presences []*Presence `json:"presences"`
  390. // The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
  391. MaxPresences int `json:"max_presences"`
  392. // The maximum number of members for the guild
  393. MaxMembers int `json:"max_members"`
  394. // A list of channels in the guild.
  395. // This field is only present in GUILD_CREATE events and websocket
  396. // update events, and thus is only present in state-cached guilds.
  397. Channels []*Channel `json:"channels"`
  398. // A list of voice states for the guild.
  399. // This field is only present in GUILD_CREATE events and websocket
  400. // update events, and thus is only present in state-cached guilds.
  401. VoiceStates []*VoiceState `json:"voice_states"`
  402. // Whether this guild is currently unavailable (most likely due to outage).
  403. // This field is only present in GUILD_CREATE events and websocket
  404. // update events, and thus is only present in state-cached guilds.
  405. Unavailable bool `json:"unavailable"`
  406. // The explicit content filter level
  407. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  408. // The list of enabled guild features
  409. Features []string `json:"features"`
  410. // Required MFA level for the guild
  411. MfaLevel MfaLevel `json:"mfa_level"`
  412. // The application id of the guild if bot created.
  413. ApplicationID string `json:"application_id"`
  414. // Whether or not the Server Widget is enabled
  415. WidgetEnabled bool `json:"widget_enabled"`
  416. // The Channel ID for the Server Widget
  417. WidgetChannelID string `json:"widget_channel_id"`
  418. // The Channel ID to which system messages are sent (eg join and leave messages)
  419. SystemChannelID string `json:"system_channel_id"`
  420. // The System channel flags
  421. SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
  422. // The ID of the rules channel ID, used for rules.
  423. RulesChannelID string `json:"rules_channel_id"`
  424. // the vanity url code for the guild
  425. VanityURLCode string `json:"vanity_url_code"`
  426. // the description for the guild
  427. Description string `json:"description"`
  428. // The hash of the guild's banner
  429. Banner string `json:"banner"`
  430. // The premium tier of the guild
  431. PremiumTier PremiumTier `json:"premium_tier"`
  432. // The total number of users currently boosting this server
  433. PremiumSubscriptionCount int `json:"premium_subscription_count"`
  434. // The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
  435. PreferredLocale string `json:"preferred_locale"`
  436. // The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
  437. PublicUpdatesChannelID string `json:"public_updates_channel_id"`
  438. // The maximum amount of users in a video channel
  439. MaxVideoChannelUsers int `json:"max_video_channel_users"`
  440. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  441. ApproximateMemberCount int `json:"approximate_member_count"`
  442. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  443. ApproximatePresenceCount int `json:"approximate_presence_count"`
  444. // Permissions of our user
  445. Permissions int64 `json:"permissions,string"`
  446. }
  447. // A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild.
  448. type GuildPreview struct {
  449. // The ID of the guild.
  450. ID string `json:"id"`
  451. // The name of the guild. (2–100 characters)
  452. Name string `json:"name"`
  453. // The hash of the guild's icon. Use Session.GuildIcon
  454. // to retrieve the icon itself.
  455. Icon string `json:"icon"`
  456. // The hash of the guild's splash.
  457. Splash string `json:"splash"`
  458. // The hash of the guild's discovery splash.
  459. DiscoverySplash string `json:"discovery_splash"`
  460. // A list of the custom emojis present in the guild.
  461. Emojis []*Emoji `json:"emojis"`
  462. // The list of enabled guild features
  463. Features []string `json:"features"`
  464. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  465. ApproximateMemberCount int `json:"approximate_member_count"`
  466. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  467. ApproximatePresenceCount int `json:"approximate_presence_count"`
  468. // the description for the guild
  469. Description string `json:"description"`
  470. }
  471. // MessageNotifications is the notification level for a guild
  472. // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
  473. type MessageNotifications int
  474. // Block containing known MessageNotifications values
  475. const (
  476. MessageNotificationsAllMessages MessageNotifications = 0
  477. MessageNotificationsOnlyMentions MessageNotifications = 1
  478. )
  479. // SystemChannelFlag is the type of flags in the system channel (see SystemChannelFlag* consts)
  480. // https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
  481. type SystemChannelFlag int
  482. // Block containing known SystemChannelFlag values
  483. const (
  484. SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << 0
  485. SystemChannelFlagsSuppressPremium SystemChannelFlag = 1 << 1
  486. )
  487. // IconURL returns a URL to the guild's icon.
  488. func (g *Guild) IconURL() string {
  489. if g.Icon == "" {
  490. return ""
  491. }
  492. if strings.HasPrefix(g.Icon, "a_") {
  493. return EndpointGuildIconAnimated(g.ID, g.Icon)
  494. }
  495. return EndpointGuildIcon(g.ID, g.Icon)
  496. }
  497. // A UserGuild holds a brief version of a Guild
  498. type UserGuild struct {
  499. ID string `json:"id"`
  500. Name string `json:"name"`
  501. Icon string `json:"icon"`
  502. Owner bool `json:"owner"`
  503. Permissions int64 `json:"permissions,string"`
  504. }
  505. // A GuildParams stores all the data needed to update discord guild settings
  506. type GuildParams struct {
  507. Name string `json:"name,omitempty"`
  508. Region string `json:"region,omitempty"`
  509. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  510. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  511. AfkChannelID string `json:"afk_channel_id,omitempty"`
  512. AfkTimeout int `json:"afk_timeout,omitempty"`
  513. Icon string `json:"icon,omitempty"`
  514. OwnerID string `json:"owner_id,omitempty"`
  515. Splash string `json:"splash,omitempty"`
  516. Banner string `json:"banner,omitempty"`
  517. }
  518. // A Role stores information about Discord guild member roles.
  519. type Role struct {
  520. // The ID of the role.
  521. ID string `json:"id"`
  522. // The name of the role.
  523. Name string `json:"name"`
  524. // Whether this role is managed by an integration, and
  525. // thus cannot be manually added to, or taken from, members.
  526. Managed bool `json:"managed"`
  527. // Whether this role is mentionable.
  528. Mentionable bool `json:"mentionable"`
  529. // Whether this role is hoisted (shows up separately in member list).
  530. Hoist bool `json:"hoist"`
  531. // The hex color of this role.
  532. Color int `json:"color"`
  533. // The position of this role in the guild's role hierarchy.
  534. Position int `json:"position"`
  535. // The permissions of the role on the guild (doesn't include channel overrides).
  536. // This is a combination of bit masks; the presence of a certain permission can
  537. // be checked by performing a bitwise AND between this int and the permission.
  538. Permissions int64 `json:"permissions,string"`
  539. }
  540. // Mention returns a string which mentions the role
  541. func (r *Role) Mention() string {
  542. return fmt.Sprintf("<@&%s>", r.ID)
  543. }
  544. // Roles are a collection of Role
  545. type Roles []*Role
  546. func (r Roles) Len() int {
  547. return len(r)
  548. }
  549. func (r Roles) Less(i, j int) bool {
  550. return r[i].Position > r[j].Position
  551. }
  552. func (r Roles) Swap(i, j int) {
  553. r[i], r[j] = r[j], r[i]
  554. }
  555. // A VoiceState stores the voice states of Guilds
  556. type VoiceState struct {
  557. UserID string `json:"user_id"`
  558. SessionID string `json:"session_id"`
  559. ChannelID string `json:"channel_id"`
  560. GuildID string `json:"guild_id"`
  561. Suppress bool `json:"suppress"`
  562. SelfMute bool `json:"self_mute"`
  563. SelfDeaf bool `json:"self_deaf"`
  564. Mute bool `json:"mute"`
  565. Deaf bool `json:"deaf"`
  566. }
  567. // A Presence stores the online, offline, or idle and game status of Guild members.
  568. type Presence struct {
  569. User *User `json:"user"`
  570. Status Status `json:"status"`
  571. Activities []*Activity `json:"activities"`
  572. Since *int `json:"since"`
  573. }
  574. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  575. type TimeStamps struct {
  576. EndTimestamp int64 `json:"end,omitempty"`
  577. StartTimestamp int64 `json:"start,omitempty"`
  578. }
  579. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  580. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  581. temp := struct {
  582. End float64 `json:"end,omitempty"`
  583. Start float64 `json:"start,omitempty"`
  584. }{}
  585. err := json.Unmarshal(b, &temp)
  586. if err != nil {
  587. return err
  588. }
  589. t.EndTimestamp = int64(temp.End)
  590. t.StartTimestamp = int64(temp.Start)
  591. return nil
  592. }
  593. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  594. type Assets struct {
  595. LargeImageID string `json:"large_image,omitempty"`
  596. SmallImageID string `json:"small_image,omitempty"`
  597. LargeText string `json:"large_text,omitempty"`
  598. SmallText string `json:"small_text,omitempty"`
  599. }
  600. // A Member stores user information for Guild members. A guild
  601. // member represents a certain user's presence in a guild.
  602. type Member struct {
  603. // The guild ID on which the member exists.
  604. GuildID string `json:"guild_id"`
  605. // The time at which the member joined the guild, in ISO8601.
  606. JoinedAt Timestamp `json:"joined_at"`
  607. // The nickname of the member, if they have one.
  608. Nick string `json:"nick"`
  609. // Whether the member is deafened at a guild level.
  610. Deaf bool `json:"deaf"`
  611. // Whether the member is muted at a guild level.
  612. Mute bool `json:"mute"`
  613. // The underlying user on which the member is based.
  614. User *User `json:"user"`
  615. // A list of IDs of the roles which are possessed by the member.
  616. Roles []string `json:"roles"`
  617. // When the user used their Nitro boost on the server
  618. PremiumSince Timestamp `json:"premium_since"`
  619. // Is true while the member hasn't accepted the membership screen.
  620. Pending bool `json:"pending"`
  621. // Total permissions of the member in the channel, including overrides, returned when in the interaction object.
  622. Permissions int64 `json:"permissions,string"`
  623. }
  624. // Mention creates a member mention
  625. func (m *Member) Mention() string {
  626. return "<@!" + m.User.ID + ">"
  627. }
  628. // A Settings stores data for a specific users Discord client settings.
  629. type Settings struct {
  630. RenderEmbeds bool `json:"render_embeds"`
  631. InlineEmbedMedia bool `json:"inline_embed_media"`
  632. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  633. EnableTTSCommand bool `json:"enable_tts_command"`
  634. MessageDisplayCompact bool `json:"message_display_compact"`
  635. ShowCurrentGame bool `json:"show_current_game"`
  636. ConvertEmoticons bool `json:"convert_emoticons"`
  637. Locale string `json:"locale"`
  638. Theme string `json:"theme"`
  639. GuildPositions []string `json:"guild_positions"`
  640. RestrictedGuilds []string `json:"restricted_guilds"`
  641. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  642. Status Status `json:"status"`
  643. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  644. DeveloperMode bool `json:"developer_mode"`
  645. }
  646. // Status type definition
  647. type Status string
  648. // Constants for Status with the different current available status
  649. const (
  650. StatusOnline Status = "online"
  651. StatusIdle Status = "idle"
  652. StatusDoNotDisturb Status = "dnd"
  653. StatusInvisible Status = "invisible"
  654. StatusOffline Status = "offline"
  655. )
  656. // FriendSourceFlags stores ... TODO :)
  657. type FriendSourceFlags struct {
  658. All bool `json:"all"`
  659. MutualGuilds bool `json:"mutual_guilds"`
  660. MutualFriends bool `json:"mutual_friends"`
  661. }
  662. // A Relationship between the logged in user and Relationship.User
  663. type Relationship struct {
  664. User *User `json:"user"`
  665. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  666. ID string `json:"id"`
  667. }
  668. // A TooManyRequests struct holds information received from Discord
  669. // when receiving a HTTP 429 response.
  670. type TooManyRequests struct {
  671. Bucket string `json:"bucket"`
  672. Message string `json:"message"`
  673. RetryAfter time.Duration `json:"retry_after"`
  674. }
  675. // UnmarshalJSON helps support translation of a milliseconds-based float
  676. // into a time.Duration on TooManyRequests.
  677. func (t *TooManyRequests) UnmarshalJSON(b []byte) error {
  678. u := struct {
  679. Bucket string `json:"bucket"`
  680. Message string `json:"message"`
  681. RetryAfter float64 `json:"retry_after"`
  682. }{}
  683. err := json.Unmarshal(b, &u)
  684. if err != nil {
  685. return err
  686. }
  687. t.Bucket = u.Bucket
  688. t.Message = u.Message
  689. whole, frac := math.Modf(u.RetryAfter)
  690. t.RetryAfter = time.Duration(whole)*time.Second + time.Duration(frac*1000)*time.Millisecond
  691. return nil
  692. }
  693. // A ReadState stores data on the read state of channels.
  694. type ReadState struct {
  695. MentionCount int `json:"mention_count"`
  696. LastMessageID string `json:"last_message_id"`
  697. ID string `json:"id"`
  698. }
  699. // An Ack is used to ack messages
  700. type Ack struct {
  701. Token string `json:"token"`
  702. }
  703. // A GuildRole stores data for guild roles.
  704. type GuildRole struct {
  705. Role *Role `json:"role"`
  706. GuildID string `json:"guild_id"`
  707. }
  708. // A GuildBan stores data for a guild ban.
  709. type GuildBan struct {
  710. Reason string `json:"reason"`
  711. User *User `json:"user"`
  712. }
  713. // A GuildEmbed stores data for a guild embed.
  714. type GuildEmbed struct {
  715. Enabled bool `json:"enabled"`
  716. ChannelID string `json:"channel_id"`
  717. }
  718. // A GuildAuditLog stores data for a guild audit log.
  719. // https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
  720. type GuildAuditLog struct {
  721. Webhooks []*Webhook `json:"webhooks,omitempty"`
  722. Users []*User `json:"users,omitempty"`
  723. AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
  724. Integrations []*Integration `json:"integrations"`
  725. }
  726. // AuditLogEntry for a GuildAuditLog
  727. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
  728. type AuditLogEntry struct {
  729. TargetID string `json:"target_id"`
  730. Changes []*AuditLogChange `json:"changes"`
  731. UserID string `json:"user_id"`
  732. ID string `json:"id"`
  733. ActionType *AuditLogAction `json:"action_type"`
  734. Options *AuditLogOptions `json:"options"`
  735. Reason string `json:"reason"`
  736. }
  737. // AuditLogChange for an AuditLogEntry
  738. type AuditLogChange struct {
  739. NewValue interface{} `json:"new_value"`
  740. OldValue interface{} `json:"old_value"`
  741. Key *AuditLogChangeKey `json:"key"`
  742. }
  743. // AuditLogChangeKey value for AuditLogChange
  744. // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
  745. type AuditLogChangeKey string
  746. // Block of valid AuditLogChangeKey
  747. const (
  748. AuditLogChangeKeyName AuditLogChangeKey = "name"
  749. AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
  750. AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
  751. AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
  752. AuditLogChangeKeyRegion AuditLogChangeKey = "region"
  753. AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
  754. AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
  755. AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
  756. AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
  757. AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
  758. AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
  759. AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
  760. AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
  761. AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
  762. AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
  763. AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
  764. AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
  765. AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
  766. AuditLogChangeKeyPosition AuditLogChangeKey = "position"
  767. AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
  768. AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
  769. AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
  770. AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
  771. AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
  772. AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
  773. AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
  774. AuditLogChangeKeyColor AuditLogChangeKey = "color"
  775. AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
  776. AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
  777. AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
  778. AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
  779. AuditLogChangeKeyCode AuditLogChangeKey = "code"
  780. AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
  781. AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
  782. AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
  783. AuditLogChangeKeyUses AuditLogChangeKey = "uses"
  784. AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
  785. AuditLogChangeKeyTempoary AuditLogChangeKey = "temporary"
  786. AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
  787. AuditLogChangeKeyMute AuditLogChangeKey = "mute"
  788. AuditLogChangeKeyNick AuditLogChangeKey = "nick"
  789. AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
  790. AuditLogChangeKeyID AuditLogChangeKey = "id"
  791. AuditLogChangeKeyType AuditLogChangeKey = "type"
  792. AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
  793. AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
  794. AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
  795. )
  796. // AuditLogOptions optional data for the AuditLog
  797. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  798. type AuditLogOptions struct {
  799. DeleteMemberDays string `json:"delete_member_days"`
  800. MembersRemoved string `json:"members_removed"`
  801. ChannelID string `json:"channel_id"`
  802. MessageID string `json:"message_id"`
  803. Count string `json:"count"`
  804. ID string `json:"id"`
  805. Type *AuditLogOptionsType `json:"type"`
  806. RoleName string `json:"role_name"`
  807. }
  808. // AuditLogOptionsType of the AuditLogOption
  809. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  810. type AuditLogOptionsType string
  811. // Valid Types for AuditLogOptionsType
  812. const (
  813. AuditLogOptionsTypeMember AuditLogOptionsType = "member"
  814. AuditLogOptionsTypeRole AuditLogOptionsType = "role"
  815. )
  816. // AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
  817. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
  818. type AuditLogAction int
  819. // Block contains Discord Audit Log Action Types
  820. const (
  821. AuditLogActionGuildUpdate AuditLogAction = 1
  822. AuditLogActionChannelCreate AuditLogAction = 10
  823. AuditLogActionChannelUpdate AuditLogAction = 11
  824. AuditLogActionChannelDelete AuditLogAction = 12
  825. AuditLogActionChannelOverwriteCreate AuditLogAction = 13
  826. AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
  827. AuditLogActionChannelOverwriteDelete AuditLogAction = 15
  828. AuditLogActionMemberKick AuditLogAction = 20
  829. AuditLogActionMemberPrune AuditLogAction = 21
  830. AuditLogActionMemberBanAdd AuditLogAction = 22
  831. AuditLogActionMemberBanRemove AuditLogAction = 23
  832. AuditLogActionMemberUpdate AuditLogAction = 24
  833. AuditLogActionMemberRoleUpdate AuditLogAction = 25
  834. AuditLogActionRoleCreate AuditLogAction = 30
  835. AuditLogActionRoleUpdate AuditLogAction = 31
  836. AuditLogActionRoleDelete AuditLogAction = 32
  837. AuditLogActionInviteCreate AuditLogAction = 40
  838. AuditLogActionInviteUpdate AuditLogAction = 41
  839. AuditLogActionInviteDelete AuditLogAction = 42
  840. AuditLogActionWebhookCreate AuditLogAction = 50
  841. AuditLogActionWebhookUpdate AuditLogAction = 51
  842. AuditLogActionWebhookDelete AuditLogAction = 52
  843. AuditLogActionEmojiCreate AuditLogAction = 60
  844. AuditLogActionEmojiUpdate AuditLogAction = 61
  845. AuditLogActionEmojiDelete AuditLogAction = 62
  846. AuditLogActionMessageDelete AuditLogAction = 72
  847. AuditLogActionMessageBulkDelete AuditLogAction = 73
  848. AuditLogActionMessagePin AuditLogAction = 74
  849. AuditLogActionMessageUnpin AuditLogAction = 75
  850. AuditLogActionIntegrationCreate AuditLogAction = 80
  851. AuditLogActionIntegrationUpdate AuditLogAction = 81
  852. AuditLogActionIntegrationDelete AuditLogAction = 82
  853. )
  854. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  855. type UserGuildSettingsChannelOverride struct {
  856. Muted bool `json:"muted"`
  857. MessageNotifications int `json:"message_notifications"`
  858. ChannelID string `json:"channel_id"`
  859. }
  860. // A UserGuildSettings stores data for a users guild settings.
  861. type UserGuildSettings struct {
  862. SupressEveryone bool `json:"suppress_everyone"`
  863. Muted bool `json:"muted"`
  864. MobilePush bool `json:"mobile_push"`
  865. MessageNotifications int `json:"message_notifications"`
  866. GuildID string `json:"guild_id"`
  867. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  868. }
  869. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  870. type UserGuildSettingsEdit struct {
  871. SupressEveryone bool `json:"suppress_everyone"`
  872. Muted bool `json:"muted"`
  873. MobilePush bool `json:"mobile_push"`
  874. MessageNotifications int `json:"message_notifications"`
  875. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  876. }
  877. // An APIErrorMessage is an api error message returned from discord
  878. type APIErrorMessage struct {
  879. Code int `json:"code"`
  880. Message string `json:"message"`
  881. }
  882. // MessageReaction stores the data for a message reaction.
  883. type MessageReaction struct {
  884. UserID string `json:"user_id"`
  885. MessageID string `json:"message_id"`
  886. Emoji Emoji `json:"emoji"`
  887. ChannelID string `json:"channel_id"`
  888. GuildID string `json:"guild_id,omitempty"`
  889. }
  890. // GatewayBotResponse stores the data for the gateway/bot response
  891. type GatewayBotResponse struct {
  892. URL string `json:"url"`
  893. Shards int `json:"shards"`
  894. SessionStartLimit SessionInformation `json:"session_start_limit"`
  895. }
  896. // SessionInformation provides the information for max concurrency sharding
  897. type SessionInformation struct {
  898. Total int `json:"total,omitempty"`
  899. Remaining int `json:"remaining,omitempty"`
  900. ResetAfter int `json:"reset_after,omitempty"`
  901. MaxConcurrency int `json:"max_concurrency,omitempty"`
  902. }
  903. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  904. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  905. type GatewayStatusUpdate struct {
  906. Since int `json:"since"`
  907. Game Activity `json:"game"`
  908. Status string `json:"status"`
  909. AFK bool `json:"afk"`
  910. }
  911. // Activity defines the Activity sent with GatewayStatusUpdate
  912. // https://discord.com/developers/docs/topics/gateway#activity-object
  913. type Activity struct {
  914. Name string `json:"name"`
  915. Type ActivityType `json:"type"`
  916. URL string `json:"url,omitempty"`
  917. CreatedAt time.Time `json:"created_at"`
  918. ApplicationID string `json:"application_id,omitempty"`
  919. State string `json:"state,omitempty"`
  920. Details string `json:"details,omitempty"`
  921. Timestamps TimeStamps `json:"timestamps,omitempty"`
  922. Emoji Emoji `json:"emoji,omitempty"`
  923. Party Party `json:"party,omitempty"`
  924. Assets Assets `json:"assets,omitempty"`
  925. Secrets Secrets `json:"secrets,omitempty"`
  926. Instance bool `json:"instance,omitempty"`
  927. Flags int `json:"flags,omitempty"`
  928. }
  929. // UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
  930. func (activity *Activity) UnmarshalJSON(b []byte) error {
  931. temp := struct {
  932. Name string `json:"name"`
  933. Type ActivityType `json:"type"`
  934. URL string `json:"url,omitempty"`
  935. CreatedAt int64 `json:"created_at"`
  936. ApplicationID string `json:"application_id,omitempty"`
  937. State string `json:"state,omitempty"`
  938. Details string `json:"details,omitempty"`
  939. Timestamps TimeStamps `json:"timestamps,omitempty"`
  940. Emoji Emoji `json:"emoji,omitempty"`
  941. Party Party `json:"party,omitempty"`
  942. Assets Assets `json:"assets,omitempty"`
  943. Secrets Secrets `json:"secrets,omitempty"`
  944. Instance bool `json:"instance,omitempty"`
  945. Flags int `json:"flags,omitempty"`
  946. }{}
  947. err := json.Unmarshal(b, &temp)
  948. if err != nil {
  949. return err
  950. }
  951. activity.CreatedAt = time.Unix(0, temp.CreatedAt*1000000)
  952. activity.ApplicationID = temp.ApplicationID
  953. activity.Assets = temp.Assets
  954. activity.Details = temp.Details
  955. activity.Emoji = temp.Emoji
  956. activity.Flags = temp.Flags
  957. activity.Instance = temp.Instance
  958. activity.Name = temp.Name
  959. activity.Party = temp.Party
  960. activity.Secrets = temp.Secrets
  961. activity.State = temp.State
  962. activity.Timestamps = temp.Timestamps
  963. activity.Type = temp.Type
  964. activity.URL = temp.URL
  965. return nil
  966. }
  967. // Party defines the Party field in the Activity struct
  968. // https://discord.com/developers/docs/topics/gateway#activity-object
  969. type Party struct {
  970. ID string `json:"id,omitempty"`
  971. Size []int `json:"size,omitempty"`
  972. }
  973. // Secrets defines the Secrets field for the Activity struct
  974. // https://discord.com/developers/docs/topics/gateway#activity-object
  975. type Secrets struct {
  976. Join string `json:"join,omitempty"`
  977. Spectate string `json:"spectate,omitempty"`
  978. Match string `json:"match,omitempty"`
  979. }
  980. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  981. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  982. type ActivityType int
  983. // Valid ActivityType values
  984. const (
  985. ActivityTypeGame ActivityType = 0
  986. ActivityTypeStreaming ActivityType = 1
  987. ActivityTypeListening ActivityType = 2
  988. ActivityTypeWatching ActivityType = 3
  989. ActivityTypeCustom ActivityType = 4
  990. ActivityTypeCompeting ActivityType = 5
  991. )
  992. // Identify is sent during initial handshake with the discord gateway.
  993. // https://discord.com/developers/docs/topics/gateway#identify
  994. type Identify struct {
  995. Token string `json:"token"`
  996. Properties IdentifyProperties `json:"properties"`
  997. Compress bool `json:"compress"`
  998. LargeThreshold int `json:"large_threshold"`
  999. Shard *[2]int `json:"shard,omitempty"`
  1000. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  1001. GuildSubscriptions bool `json:"guild_subscriptions"`
  1002. Intents Intent `json:"intents"`
  1003. }
  1004. // IdentifyProperties contains the "properties" portion of an Identify packet
  1005. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  1006. type IdentifyProperties struct {
  1007. OS string `json:"$os"`
  1008. Browser string `json:"$browser"`
  1009. Device string `json:"$device"`
  1010. Referer string `json:"$referer"`
  1011. ReferringDomain string `json:"$referring_domain"`
  1012. }
  1013. // Constants for the different bit offsets of text channel permissions
  1014. const (
  1015. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  1016. PermissionReadMessages = 0x0000000000000400
  1017. PermissionSendMessages = 0x0000000000000800
  1018. PermissionSendTTSMessages = 0x0000000000001000
  1019. PermissionManageMessages = 0x0000000000002000
  1020. PermissionEmbedLinks = 0x0000000000004000
  1021. PermissionAttachFiles = 0x0000000000008000
  1022. PermissionReadMessageHistory = 0x0000000000010000
  1023. PermissionMentionEveryone = 0x0000000000020000
  1024. PermissionUseExternalEmojis = 0x0000000000040000
  1025. PermissionUseSlashCommands = 0x0000000080000000
  1026. )
  1027. // Constants for the different bit offsets of voice permissions
  1028. const (
  1029. PermissionVoicePrioritySpeaker = 0x0000000000000100
  1030. PermissionVoiceStreamVideo = 0x0000000000000200
  1031. PermissionVoiceConnect = 0x0000000000100000
  1032. PermissionVoiceSpeak = 0x0000000000200000
  1033. PermissionVoiceMuteMembers = 0x0000000000400000
  1034. PermissionVoiceDeafenMembers = 0x0000000000800000
  1035. PermissionVoiceMoveMembers = 0x0000000001000000
  1036. PermissionVoiceUseVAD = 0x0000000002000000
  1037. PermissionVoiceRequestToSpeak = 0x0000000100000000
  1038. )
  1039. // Constants for general management.
  1040. const (
  1041. PermissionChangeNickname = 0x0000000004000000
  1042. PermissionManageNicknames = 0x0000000008000000
  1043. PermissionManageRoles = 0x0000000010000000
  1044. PermissionManageWebhooks = 0x0000000020000000
  1045. PermissionManageEmojis = 0x0000000040000000
  1046. )
  1047. // Constants for the different bit offsets of general permissions
  1048. const (
  1049. PermissionCreateInstantInvite = 0x0000000000000001
  1050. PermissionKickMembers = 0x0000000000000002
  1051. PermissionBanMembers = 0x0000000000000004
  1052. PermissionAdministrator = 0x0000000000000008
  1053. PermissionManageChannels = 0x0000000000000010
  1054. PermissionManageServer = 0x0000000000000020
  1055. PermissionAddReactions = 0x0000000000000040
  1056. PermissionViewAuditLogs = 0x0000000000000080
  1057. PermissionViewChannel = 0x0000000000000400
  1058. PermissionViewGuildInsights = 0x0000000000080000
  1059. PermissionAllText = PermissionViewChannel |
  1060. PermissionSendMessages |
  1061. PermissionSendTTSMessages |
  1062. PermissionManageMessages |
  1063. PermissionEmbedLinks |
  1064. PermissionAttachFiles |
  1065. PermissionReadMessageHistory |
  1066. PermissionMentionEveryone
  1067. PermissionAllVoice = PermissionViewChannel |
  1068. PermissionVoiceConnect |
  1069. PermissionVoiceSpeak |
  1070. PermissionVoiceMuteMembers |
  1071. PermissionVoiceDeafenMembers |
  1072. PermissionVoiceMoveMembers |
  1073. PermissionVoiceUseVAD |
  1074. PermissionVoicePrioritySpeaker
  1075. PermissionAllChannel = PermissionAllText |
  1076. PermissionAllVoice |
  1077. PermissionCreateInstantInvite |
  1078. PermissionManageRoles |
  1079. PermissionManageChannels |
  1080. PermissionAddReactions |
  1081. PermissionViewAuditLogs
  1082. PermissionAll = PermissionAllChannel |
  1083. PermissionKickMembers |
  1084. PermissionBanMembers |
  1085. PermissionManageServer |
  1086. PermissionAdministrator |
  1087. PermissionManageWebhooks |
  1088. PermissionManageEmojis
  1089. )
  1090. // Block contains Discord JSON Error Response codes
  1091. const (
  1092. ErrCodeUnknownAccount = 10001
  1093. ErrCodeUnknownApplication = 10002
  1094. ErrCodeUnknownChannel = 10003
  1095. ErrCodeUnknownGuild = 10004
  1096. ErrCodeUnknownIntegration = 10005
  1097. ErrCodeUnknownInvite = 10006
  1098. ErrCodeUnknownMember = 10007
  1099. ErrCodeUnknownMessage = 10008
  1100. ErrCodeUnknownOverwrite = 10009
  1101. ErrCodeUnknownProvider = 10010
  1102. ErrCodeUnknownRole = 10011
  1103. ErrCodeUnknownToken = 10012
  1104. ErrCodeUnknownUser = 10013
  1105. ErrCodeUnknownEmoji = 10014
  1106. ErrCodeUnknownWebhook = 10015
  1107. ErrCodeUnknownBan = 10026
  1108. ErrCodeBotsCannotUseEndpoint = 20001
  1109. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1110. ErrCodeMaximumGuildsReached = 30001
  1111. ErrCodeMaximumFriendsReached = 30002
  1112. ErrCodeMaximumPinsReached = 30003
  1113. ErrCodeMaximumGuildRolesReached = 30005
  1114. ErrCodeTooManyReactions = 30010
  1115. ErrCodeUnauthorized = 40001
  1116. ErrCodeMissingAccess = 50001
  1117. ErrCodeInvalidAccountType = 50002
  1118. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1119. ErrCodeEmbedDisabled = 50004
  1120. ErrCodeCannotEditFromAnotherUser = 50005
  1121. ErrCodeCannotSendEmptyMessage = 50006
  1122. ErrCodeCannotSendMessagesToThisUser = 50007
  1123. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1124. ErrCodeChannelVerificationLevelTooHigh = 50009
  1125. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1126. ErrCodeOAuth2ApplicationLimitReached = 50011
  1127. ErrCodeInvalidOAuthState = 50012
  1128. ErrCodeMissingPermissions = 50013
  1129. ErrCodeInvalidAuthenticationToken = 50014
  1130. ErrCodeNoteTooLong = 50015
  1131. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1132. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1133. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1134. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1135. ErrCodeInvalidFormBody = 50035
  1136. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1137. ErrCodeReactionBlocked = 90001
  1138. )
  1139. // Intent is the type of a Gateway Intent
  1140. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1141. type Intent int
  1142. // Constants for the different bit offsets of intents
  1143. const (
  1144. IntentsGuilds Intent = 1 << 0
  1145. IntentsGuildMembers Intent = 1 << 1
  1146. IntentsGuildBans Intent = 1 << 2
  1147. IntentsGuildEmojis Intent = 1 << 3
  1148. IntentsGuildIntegrations Intent = 1 << 4
  1149. IntentsGuildWebhooks Intent = 1 << 5
  1150. IntentsGuildInvites Intent = 1 << 6
  1151. IntentsGuildVoiceStates Intent = 1 << 7
  1152. IntentsGuildPresences Intent = 1 << 8
  1153. IntentsGuildMessages Intent = 1 << 9
  1154. IntentsGuildMessageReactions Intent = 1 << 10
  1155. IntentsGuildMessageTyping Intent = 1 << 11
  1156. IntentsDirectMessages Intent = 1 << 12
  1157. IntentsDirectMessageReactions Intent = 1 << 13
  1158. IntentsDirectMessageTyping Intent = 1 << 14
  1159. IntentsAllWithoutPrivileged = IntentsGuilds |
  1160. IntentsGuildBans |
  1161. IntentsGuildEmojis |
  1162. IntentsGuildIntegrations |
  1163. IntentsGuildWebhooks |
  1164. IntentsGuildInvites |
  1165. IntentsGuildVoiceStates |
  1166. IntentsGuildMessages |
  1167. IntentsGuildMessageReactions |
  1168. IntentsGuildMessageTyping |
  1169. IntentsDirectMessages |
  1170. IntentsDirectMessageReactions |
  1171. IntentsDirectMessageTyping
  1172. IntentsAll = IntentsAllWithoutPrivileged |
  1173. IntentsGuildMembers |
  1174. IntentsGuildPresences
  1175. IntentsNone Intent = 0
  1176. )
  1177. // MakeIntent used to help convert a gateway intent value for use in the Identify structure;
  1178. // this was useful to help support the use of a pointer type when intents were optional.
  1179. // This is now a no-op, and is not necessary to use.
  1180. func MakeIntent(intents Intent) Intent {
  1181. return intents
  1182. }