structs.go 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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 time.Time `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 time.Time `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. // nil if the channel has no pinned messages.
  205. LastPinTimestamp *time.Time `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 time.Time `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. // BannerURL returns a URL to the guild's banner.
  498. func (g *Guild) BannerURL() string {
  499. if g.Banner == "" {
  500. return ""
  501. }
  502. return EndpointGuildBanner(g.ID, g.Banner)
  503. }
  504. // A UserGuild holds a brief version of a Guild
  505. type UserGuild struct {
  506. ID string `json:"id"`
  507. Name string `json:"name"`
  508. Icon string `json:"icon"`
  509. Owner bool `json:"owner"`
  510. Permissions int64 `json:"permissions,string"`
  511. }
  512. // A GuildParams stores all the data needed to update discord guild settings
  513. type GuildParams struct {
  514. Name string `json:"name,omitempty"`
  515. Region string `json:"region,omitempty"`
  516. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  517. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  518. AfkChannelID string `json:"afk_channel_id,omitempty"`
  519. AfkTimeout int `json:"afk_timeout,omitempty"`
  520. Icon string `json:"icon,omitempty"`
  521. OwnerID string `json:"owner_id,omitempty"`
  522. Splash string `json:"splash,omitempty"`
  523. Banner string `json:"banner,omitempty"`
  524. }
  525. // A Role stores information about Discord guild member roles.
  526. type Role struct {
  527. // The ID of the role.
  528. ID string `json:"id"`
  529. // The name of the role.
  530. Name string `json:"name"`
  531. // Whether this role is managed by an integration, and
  532. // thus cannot be manually added to, or taken from, members.
  533. Managed bool `json:"managed"`
  534. // Whether this role is mentionable.
  535. Mentionable bool `json:"mentionable"`
  536. // Whether this role is hoisted (shows up separately in member list).
  537. Hoist bool `json:"hoist"`
  538. // The hex color of this role.
  539. Color int `json:"color"`
  540. // The position of this role in the guild's role hierarchy.
  541. Position int `json:"position"`
  542. // The permissions of the role on the guild (doesn't include channel overrides).
  543. // This is a combination of bit masks; the presence of a certain permission can
  544. // be checked by performing a bitwise AND between this int and the permission.
  545. Permissions int64 `json:"permissions,string"`
  546. }
  547. // Mention returns a string which mentions the role
  548. func (r *Role) Mention() string {
  549. return fmt.Sprintf("<@&%s>", r.ID)
  550. }
  551. // Roles are a collection of Role
  552. type Roles []*Role
  553. func (r Roles) Len() int {
  554. return len(r)
  555. }
  556. func (r Roles) Less(i, j int) bool {
  557. return r[i].Position > r[j].Position
  558. }
  559. func (r Roles) Swap(i, j int) {
  560. r[i], r[j] = r[j], r[i]
  561. }
  562. // A VoiceState stores the voice states of Guilds
  563. type VoiceState struct {
  564. UserID string `json:"user_id"`
  565. SessionID string `json:"session_id"`
  566. ChannelID string `json:"channel_id"`
  567. GuildID string `json:"guild_id"`
  568. Suppress bool `json:"suppress"`
  569. SelfMute bool `json:"self_mute"`
  570. SelfDeaf bool `json:"self_deaf"`
  571. Mute bool `json:"mute"`
  572. Deaf bool `json:"deaf"`
  573. }
  574. // A Presence stores the online, offline, or idle and game status of Guild members.
  575. type Presence struct {
  576. User *User `json:"user"`
  577. Status Status `json:"status"`
  578. Activities []*Activity `json:"activities"`
  579. Since *int `json:"since"`
  580. }
  581. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  582. type TimeStamps struct {
  583. EndTimestamp int64 `json:"end,omitempty"`
  584. StartTimestamp int64 `json:"start,omitempty"`
  585. }
  586. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  587. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  588. temp := struct {
  589. End float64 `json:"end,omitempty"`
  590. Start float64 `json:"start,omitempty"`
  591. }{}
  592. err := json.Unmarshal(b, &temp)
  593. if err != nil {
  594. return err
  595. }
  596. t.EndTimestamp = int64(temp.End)
  597. t.StartTimestamp = int64(temp.Start)
  598. return nil
  599. }
  600. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  601. type Assets struct {
  602. LargeImageID string `json:"large_image,omitempty"`
  603. SmallImageID string `json:"small_image,omitempty"`
  604. LargeText string `json:"large_text,omitempty"`
  605. SmallText string `json:"small_text,omitempty"`
  606. }
  607. // A Member stores user information for Guild members. A guild
  608. // member represents a certain user's presence in a guild.
  609. type Member struct {
  610. // The guild ID on which the member exists.
  611. GuildID string `json:"guild_id"`
  612. // The time at which the member joined the guild.
  613. JoinedAt time.Time `json:"joined_at"`
  614. // The nickname of the member, if they have one.
  615. Nick string `json:"nick"`
  616. // Whether the member is deafened at a guild level.
  617. Deaf bool `json:"deaf"`
  618. // Whether the member is muted at a guild level.
  619. Mute bool `json:"mute"`
  620. // The underlying user on which the member is based.
  621. User *User `json:"user"`
  622. // A list of IDs of the roles which are possessed by the member.
  623. Roles []string `json:"roles"`
  624. // When the user used their Nitro boost on the server
  625. PremiumSince *time.Time `json:"premium_since"`
  626. // Is true while the member hasn't accepted the membership screen.
  627. Pending bool `json:"pending"`
  628. // Total permissions of the member in the channel, including overrides, returned when in the interaction object.
  629. Permissions int64 `json:"permissions,string"`
  630. }
  631. // Mention creates a member mention
  632. func (m *Member) Mention() string {
  633. return "<@!" + m.User.ID + ">"
  634. }
  635. // A Settings stores data for a specific users Discord client settings.
  636. type Settings struct {
  637. RenderEmbeds bool `json:"render_embeds"`
  638. InlineEmbedMedia bool `json:"inline_embed_media"`
  639. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  640. EnableTTSCommand bool `json:"enable_tts_command"`
  641. MessageDisplayCompact bool `json:"message_display_compact"`
  642. ShowCurrentGame bool `json:"show_current_game"`
  643. ConvertEmoticons bool `json:"convert_emoticons"`
  644. Locale string `json:"locale"`
  645. Theme string `json:"theme"`
  646. GuildPositions []string `json:"guild_positions"`
  647. RestrictedGuilds []string `json:"restricted_guilds"`
  648. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  649. Status Status `json:"status"`
  650. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  651. DeveloperMode bool `json:"developer_mode"`
  652. }
  653. // Status type definition
  654. type Status string
  655. // Constants for Status with the different current available status
  656. const (
  657. StatusOnline Status = "online"
  658. StatusIdle Status = "idle"
  659. StatusDoNotDisturb Status = "dnd"
  660. StatusInvisible Status = "invisible"
  661. StatusOffline Status = "offline"
  662. )
  663. // FriendSourceFlags stores ... TODO :)
  664. type FriendSourceFlags struct {
  665. All bool `json:"all"`
  666. MutualGuilds bool `json:"mutual_guilds"`
  667. MutualFriends bool `json:"mutual_friends"`
  668. }
  669. // A Relationship between the logged in user and Relationship.User
  670. type Relationship struct {
  671. User *User `json:"user"`
  672. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  673. ID string `json:"id"`
  674. }
  675. // A TooManyRequests struct holds information received from Discord
  676. // when receiving a HTTP 429 response.
  677. type TooManyRequests struct {
  678. Bucket string `json:"bucket"`
  679. Message string `json:"message"`
  680. RetryAfter time.Duration `json:"retry_after"`
  681. }
  682. // UnmarshalJSON helps support translation of a milliseconds-based float
  683. // into a time.Duration on TooManyRequests.
  684. func (t *TooManyRequests) UnmarshalJSON(b []byte) error {
  685. u := struct {
  686. Bucket string `json:"bucket"`
  687. Message string `json:"message"`
  688. RetryAfter float64 `json:"retry_after"`
  689. }{}
  690. err := json.Unmarshal(b, &u)
  691. if err != nil {
  692. return err
  693. }
  694. t.Bucket = u.Bucket
  695. t.Message = u.Message
  696. whole, frac := math.Modf(u.RetryAfter)
  697. t.RetryAfter = time.Duration(whole)*time.Second + time.Duration(frac*1000)*time.Millisecond
  698. return nil
  699. }
  700. // A ReadState stores data on the read state of channels.
  701. type ReadState struct {
  702. MentionCount int `json:"mention_count"`
  703. LastMessageID string `json:"last_message_id"`
  704. ID string `json:"id"`
  705. }
  706. // An Ack is used to ack messages
  707. type Ack struct {
  708. Token string `json:"token"`
  709. }
  710. // A GuildRole stores data for guild roles.
  711. type GuildRole struct {
  712. Role *Role `json:"role"`
  713. GuildID string `json:"guild_id"`
  714. }
  715. // A GuildBan stores data for a guild ban.
  716. type GuildBan struct {
  717. Reason string `json:"reason"`
  718. User *User `json:"user"`
  719. }
  720. // A GuildEmbed stores data for a guild embed.
  721. type GuildEmbed struct {
  722. Enabled bool `json:"enabled"`
  723. ChannelID string `json:"channel_id"`
  724. }
  725. // A GuildAuditLog stores data for a guild audit log.
  726. // https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
  727. type GuildAuditLog struct {
  728. Webhooks []*Webhook `json:"webhooks,omitempty"`
  729. Users []*User `json:"users,omitempty"`
  730. AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
  731. Integrations []*Integration `json:"integrations"`
  732. }
  733. // AuditLogEntry for a GuildAuditLog
  734. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
  735. type AuditLogEntry struct {
  736. TargetID string `json:"target_id"`
  737. Changes []*AuditLogChange `json:"changes"`
  738. UserID string `json:"user_id"`
  739. ID string `json:"id"`
  740. ActionType *AuditLogAction `json:"action_type"`
  741. Options *AuditLogOptions `json:"options"`
  742. Reason string `json:"reason"`
  743. }
  744. // AuditLogChange for an AuditLogEntry
  745. type AuditLogChange struct {
  746. NewValue interface{} `json:"new_value"`
  747. OldValue interface{} `json:"old_value"`
  748. Key *AuditLogChangeKey `json:"key"`
  749. }
  750. // AuditLogChangeKey value for AuditLogChange
  751. // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
  752. type AuditLogChangeKey string
  753. // Block of valid AuditLogChangeKey
  754. const (
  755. AuditLogChangeKeyName AuditLogChangeKey = "name"
  756. AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
  757. AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
  758. AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
  759. AuditLogChangeKeyRegion AuditLogChangeKey = "region"
  760. AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
  761. AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
  762. AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
  763. AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
  764. AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
  765. AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
  766. AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
  767. AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
  768. AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
  769. AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
  770. AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
  771. AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
  772. AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
  773. AuditLogChangeKeyPosition AuditLogChangeKey = "position"
  774. AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
  775. AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
  776. AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
  777. AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
  778. AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
  779. AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
  780. AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
  781. AuditLogChangeKeyColor AuditLogChangeKey = "color"
  782. AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
  783. AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
  784. AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
  785. AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
  786. AuditLogChangeKeyCode AuditLogChangeKey = "code"
  787. AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
  788. AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
  789. AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
  790. AuditLogChangeKeyUses AuditLogChangeKey = "uses"
  791. AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
  792. AuditLogChangeKeyTempoary AuditLogChangeKey = "temporary"
  793. AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
  794. AuditLogChangeKeyMute AuditLogChangeKey = "mute"
  795. AuditLogChangeKeyNick AuditLogChangeKey = "nick"
  796. AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
  797. AuditLogChangeKeyID AuditLogChangeKey = "id"
  798. AuditLogChangeKeyType AuditLogChangeKey = "type"
  799. AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
  800. AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
  801. AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
  802. )
  803. // AuditLogOptions optional data for the AuditLog
  804. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  805. type AuditLogOptions struct {
  806. DeleteMemberDays string `json:"delete_member_days"`
  807. MembersRemoved string `json:"members_removed"`
  808. ChannelID string `json:"channel_id"`
  809. MessageID string `json:"message_id"`
  810. Count string `json:"count"`
  811. ID string `json:"id"`
  812. Type *AuditLogOptionsType `json:"type"`
  813. RoleName string `json:"role_name"`
  814. }
  815. // AuditLogOptionsType of the AuditLogOption
  816. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  817. type AuditLogOptionsType string
  818. // Valid Types for AuditLogOptionsType
  819. const (
  820. AuditLogOptionsTypeMember AuditLogOptionsType = "member"
  821. AuditLogOptionsTypeRole AuditLogOptionsType = "role"
  822. )
  823. // AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
  824. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
  825. type AuditLogAction int
  826. // Block contains Discord Audit Log Action Types
  827. const (
  828. AuditLogActionGuildUpdate AuditLogAction = 1
  829. AuditLogActionChannelCreate AuditLogAction = 10
  830. AuditLogActionChannelUpdate AuditLogAction = 11
  831. AuditLogActionChannelDelete AuditLogAction = 12
  832. AuditLogActionChannelOverwriteCreate AuditLogAction = 13
  833. AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
  834. AuditLogActionChannelOverwriteDelete AuditLogAction = 15
  835. AuditLogActionMemberKick AuditLogAction = 20
  836. AuditLogActionMemberPrune AuditLogAction = 21
  837. AuditLogActionMemberBanAdd AuditLogAction = 22
  838. AuditLogActionMemberBanRemove AuditLogAction = 23
  839. AuditLogActionMemberUpdate AuditLogAction = 24
  840. AuditLogActionMemberRoleUpdate AuditLogAction = 25
  841. AuditLogActionRoleCreate AuditLogAction = 30
  842. AuditLogActionRoleUpdate AuditLogAction = 31
  843. AuditLogActionRoleDelete AuditLogAction = 32
  844. AuditLogActionInviteCreate AuditLogAction = 40
  845. AuditLogActionInviteUpdate AuditLogAction = 41
  846. AuditLogActionInviteDelete AuditLogAction = 42
  847. AuditLogActionWebhookCreate AuditLogAction = 50
  848. AuditLogActionWebhookUpdate AuditLogAction = 51
  849. AuditLogActionWebhookDelete AuditLogAction = 52
  850. AuditLogActionEmojiCreate AuditLogAction = 60
  851. AuditLogActionEmojiUpdate AuditLogAction = 61
  852. AuditLogActionEmojiDelete AuditLogAction = 62
  853. AuditLogActionMessageDelete AuditLogAction = 72
  854. AuditLogActionMessageBulkDelete AuditLogAction = 73
  855. AuditLogActionMessagePin AuditLogAction = 74
  856. AuditLogActionMessageUnpin AuditLogAction = 75
  857. AuditLogActionIntegrationCreate AuditLogAction = 80
  858. AuditLogActionIntegrationUpdate AuditLogAction = 81
  859. AuditLogActionIntegrationDelete AuditLogAction = 82
  860. )
  861. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  862. type UserGuildSettingsChannelOverride struct {
  863. Muted bool `json:"muted"`
  864. MessageNotifications int `json:"message_notifications"`
  865. ChannelID string `json:"channel_id"`
  866. }
  867. // A UserGuildSettings stores data for a users guild settings.
  868. type UserGuildSettings struct {
  869. SupressEveryone bool `json:"suppress_everyone"`
  870. Muted bool `json:"muted"`
  871. MobilePush bool `json:"mobile_push"`
  872. MessageNotifications int `json:"message_notifications"`
  873. GuildID string `json:"guild_id"`
  874. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  875. }
  876. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  877. type UserGuildSettingsEdit struct {
  878. SupressEveryone bool `json:"suppress_everyone"`
  879. Muted bool `json:"muted"`
  880. MobilePush bool `json:"mobile_push"`
  881. MessageNotifications int `json:"message_notifications"`
  882. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  883. }
  884. // An APIErrorMessage is an api error message returned from discord
  885. type APIErrorMessage struct {
  886. Code int `json:"code"`
  887. Message string `json:"message"`
  888. }
  889. // MessageReaction stores the data for a message reaction.
  890. type MessageReaction struct {
  891. UserID string `json:"user_id"`
  892. MessageID string `json:"message_id"`
  893. Emoji Emoji `json:"emoji"`
  894. ChannelID string `json:"channel_id"`
  895. GuildID string `json:"guild_id,omitempty"`
  896. }
  897. // GatewayBotResponse stores the data for the gateway/bot response
  898. type GatewayBotResponse struct {
  899. URL string `json:"url"`
  900. Shards int `json:"shards"`
  901. SessionStartLimit SessionInformation `json:"session_start_limit"`
  902. }
  903. // SessionInformation provides the information for max concurrency sharding
  904. type SessionInformation struct {
  905. Total int `json:"total,omitempty"`
  906. Remaining int `json:"remaining,omitempty"`
  907. ResetAfter int `json:"reset_after,omitempty"`
  908. MaxConcurrency int `json:"max_concurrency,omitempty"`
  909. }
  910. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  911. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  912. type GatewayStatusUpdate struct {
  913. Since int `json:"since"`
  914. Game Activity `json:"game"`
  915. Status string `json:"status"`
  916. AFK bool `json:"afk"`
  917. }
  918. // Activity defines the Activity sent with GatewayStatusUpdate
  919. // https://discord.com/developers/docs/topics/gateway#activity-object
  920. type Activity struct {
  921. Name string `json:"name"`
  922. Type ActivityType `json:"type"`
  923. URL string `json:"url,omitempty"`
  924. CreatedAt time.Time `json:"created_at"`
  925. ApplicationID string `json:"application_id,omitempty"`
  926. State string `json:"state,omitempty"`
  927. Details string `json:"details,omitempty"`
  928. Timestamps TimeStamps `json:"timestamps,omitempty"`
  929. Emoji Emoji `json:"emoji,omitempty"`
  930. Party Party `json:"party,omitempty"`
  931. Assets Assets `json:"assets,omitempty"`
  932. Secrets Secrets `json:"secrets,omitempty"`
  933. Instance bool `json:"instance,omitempty"`
  934. Flags int `json:"flags,omitempty"`
  935. }
  936. // UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
  937. func (activity *Activity) UnmarshalJSON(b []byte) error {
  938. temp := struct {
  939. Name string `json:"name"`
  940. Type ActivityType `json:"type"`
  941. URL string `json:"url,omitempty"`
  942. CreatedAt int64 `json:"created_at"`
  943. ApplicationID string `json:"application_id,omitempty"`
  944. State string `json:"state,omitempty"`
  945. Details string `json:"details,omitempty"`
  946. Timestamps TimeStamps `json:"timestamps,omitempty"`
  947. Emoji Emoji `json:"emoji,omitempty"`
  948. Party Party `json:"party,omitempty"`
  949. Assets Assets `json:"assets,omitempty"`
  950. Secrets Secrets `json:"secrets,omitempty"`
  951. Instance bool `json:"instance,omitempty"`
  952. Flags int `json:"flags,omitempty"`
  953. }{}
  954. err := json.Unmarshal(b, &temp)
  955. if err != nil {
  956. return err
  957. }
  958. activity.CreatedAt = time.Unix(0, temp.CreatedAt*1000000)
  959. activity.ApplicationID = temp.ApplicationID
  960. activity.Assets = temp.Assets
  961. activity.Details = temp.Details
  962. activity.Emoji = temp.Emoji
  963. activity.Flags = temp.Flags
  964. activity.Instance = temp.Instance
  965. activity.Name = temp.Name
  966. activity.Party = temp.Party
  967. activity.Secrets = temp.Secrets
  968. activity.State = temp.State
  969. activity.Timestamps = temp.Timestamps
  970. activity.Type = temp.Type
  971. activity.URL = temp.URL
  972. return nil
  973. }
  974. // Party defines the Party field in the Activity struct
  975. // https://discord.com/developers/docs/topics/gateway#activity-object
  976. type Party struct {
  977. ID string `json:"id,omitempty"`
  978. Size []int `json:"size,omitempty"`
  979. }
  980. // Secrets defines the Secrets field for the Activity struct
  981. // https://discord.com/developers/docs/topics/gateway#activity-object
  982. type Secrets struct {
  983. Join string `json:"join,omitempty"`
  984. Spectate string `json:"spectate,omitempty"`
  985. Match string `json:"match,omitempty"`
  986. }
  987. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  988. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  989. type ActivityType int
  990. // Valid ActivityType values
  991. const (
  992. ActivityTypeGame ActivityType = 0
  993. ActivityTypeStreaming ActivityType = 1
  994. ActivityTypeListening ActivityType = 2
  995. ActivityTypeWatching ActivityType = 3
  996. ActivityTypeCustom ActivityType = 4
  997. ActivityTypeCompeting ActivityType = 5
  998. )
  999. // Identify is sent during initial handshake with the discord gateway.
  1000. // https://discord.com/developers/docs/topics/gateway#identify
  1001. type Identify struct {
  1002. Token string `json:"token"`
  1003. Properties IdentifyProperties `json:"properties"`
  1004. Compress bool `json:"compress"`
  1005. LargeThreshold int `json:"large_threshold"`
  1006. Shard *[2]int `json:"shard,omitempty"`
  1007. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  1008. GuildSubscriptions bool `json:"guild_subscriptions"`
  1009. Intents Intent `json:"intents"`
  1010. }
  1011. // IdentifyProperties contains the "properties" portion of an Identify packet
  1012. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  1013. type IdentifyProperties struct {
  1014. OS string `json:"$os"`
  1015. Browser string `json:"$browser"`
  1016. Device string `json:"$device"`
  1017. Referer string `json:"$referer"`
  1018. ReferringDomain string `json:"$referring_domain"`
  1019. }
  1020. // Constants for the different bit offsets of text channel permissions
  1021. const (
  1022. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  1023. PermissionReadMessages = 0x0000000000000400
  1024. PermissionSendMessages = 0x0000000000000800
  1025. PermissionSendTTSMessages = 0x0000000000001000
  1026. PermissionManageMessages = 0x0000000000002000
  1027. PermissionEmbedLinks = 0x0000000000004000
  1028. PermissionAttachFiles = 0x0000000000008000
  1029. PermissionReadMessageHistory = 0x0000000000010000
  1030. PermissionMentionEveryone = 0x0000000000020000
  1031. PermissionUseExternalEmojis = 0x0000000000040000
  1032. PermissionUseSlashCommands = 0x0000000080000000
  1033. )
  1034. // Constants for the different bit offsets of voice permissions
  1035. const (
  1036. PermissionVoicePrioritySpeaker = 0x0000000000000100
  1037. PermissionVoiceStreamVideo = 0x0000000000000200
  1038. PermissionVoiceConnect = 0x0000000000100000
  1039. PermissionVoiceSpeak = 0x0000000000200000
  1040. PermissionVoiceMuteMembers = 0x0000000000400000
  1041. PermissionVoiceDeafenMembers = 0x0000000000800000
  1042. PermissionVoiceMoveMembers = 0x0000000001000000
  1043. PermissionVoiceUseVAD = 0x0000000002000000
  1044. PermissionVoiceRequestToSpeak = 0x0000000100000000
  1045. )
  1046. // Constants for general management.
  1047. const (
  1048. PermissionChangeNickname = 0x0000000004000000
  1049. PermissionManageNicknames = 0x0000000008000000
  1050. PermissionManageRoles = 0x0000000010000000
  1051. PermissionManageWebhooks = 0x0000000020000000
  1052. PermissionManageEmojis = 0x0000000040000000
  1053. )
  1054. // Constants for the different bit offsets of general permissions
  1055. const (
  1056. PermissionCreateInstantInvite = 0x0000000000000001
  1057. PermissionKickMembers = 0x0000000000000002
  1058. PermissionBanMembers = 0x0000000000000004
  1059. PermissionAdministrator = 0x0000000000000008
  1060. PermissionManageChannels = 0x0000000000000010
  1061. PermissionManageServer = 0x0000000000000020
  1062. PermissionAddReactions = 0x0000000000000040
  1063. PermissionViewAuditLogs = 0x0000000000000080
  1064. PermissionViewChannel = 0x0000000000000400
  1065. PermissionViewGuildInsights = 0x0000000000080000
  1066. PermissionAllText = PermissionViewChannel |
  1067. PermissionSendMessages |
  1068. PermissionSendTTSMessages |
  1069. PermissionManageMessages |
  1070. PermissionEmbedLinks |
  1071. PermissionAttachFiles |
  1072. PermissionReadMessageHistory |
  1073. PermissionMentionEveryone
  1074. PermissionAllVoice = PermissionViewChannel |
  1075. PermissionVoiceConnect |
  1076. PermissionVoiceSpeak |
  1077. PermissionVoiceMuteMembers |
  1078. PermissionVoiceDeafenMembers |
  1079. PermissionVoiceMoveMembers |
  1080. PermissionVoiceUseVAD |
  1081. PermissionVoicePrioritySpeaker
  1082. PermissionAllChannel = PermissionAllText |
  1083. PermissionAllVoice |
  1084. PermissionCreateInstantInvite |
  1085. PermissionManageRoles |
  1086. PermissionManageChannels |
  1087. PermissionAddReactions |
  1088. PermissionViewAuditLogs
  1089. PermissionAll = PermissionAllChannel |
  1090. PermissionKickMembers |
  1091. PermissionBanMembers |
  1092. PermissionManageServer |
  1093. PermissionAdministrator |
  1094. PermissionManageWebhooks |
  1095. PermissionManageEmojis
  1096. )
  1097. // Block contains Discord JSON Error Response codes
  1098. const (
  1099. ErrCodeUnknownAccount = 10001
  1100. ErrCodeUnknownApplication = 10002
  1101. ErrCodeUnknownChannel = 10003
  1102. ErrCodeUnknownGuild = 10004
  1103. ErrCodeUnknownIntegration = 10005
  1104. ErrCodeUnknownInvite = 10006
  1105. ErrCodeUnknownMember = 10007
  1106. ErrCodeUnknownMessage = 10008
  1107. ErrCodeUnknownOverwrite = 10009
  1108. ErrCodeUnknownProvider = 10010
  1109. ErrCodeUnknownRole = 10011
  1110. ErrCodeUnknownToken = 10012
  1111. ErrCodeUnknownUser = 10013
  1112. ErrCodeUnknownEmoji = 10014
  1113. ErrCodeUnknownWebhook = 10015
  1114. ErrCodeUnknownBan = 10026
  1115. ErrCodeBotsCannotUseEndpoint = 20001
  1116. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1117. ErrCodeMaximumGuildsReached = 30001
  1118. ErrCodeMaximumFriendsReached = 30002
  1119. ErrCodeMaximumPinsReached = 30003
  1120. ErrCodeMaximumGuildRolesReached = 30005
  1121. ErrCodeTooManyReactions = 30010
  1122. ErrCodeUnauthorized = 40001
  1123. ErrCodeMissingAccess = 50001
  1124. ErrCodeInvalidAccountType = 50002
  1125. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1126. ErrCodeEmbedDisabled = 50004
  1127. ErrCodeCannotEditFromAnotherUser = 50005
  1128. ErrCodeCannotSendEmptyMessage = 50006
  1129. ErrCodeCannotSendMessagesToThisUser = 50007
  1130. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1131. ErrCodeChannelVerificationLevelTooHigh = 50009
  1132. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1133. ErrCodeOAuth2ApplicationLimitReached = 50011
  1134. ErrCodeInvalidOAuthState = 50012
  1135. ErrCodeMissingPermissions = 50013
  1136. ErrCodeInvalidAuthenticationToken = 50014
  1137. ErrCodeNoteTooLong = 50015
  1138. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1139. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1140. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1141. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1142. ErrCodeInvalidFormBody = 50035
  1143. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1144. ErrCodeReactionBlocked = 90001
  1145. )
  1146. // Intent is the type of a Gateway Intent
  1147. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1148. type Intent int
  1149. // Constants for the different bit offsets of intents
  1150. const (
  1151. IntentsGuilds Intent = 1 << 0
  1152. IntentsGuildMembers Intent = 1 << 1
  1153. IntentsGuildBans Intent = 1 << 2
  1154. IntentsGuildEmojis Intent = 1 << 3
  1155. IntentsGuildIntegrations Intent = 1 << 4
  1156. IntentsGuildWebhooks Intent = 1 << 5
  1157. IntentsGuildInvites Intent = 1 << 6
  1158. IntentsGuildVoiceStates Intent = 1 << 7
  1159. IntentsGuildPresences Intent = 1 << 8
  1160. IntentsGuildMessages Intent = 1 << 9
  1161. IntentsGuildMessageReactions Intent = 1 << 10
  1162. IntentsGuildMessageTyping Intent = 1 << 11
  1163. IntentsDirectMessages Intent = 1 << 12
  1164. IntentsDirectMessageReactions Intent = 1 << 13
  1165. IntentsDirectMessageTyping Intent = 1 << 14
  1166. IntentsAllWithoutPrivileged = IntentsGuilds |
  1167. IntentsGuildBans |
  1168. IntentsGuildEmojis |
  1169. IntentsGuildIntegrations |
  1170. IntentsGuildWebhooks |
  1171. IntentsGuildInvites |
  1172. IntentsGuildVoiceStates |
  1173. IntentsGuildMessages |
  1174. IntentsGuildMessageReactions |
  1175. IntentsGuildMessageTyping |
  1176. IntentsDirectMessages |
  1177. IntentsDirectMessageReactions |
  1178. IntentsDirectMessageTyping
  1179. IntentsAll = IntentsAllWithoutPrivileged |
  1180. IntentsGuildMembers |
  1181. IntentsGuildPresences
  1182. IntentsNone Intent = 0
  1183. )
  1184. // MakeIntent used to help convert a gateway intent value for use in the Identify structure;
  1185. // this was useful to help support the use of a pointer type when intents were optional.
  1186. // This is now a no-op, and is not necessary to use.
  1187. func MakeIntent(intents Intent) Intent {
  1188. return intents
  1189. }