structs.go 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  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 recieved (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 = iota
  123. ExpireBehaviorKick
  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 = iota
  174. )
  175. // ChannelType is the type of a Channel
  176. type ChannelType int
  177. // Block contains known ChannelType values
  178. const (
  179. ChannelTypeGuildText ChannelType = iota
  180. ChannelTypeDM
  181. ChannelTypeGuildVoice
  182. ChannelTypeGroupDM
  183. ChannelTypeGuildCategory
  184. ChannelTypeGuildNews
  185. ChannelTypeGuildStore
  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 = iota
  260. PermissionOverwriteTypeMember
  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 = iota
  309. VerificationLevelLow
  310. VerificationLevelMedium
  311. VerificationLevelHigh
  312. VerificationLevelVeryHigh
  313. )
  314. // ExplicitContentFilterLevel type definition
  315. type ExplicitContentFilterLevel int
  316. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  317. const (
  318. ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
  319. ExplicitContentFilterMembersWithoutRoles
  320. ExplicitContentFilterAllMembers
  321. )
  322. // MfaLevel type definition
  323. type MfaLevel int
  324. // Constants for MfaLevel levels from 0 to 1 inclusive
  325. const (
  326. MfaLevelNone MfaLevel = iota
  327. MfaLevelElevated
  328. )
  329. // PremiumTier type definition
  330. type PremiumTier int
  331. // Constants for PremiumTier levels from 0 to 3 inclusive
  332. const (
  333. PremiumTierNone PremiumTier = iota
  334. PremiumTier1
  335. PremiumTier2
  336. PremiumTier3
  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 = iota
  477. MessageNotificationsOnlyMentions
  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 << iota
  485. SystemChannelFlagsSuppressPremium
  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. }
  895. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  896. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  897. type GatewayStatusUpdate struct {
  898. Since int `json:"since"`
  899. Game Activity `json:"game"`
  900. Status string `json:"status"`
  901. AFK bool `json:"afk"`
  902. }
  903. // Activity defines the Activity sent with GatewayStatusUpdate
  904. // https://discord.com/developers/docs/topics/gateway#activity-object
  905. type Activity struct {
  906. Name string `json:"name"`
  907. Type ActivityType `json:"type"`
  908. URL string `json:"url,omitempty"`
  909. CreatedAt time.Time `json:"created_at"`
  910. ApplicationID string `json:"application_id,omitempty"`
  911. State string `json:"state,omitempty"`
  912. Details string `json:"details,omitempty"`
  913. Timestamps TimeStamps `json:"timestamps,omitempty"`
  914. Emoji Emoji `json:"emoji,omitempty"`
  915. Party Party `json:"party,omitempty"`
  916. Assets Assets `json:"assets,omitempty"`
  917. Secrets Secrets `json:"secrets,omitempty"`
  918. Instance bool `json:"instance,omitempty"`
  919. Flags int `json:"flags,omitempty"`
  920. }
  921. // UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
  922. func (activity *Activity) UnmarshalJSON(b []byte) error {
  923. temp := struct {
  924. Name string `json:"name"`
  925. Type ActivityType `json:"type"`
  926. URL string `json:"url,omitempty"`
  927. CreatedAt int64 `json:"created_at"`
  928. ApplicationID string `json:"application_id,omitempty"`
  929. State string `json:"state,omitempty"`
  930. Details string `json:"details,omitempty"`
  931. Timestamps TimeStamps `json:"timestamps,omitempty"`
  932. Emoji Emoji `json:"emoji,omitempty"`
  933. Party Party `json:"party,omitempty"`
  934. Assets Assets `json:"assets,omitempty"`
  935. Secrets Secrets `json:"secrets,omitempty"`
  936. Instance bool `json:"instance,omitempty"`
  937. Flags int `json:"flags,omitempty"`
  938. }{}
  939. err := json.Unmarshal(b, &temp)
  940. if err != nil {
  941. return err
  942. }
  943. activity.CreatedAt = time.Unix(0, temp.CreatedAt*1000000)
  944. activity.ApplicationID = temp.ApplicationID
  945. activity.Assets = temp.Assets
  946. activity.Details = temp.Details
  947. activity.Emoji = temp.Emoji
  948. activity.Flags = temp.Flags
  949. activity.Instance = temp.Instance
  950. activity.Name = temp.Name
  951. activity.Party = temp.Party
  952. activity.Secrets = temp.Secrets
  953. activity.State = temp.State
  954. activity.Timestamps = temp.Timestamps
  955. activity.Type = temp.Type
  956. activity.URL = temp.URL
  957. return nil
  958. }
  959. // Party defines the Party field in the Activity struct
  960. // https://discord.com/developers/docs/topics/gateway#activity-object
  961. type Party struct {
  962. ID string `json:"id,omitempty"`
  963. Size []int `json:"size,omitempty"`
  964. }
  965. // Secrets defines the Secrets field for the Activity struct
  966. // https://discord.com/developers/docs/topics/gateway#activity-object
  967. type Secrets struct {
  968. Join string `json:"join,omitempty"`
  969. Spectate string `json:"spectate,omitempty"`
  970. Match string `json:"match,omitempty"`
  971. }
  972. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  973. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  974. type ActivityType int
  975. // Valid ActivityType values
  976. const (
  977. ActivityTypeGame ActivityType = iota
  978. ActivityTypeStreaming
  979. ActivityTypeListening
  980. // ActivityTypeWatching // not valid in this use case?
  981. ActivityTypeCustom = 4
  982. )
  983. // Identify is sent during initial handshake with the discord gateway.
  984. // https://discord.com/developers/docs/topics/gateway#identify
  985. type Identify struct {
  986. Token string `json:"token"`
  987. Properties IdentifyProperties `json:"properties"`
  988. Compress bool `json:"compress"`
  989. LargeThreshold int `json:"large_threshold"`
  990. Shard *[2]int `json:"shard,omitempty"`
  991. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  992. GuildSubscriptions bool `json:"guild_subscriptions"`
  993. Intents Intent `json:"intents"`
  994. }
  995. // IdentifyProperties contains the "properties" portion of an Identify packet
  996. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  997. type IdentifyProperties struct {
  998. OS string `json:"$os"`
  999. Browser string `json:"$browser"`
  1000. Device string `json:"$device"`
  1001. Referer string `json:"$referer"`
  1002. ReferringDomain string `json:"$referring_domain"`
  1003. }
  1004. // Constants for the different bit offsets of text channel permissions
  1005. const (
  1006. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  1007. PermissionReadMessages = 0x0000000000000400
  1008. PermissionSendMessages = 0x0000000000000800
  1009. PermissionSendTTSMessages = 0x0000000000001000
  1010. PermissionManageMessages = 0x0000000000002000
  1011. PermissionEmbedLinks = 0x0000000000004000
  1012. PermissionAttachFiles = 0x0000000000008000
  1013. PermissionReadMessageHistory = 0x0000000000010000
  1014. PermissionMentionEveryone = 0x0000000000020000
  1015. PermissionUseExternalEmojis = 0x0000000000040000
  1016. PermissionUseSlashCommands = 0x0000000080000000
  1017. )
  1018. // Constants for the different bit offsets of voice permissions
  1019. const (
  1020. PermissionVoicePrioritySpeaker = 0x0000000000000100
  1021. PermissionVoiceStreamVideo = 0x0000000000000200
  1022. PermissionVoiceConnect = 0x0000000000100000
  1023. PermissionVoiceSpeak = 0x0000000000200000
  1024. PermissionVoiceMuteMembers = 0x0000000000400000
  1025. PermissionVoiceDeafenMembers = 0x0000000000800000
  1026. PermissionVoiceMoveMembers = 0x0000000001000000
  1027. PermissionVoiceUseVAD = 0x0000000002000000
  1028. PermissionVoiceRequestToSpeak = 0x0000000100000000
  1029. )
  1030. // Constants for general management.
  1031. const (
  1032. PermissionChangeNickname = 0x0000000004000000
  1033. PermissionManageNicknames = 0x0000000008000000
  1034. PermissionManageRoles = 0x0000000010000000
  1035. PermissionManageWebhooks = 0x0000000020000000
  1036. PermissionManageEmojis = 0x0000000040000000
  1037. )
  1038. // Constants for the different bit offsets of general permissions
  1039. const (
  1040. PermissionCreateInstantInvite = 0x0000000000000001
  1041. PermissionKickMembers = 0x0000000000000002
  1042. PermissionBanMembers = 0x0000000000000004
  1043. PermissionAdministrator = 0x0000000000000008
  1044. PermissionManageChannels = 0x0000000000000010
  1045. PermissionManageServer = 0x0000000000000020
  1046. PermissionAddReactions = 0x0000000000000040
  1047. PermissionViewAuditLogs = 0x0000000000000080
  1048. PermissionViewChannel = 0x0000000000000400
  1049. PermissionViewGuildInsights = 0x0000000000080000
  1050. PermissionAllText = PermissionViewChannel |
  1051. PermissionSendMessages |
  1052. PermissionSendTTSMessages |
  1053. PermissionManageMessages |
  1054. PermissionEmbedLinks |
  1055. PermissionAttachFiles |
  1056. PermissionReadMessageHistory |
  1057. PermissionMentionEveryone
  1058. PermissionAllVoice = PermissionViewChannel |
  1059. PermissionVoiceConnect |
  1060. PermissionVoiceSpeak |
  1061. PermissionVoiceMuteMembers |
  1062. PermissionVoiceDeafenMembers |
  1063. PermissionVoiceMoveMembers |
  1064. PermissionVoiceUseVAD |
  1065. PermissionVoicePrioritySpeaker
  1066. PermissionAllChannel = PermissionAllText |
  1067. PermissionAllVoice |
  1068. PermissionCreateInstantInvite |
  1069. PermissionManageRoles |
  1070. PermissionManageChannels |
  1071. PermissionAddReactions |
  1072. PermissionViewAuditLogs
  1073. PermissionAll = PermissionAllChannel |
  1074. PermissionKickMembers |
  1075. PermissionBanMembers |
  1076. PermissionManageServer |
  1077. PermissionAdministrator |
  1078. PermissionManageWebhooks |
  1079. PermissionManageEmojis
  1080. )
  1081. // Block contains Discord JSON Error Response codes
  1082. const (
  1083. ErrCodeUnknownAccount = 10001
  1084. ErrCodeUnknownApplication = 10002
  1085. ErrCodeUnknownChannel = 10003
  1086. ErrCodeUnknownGuild = 10004
  1087. ErrCodeUnknownIntegration = 10005
  1088. ErrCodeUnknownInvite = 10006
  1089. ErrCodeUnknownMember = 10007
  1090. ErrCodeUnknownMessage = 10008
  1091. ErrCodeUnknownOverwrite = 10009
  1092. ErrCodeUnknownProvider = 10010
  1093. ErrCodeUnknownRole = 10011
  1094. ErrCodeUnknownToken = 10012
  1095. ErrCodeUnknownUser = 10013
  1096. ErrCodeUnknownEmoji = 10014
  1097. ErrCodeUnknownWebhook = 10015
  1098. ErrCodeUnknownBan = 10026
  1099. ErrCodeBotsCannotUseEndpoint = 20001
  1100. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1101. ErrCodeMaximumGuildsReached = 30001
  1102. ErrCodeMaximumFriendsReached = 30002
  1103. ErrCodeMaximumPinsReached = 30003
  1104. ErrCodeMaximumGuildRolesReached = 30005
  1105. ErrCodeTooManyReactions = 30010
  1106. ErrCodeUnauthorized = 40001
  1107. ErrCodeMissingAccess = 50001
  1108. ErrCodeInvalidAccountType = 50002
  1109. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1110. ErrCodeEmbedDisabled = 50004
  1111. ErrCodeCannotEditFromAnotherUser = 50005
  1112. ErrCodeCannotSendEmptyMessage = 50006
  1113. ErrCodeCannotSendMessagesToThisUser = 50007
  1114. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1115. ErrCodeChannelVerificationLevelTooHigh = 50009
  1116. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1117. ErrCodeOAuth2ApplicationLimitReached = 50011
  1118. ErrCodeInvalidOAuthState = 50012
  1119. ErrCodeMissingPermissions = 50013
  1120. ErrCodeInvalidAuthenticationToken = 50014
  1121. ErrCodeNoteTooLong = 50015
  1122. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1123. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1124. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1125. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1126. ErrCodeInvalidFormBody = 50035
  1127. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1128. ErrCodeReactionBlocked = 90001
  1129. )
  1130. // Intent is the type of a Gateway Intent
  1131. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1132. type Intent int
  1133. // Constants for the different bit offsets of intents
  1134. const (
  1135. IntentsGuilds Intent = 1 << iota
  1136. IntentsGuildMembers
  1137. IntentsGuildBans
  1138. IntentsGuildEmojis
  1139. IntentsGuildIntegrations
  1140. IntentsGuildWebhooks
  1141. IntentsGuildInvites
  1142. IntentsGuildVoiceStates
  1143. IntentsGuildPresences
  1144. IntentsGuildMessages
  1145. IntentsGuildMessageReactions
  1146. IntentsGuildMessageTyping
  1147. IntentsDirectMessages
  1148. IntentsDirectMessageReactions
  1149. IntentsDirectMessageTyping
  1150. IntentsAllWithoutPrivileged = IntentsGuilds |
  1151. IntentsGuildBans |
  1152. IntentsGuildEmojis |
  1153. IntentsGuildIntegrations |
  1154. IntentsGuildWebhooks |
  1155. IntentsGuildInvites |
  1156. IntentsGuildVoiceStates |
  1157. IntentsGuildMessages |
  1158. IntentsGuildMessageReactions |
  1159. IntentsGuildMessageTyping |
  1160. IntentsDirectMessages |
  1161. IntentsDirectMessageReactions |
  1162. IntentsDirectMessageTyping
  1163. IntentsAll = IntentsAllWithoutPrivileged |
  1164. IntentsGuildMembers |
  1165. IntentsGuildPresences
  1166. IntentsNone Intent = 0
  1167. )
  1168. // MakeIntent used to help convert a gateway intent value for use in the Identify structure;
  1169. // this was useful to help support the use of a pointer type when intents were optional.
  1170. // This is now a no-op, and is not necessary to use.
  1171. func MakeIntent(intents Intent) Intent {
  1172. return intents
  1173. }