discord.js-selfv13 13.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discord.js-selfv13 might be problematic. Click here for more details.

Files changed (188) hide show
  1. package/.dccache +1 -0
  2. package/LICENSE +190 -0
  3. package/README.md +87 -0
  4. package/browser.js +9 -0
  5. package/deploy/deploy-key.enc +0 -0
  6. package/deploy/deploy.sh +90 -0
  7. package/deploy/test.sh +34 -0
  8. package/docs/README.md +1 -0
  9. package/docs/examples/attachments.md +163 -0
  10. package/docs/examples/avatars.js +29 -0
  11. package/docs/examples/embed.js +38 -0
  12. package/docs/examples/greeting.js +30 -0
  13. package/docs/examples/moderation.md +145 -0
  14. package/docs/examples/ping.js +29 -0
  15. package/docs/examples/webhook.js +12 -0
  16. package/docs/general/faq.md +23 -0
  17. package/docs/general/updating.md +181 -0
  18. package/docs/general/welcome.md +95 -0
  19. package/docs/index.yml +30 -0
  20. package/docs/logo.svg +19 -0
  21. package/docs/topics/voice.md +113 -0
  22. package/docs/topics/web.md +38 -0
  23. package/package.json +147 -0
  24. package/src/client/Client.js +564 -0
  25. package/src/client/ClientDataManager.js +150 -0
  26. package/src/client/ClientDataResolver.js +376 -0
  27. package/src/client/ClientManager.js +74 -0
  28. package/src/client/WebhookClient.js +118 -0
  29. package/src/client/actions/Action.js +23 -0
  30. package/src/client/actions/ActionsManager.js +40 -0
  31. package/src/client/actions/ChannelCreate.js +11 -0
  32. package/src/client/actions/ChannelDelete.js +30 -0
  33. package/src/client/actions/ChannelUpdate.js +74 -0
  34. package/src/client/actions/GuildBanRemove.js +13 -0
  35. package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
  36. package/src/client/actions/GuildDelete.js +57 -0
  37. package/src/client/actions/GuildEmojiCreate.js +17 -0
  38. package/src/client/actions/GuildEmojiDelete.js +18 -0
  39. package/src/client/actions/GuildEmojiUpdate.js +17 -0
  40. package/src/client/actions/GuildEmojisUpdate.js +38 -0
  41. package/src/client/actions/GuildMemberGet.js +10 -0
  42. package/src/client/actions/GuildMemberRemove.js +41 -0
  43. package/src/client/actions/GuildRoleCreate.js +26 -0
  44. package/src/client/actions/GuildRoleDelete.js +42 -0
  45. package/src/client/actions/GuildRoleUpdate.js +41 -0
  46. package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
  47. package/src/client/actions/GuildSync.js +29 -0
  48. package/src/client/actions/GuildUpdate.js +34 -0
  49. package/src/client/actions/MessageCreate.js +53 -0
  50. package/src/client/actions/MessageDelete.js +35 -0
  51. package/src/client/actions/MessageDeleteBulk.js +26 -0
  52. package/src/client/actions/MessageReactionAdd.js +37 -0
  53. package/src/client/actions/MessageReactionRemove.js +37 -0
  54. package/src/client/actions/MessageReactionRemoveAll.js +25 -0
  55. package/src/client/actions/MessageUpdate.js +40 -0
  56. package/src/client/actions/Ready.js +1 -0
  57. package/src/client/actions/Ready.js.bak +65 -0
  58. package/src/client/actions/UserGet.js +11 -0
  59. package/src/client/actions/UserNoteUpdate.js +30 -0
  60. package/src/client/actions/UserUpdate.js +33 -0
  61. package/src/client/rest/APIRequest.js +56 -0
  62. package/src/client/rest/DiscordAPIError.js +60 -0
  63. package/src/client/rest/RESTManager.js +58 -0
  64. package/src/client/rest/RESTMethods.js +1006 -0
  65. package/src/client/rest/RequestHandlers/Burst.js +90 -0
  66. package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
  67. package/src/client/rest/RequestHandlers/Sequential.js +132 -0
  68. package/src/client/rest/UserAgentManager.js +25 -0
  69. package/src/client/voice/ClientVoiceManager.js +81 -0
  70. package/src/client/voice/VoiceBroadcast.js +366 -0
  71. package/src/client/voice/VoiceConnection.js +530 -0
  72. package/src/client/voice/VoiceUDPClient.js +127 -0
  73. package/src/client/voice/VoiceWebSocket.js +246 -0
  74. package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
  75. package/src/client/voice/opus/BaseOpusEngine.js +60 -0
  76. package/src/client/voice/opus/NodeOpusEngine.js +40 -0
  77. package/src/client/voice/opus/OpusEngineList.js +28 -0
  78. package/src/client/voice/opus/OpusScriptEngine.js +45 -0
  79. package/src/client/voice/player/AudioPlayer.js +170 -0
  80. package/src/client/voice/receiver/VoiceReadable.js +17 -0
  81. package/src/client/voice/receiver/VoiceReceiver.js +219 -0
  82. package/src/client/voice/util/SecretKey.js +16 -0
  83. package/src/client/voice/util/Secretbox.js +33 -0
  84. package/src/client/voice/util/VolumeInterface.js +86 -0
  85. package/src/client/websocket/WebSocketConnection.js +506 -0
  86. package/src/client/websocket/WebSocketManager.js +90 -0
  87. package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
  88. package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
  89. package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
  90. package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
  91. package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
  92. package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
  93. package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
  94. package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
  95. package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
  96. package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
  97. package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
  98. package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
  99. package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
  100. package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
  101. package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
  102. package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
  103. package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
  104. package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
  105. package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
  106. package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
  107. package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
  108. package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
  109. package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
  110. package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
  111. package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
  112. package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
  113. package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
  114. package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
  115. package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
  116. package/src/client/websocket/packets/handlers/Ready.js +83 -0
  117. package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
  118. package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
  119. package/src/client/websocket/packets/handlers/Resumed.js +28 -0
  120. package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
  121. package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
  122. package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
  123. package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
  124. package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
  125. package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
  126. package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
  127. package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
  128. package/src/index.js +66 -0
  129. package/src/sharding/Shard.js +282 -0
  130. package/src/sharding/ShardClientUtil.js +146 -0
  131. package/src/sharding/ShardingManager.js +220 -0
  132. package/src/structures/Attachment.js +75 -0
  133. package/src/structures/CategoryChannel.js +22 -0
  134. package/src/structures/Channel.js +78 -0
  135. package/src/structures/ClientUser.js +447 -0
  136. package/src/structures/ClientUserChannelOverride.js +30 -0
  137. package/src/structures/ClientUserGuildSettings.js +60 -0
  138. package/src/structures/ClientUserSettings.js +80 -0
  139. package/src/structures/DMChannel.js +76 -0
  140. package/src/structures/Emoji.js +256 -0
  141. package/src/structures/GroupDMChannel.js +246 -0
  142. package/src/structures/Guild.js +1461 -0
  143. package/src/structures/GuildAuditLogs.js +371 -0
  144. package/src/structures/GuildChannel.js +537 -0
  145. package/src/structures/GuildMember.js +613 -0
  146. package/src/structures/Invite.js +164 -0
  147. package/src/structures/Message.js +605 -0
  148. package/src/structures/MessageAttachment.js +68 -0
  149. package/src/structures/MessageCollector.js +100 -0
  150. package/src/structures/MessageEmbed.js +386 -0
  151. package/src/structures/MessageMentions.js +144 -0
  152. package/src/structures/MessageReaction.js +96 -0
  153. package/src/structures/NewsChannel.js +24 -0
  154. package/src/structures/OAuth2Application.js +148 -0
  155. package/src/structures/PartialGuild.js +51 -0
  156. package/src/structures/PartialGuildChannel.js +44 -0
  157. package/src/structures/PermissionOverwrites.js +69 -0
  158. package/src/structures/Presence.js +241 -0
  159. package/src/structures/ReactionCollector.js +85 -0
  160. package/src/structures/ReactionEmoji.js +49 -0
  161. package/src/structures/RichEmbed.js +295 -0
  162. package/src/structures/Role.js +376 -0
  163. package/src/structures/StoreChannel.js +25 -0
  164. package/src/structures/TextChannel.js +154 -0
  165. package/src/structures/User.js +329 -0
  166. package/src/structures/UserConnection.js +48 -0
  167. package/src/structures/UserProfile.js +62 -0
  168. package/src/structures/VoiceChannel.js +146 -0
  169. package/src/structures/VoiceRegion.js +50 -0
  170. package/src/structures/Webhook.js +304 -0
  171. package/src/structures/interfaces/Collector.js +179 -0
  172. package/src/structures/interfaces/TextBasedChannel.js +635 -0
  173. package/src/structures/shared/resolvePermissions.js +26 -0
  174. package/src/util/Collection.js +532 -0
  175. package/src/util/Constants.js +845 -0
  176. package/src/util/Permissions.js +306 -0
  177. package/src/util/Snowflake.js +82 -0
  178. package/src/util/Util.js +221 -0
  179. package/test/random.js +207 -0
  180. package/test/shard.js +31 -0
  181. package/test/sharder.js +7 -0
  182. package/test/voice.js +78 -0
  183. package/test/webpack.html +31 -0
  184. package/tsconfig.json +13 -0
  185. package/tslint.json +62 -0
  186. package/typings/discord.js-test.ts +69 -0
  187. package/typings/index.d.ts +2190 -0
  188. package/webpack.config.js +62 -0
@@ -0,0 +1,154 @@
1
+ const GuildChannel = require('./GuildChannel');
2
+ const TextBasedChannel = require('./interfaces/TextBasedChannel');
3
+ const Collection = require('../util/Collection');
4
+
5
+ /**
6
+ * Represents a guild text channel on Discord.
7
+ * @extends {GuildChannel}
8
+ * @implements {TextBasedChannel}
9
+ */
10
+ class TextChannel extends GuildChannel {
11
+ constructor(guild, data) {
12
+ super(guild, data);
13
+ this.type = 'text';
14
+ /**
15
+ * A collection containing the messages sent to this channel
16
+ * @type {Collection<Snowflake, Message>}
17
+ */
18
+ this.messages = new Collection();
19
+ this._typing = new Map();
20
+ }
21
+
22
+ setup(data) {
23
+ super.setup(data);
24
+
25
+ /**
26
+ * The topic of the text channel
27
+ * @type {?string}
28
+ */
29
+ this.topic = data.topic;
30
+
31
+ /**
32
+ * If the Discord considers this channel NSFW
33
+ * @type {boolean}
34
+ * @readonly
35
+ */
36
+ this.nsfw = Boolean(data.nsfw);
37
+
38
+ /**
39
+ * The ID of the last message sent in this channel, if one was sent
40
+ * @type {?Snowflake}
41
+ */
42
+ this.lastMessageID = data.last_message_id;
43
+
44
+ /**
45
+ * The timestamp when the last pinned message was pinned, if there was one
46
+ * @type {?number}
47
+ */
48
+ this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
49
+
50
+ /**
51
+ * The ratelimit per user for this channel in seconds
52
+ * @type {number}
53
+ */
54
+ this.rateLimitPerUser = data.rate_limit_per_user || 0;
55
+ }
56
+
57
+ /**
58
+ * A collection of members that can see this channel, mapped by their ID
59
+ * @type {Collection<Snowflake, GuildMember>}
60
+ * @readonly
61
+ */
62
+ get members() {
63
+ const members = new Collection();
64
+ for (const member of this.guild.members.values()) {
65
+ if (this.permissionsFor(member).has('READ_MESSAGES')) {
66
+ members.set(member.id, member);
67
+ }
68
+ }
69
+ return members;
70
+ }
71
+
72
+ /**
73
+ * Fetch all webhooks for the channel.
74
+ * @returns {Promise<Collection<Snowflake, Webhook>>}
75
+ * @example
76
+ * // Fetch webhooks
77
+ * channel.fetchWebhooks()
78
+ * .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
79
+ * .catch(console.error);
80
+ */
81
+ fetchWebhooks() {
82
+ return this.client.rest.methods.getChannelWebhooks(this);
83
+ }
84
+
85
+ /**
86
+ * Sets whether this channel is flagged as NSFW.
87
+ * @param {boolean} nsfw Whether the channel should be considered NSFW
88
+ * @param {string} [reason] Reason for changing the channel's NSFW flag
89
+ * @returns {Promise<TextChannel>}
90
+ */
91
+ setNSFW(nsfw, reason) {
92
+ return this.edit({ nsfw }, reason);
93
+ }
94
+
95
+ /**
96
+ * Create a webhook for the channel.
97
+ * @param {string} name The name of the webhook
98
+ * @param {BufferResolvable|Base64Resolvable} [avatar] The avatar for the webhook
99
+ * @param {string} [reason] Reason for creating this webhook
100
+ * @returns {Promise<Webhook>} webhook The created webhook
101
+ * @example
102
+ * channel.createWebhook('Snek', 'https://i.imgur.com/mI8XcpG.jpg')
103
+ * .then(webhook => console.log(`Created webhook ${webhook}`))
104
+ * .catch(console.error)
105
+ */
106
+ createWebhook(name, avatar, reason) {
107
+ if (typeof avatar === 'string' && avatar.startsWith('data:')) {
108
+ return this.client.rest.methods.createWebhook(this, name, avatar, reason);
109
+ } else {
110
+ return this.client.resolver.resolveImage(avatar).then(data =>
111
+ this.client.rest.methods.createWebhook(this, name, data, reason)
112
+ );
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Sets the rate limit per user for this channel.
118
+ * @param {number} rateLimitPerUser The new ratelimit in seconds
119
+ * @param {string} [reason] Reason for changing the channel's ratelimits
120
+ * @returns {Promise<TextChannel>}
121
+ */
122
+ setRateLimitPerUser(rateLimitPerUser, reason) {
123
+ return this.edit({ rateLimitPerUser }, reason);
124
+ }
125
+
126
+ // These are here only for documentation purposes - they are implemented by TextBasedChannel
127
+ /* eslint-disable no-empty-function */
128
+ get lastMessage() {}
129
+ get lastPinAt() {}
130
+ send() { }
131
+ sendMessage() { }
132
+ sendEmbed() { }
133
+ sendFile() { }
134
+ sendFiles() { }
135
+ sendCode() { }
136
+ fetchMessage() { }
137
+ fetchMessages() { }
138
+ fetchPinnedMessages() { }
139
+ search() { }
140
+ startTyping() { }
141
+ stopTyping() { }
142
+ get typing() { }
143
+ get typingCount() { }
144
+ createCollector() { }
145
+ createMessageCollector() { }
146
+ awaitMessages() { }
147
+ bulkDelete() { }
148
+ acknowledge() { }
149
+ _cacheMessage() { }
150
+ }
151
+
152
+ TextBasedChannel.applyToClass(TextChannel, true);
153
+
154
+ module.exports = TextChannel;
@@ -0,0 +1,329 @@
1
+ const TextBasedChannel = require('./interfaces/TextBasedChannel');
2
+ const Constants = require('../util/Constants');
3
+ const Presence = require('./Presence').Presence;
4
+ const Snowflake = require('../util/Snowflake');
5
+ const util = require('util');
6
+
7
+ /**
8
+ * Represents a user on Discord.
9
+ * @implements {TextBasedChannel}
10
+ */
11
+ class User {
12
+ constructor(client, data) {
13
+ /**
14
+ * The client that created the instance of the user
15
+ * @name User#client
16
+ * @type {Client}
17
+ * @readonly
18
+ */
19
+ Object.defineProperty(this, 'client', { value: client });
20
+
21
+ if (data) this.setup(data);
22
+ }
23
+
24
+ setup(data) {
25
+ /**
26
+ * The ID of the user
27
+ * @type {Snowflake}
28
+ */
29
+ this.id = data.id;
30
+
31
+ /**
32
+ * The username of the user
33
+ * @type {string}
34
+ */
35
+ this.username = data.username;
36
+
37
+ /**
38
+ * A discriminator based on username for the user
39
+ * @type {string}
40
+ */
41
+ this.discriminator = data.discriminator;
42
+
43
+ /**
44
+ * The ID of the user's avatar
45
+ * @type {string}
46
+ */
47
+ this.avatar = data.avatar;
48
+
49
+ /**
50
+ * Whether or not the user is a bot
51
+ * @type {boolean}
52
+ */
53
+ this.bot = Boolean(data.bot);
54
+
55
+ /**
56
+ * The ID of the last message sent by the user, if one was sent
57
+ * @type {?Snowflake}
58
+ */
59
+ this.lastMessageID = null;
60
+
61
+ /**
62
+ * The Message object of the last message sent by the user, if one was sent
63
+ * @type {?Message}
64
+ */
65
+ this.lastMessage = null;
66
+ }
67
+
68
+ patch(data) {
69
+ for (const prop of ['id', 'username', 'discriminator', 'avatar', 'bot']) {
70
+ if (typeof data[prop] !== 'undefined') this[prop] = data[prop];
71
+ }
72
+ if (data.token) this.client.token = data.token;
73
+ }
74
+
75
+ /**
76
+ * The timestamp the user was created at
77
+ * @type {number}
78
+ * @readonly
79
+ */
80
+ get createdTimestamp() {
81
+ return Snowflake.deconstruct(this.id).timestamp;
82
+ }
83
+
84
+ /**
85
+ * The time the user was created
86
+ * @type {Date}
87
+ * @readonly
88
+ */
89
+ get createdAt() {
90
+ return new Date(this.createdTimestamp);
91
+ }
92
+
93
+ /**
94
+ * The presence of this user
95
+ * @type {Presence}
96
+ * @readonly
97
+ */
98
+ get presence() {
99
+ if (this.client.presences.has(this.id)) return this.client.presences.get(this.id);
100
+ for (const guild of this.client.guilds.values()) {
101
+ if (guild.presences.has(this.id)) return guild.presences.get(this.id);
102
+ }
103
+ return new Presence(undefined, this.client);
104
+ }
105
+
106
+ /**
107
+ * A link to the user's avatar
108
+ * @type {?string}
109
+ * @readonly
110
+ */
111
+ get avatarURL() {
112
+ if (!this.avatar) return null;
113
+ return Constants.Endpoints.User(this).Avatar(this.client.options.http.cdn, this.avatar);
114
+ }
115
+
116
+ /**
117
+ * A link to the user's default avatar
118
+ * @type {string}
119
+ * @readonly
120
+ */
121
+ get defaultAvatarURL() {
122
+ const avatars = Object.keys(Constants.DefaultAvatars);
123
+ const avatar = avatars[this.discriminator % avatars.length];
124
+ return Constants.Endpoints.CDN(this.client.options.http.host).Asset(`${Constants.DefaultAvatars[avatar]}.png`);
125
+ }
126
+
127
+ /**
128
+ * A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned
129
+ * @type {string}
130
+ * @readonly
131
+ */
132
+ get displayAvatarURL() {
133
+ return this.avatarURL || this.defaultAvatarURL;
134
+ }
135
+
136
+ /**
137
+ * The Discord "tag" (e.g. `hydrabolt#0001`) for this user
138
+ * @type {string}
139
+ * @readonly
140
+ */
141
+ get tag() {
142
+ return `${this.username}#${this.discriminator}`;
143
+ }
144
+
145
+ /**
146
+ * The note that is set for the user
147
+ * <warn>This is only available when using a user account.</warn>
148
+ * @type {?string}
149
+ * @readonly
150
+ * @deprecated
151
+ */
152
+ get note() {
153
+ return this.client.user.notes.get(this.id) || null;
154
+ }
155
+
156
+ /**
157
+ * Check whether the user is typing in a channel.
158
+ * @param {ChannelResolvable} channel The channel to check in
159
+ * @returns {boolean}
160
+ */
161
+ typingIn(channel) {
162
+ channel = this.client.resolver.resolveChannel(channel);
163
+ return channel._typing.has(this.id);
164
+ }
165
+
166
+ /**
167
+ * Get the time that the user started typing.
168
+ * @param {ChannelResolvable} channel The channel to get the time in
169
+ * @returns {?Date}
170
+ */
171
+ typingSinceIn(channel) {
172
+ channel = this.client.resolver.resolveChannel(channel);
173
+ return channel._typing.has(this.id) ? new Date(channel._typing.get(this.id).since) : null;
174
+ }
175
+
176
+ /**
177
+ * Get the amount of time the user has been typing in a channel for (in milliseconds), or -1 if they're not typing.
178
+ * @param {ChannelResolvable} channel The channel to get the time in
179
+ * @returns {number}
180
+ */
181
+ typingDurationIn(channel) {
182
+ channel = this.client.resolver.resolveChannel(channel);
183
+ return channel._typing.has(this.id) ? channel._typing.get(this.id).elapsedTime : -1;
184
+ }
185
+
186
+ /**
187
+ * The DM between the client's user and this user
188
+ * @type {?DMChannel}
189
+ * @readonly
190
+ */
191
+ get dmChannel() {
192
+ return this.client.channels.find(c => c.type === 'dm' && c.recipient.id === this.id);
193
+ }
194
+
195
+ /**
196
+ * Creates a DM channel between the client and the user.
197
+ * @returns {Promise<DMChannel>}
198
+ */
199
+ createDM() {
200
+ return this.client.rest.methods.createDM(this);
201
+ }
202
+
203
+ /**
204
+ * Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful.
205
+ * @returns {Promise<DMChannel>}
206
+ */
207
+ deleteDM() {
208
+ return this.client.rest.methods.deleteChannel(this);
209
+ }
210
+
211
+ /**
212
+ * Sends a friend request to the user.
213
+ * <warn>This is only available when using a user account.</warn>
214
+ * @returns {Promise<User>}
215
+ * @deprecated
216
+ */
217
+ addFriend() {
218
+ return this.client.rest.methods.addFriend(this);
219
+ }
220
+
221
+ /**
222
+ * Removes the user from your friends.
223
+ * <warn>This is only available when using a user account.</warn>
224
+ * @returns {Promise<User>}
225
+ * @deprecated
226
+ */
227
+ removeFriend() {
228
+ return this.client.rest.methods.removeFriend(this);
229
+ }
230
+
231
+ /**
232
+ * Blocks the user.
233
+ * <warn>This is only available when using a user account.</warn>
234
+ * @returns {Promise<User>}
235
+ * @deprecated
236
+ */
237
+ block() {
238
+ return this.client.rest.methods.blockUser(this);
239
+ }
240
+
241
+ /**
242
+ * Unblocks the user.
243
+ * <warn>This is only available when using a user account.</warn>
244
+ * @returns {Promise<User>}
245
+ * @deprecated
246
+ */
247
+ unblock() {
248
+ return this.client.rest.methods.unblockUser(this);
249
+ }
250
+
251
+ /**
252
+ * Get the profile of the user.
253
+ * <warn>This is only available when using a user account.</warn>
254
+ * @returns {Promise<UserProfile>}
255
+ * @deprecated
256
+ */
257
+ fetchProfile() {
258
+ return this.client.rest.methods.fetchUserProfile(this);
259
+ }
260
+
261
+ /**
262
+ * Sets a note for the user.
263
+ * <warn>This is only available when using a user account.</warn>
264
+ * @param {string} note The note to set for the user
265
+ * @returns {Promise<User>}
266
+ * @deprecated
267
+ */
268
+ setNote(note) {
269
+ return this.client.rest.methods.setNote(this, note);
270
+ }
271
+
272
+ /**
273
+ * Checks if the user is equal to another. It compares ID, username, discriminator, avatar, and bot flags.
274
+ * It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
275
+ * @param {User} user User to compare with
276
+ * @returns {boolean}
277
+ */
278
+ equals(user) {
279
+ let equal = user &&
280
+ this.id === user.id &&
281
+ this.username === user.username &&
282
+ this.discriminator === user.discriminator &&
283
+ this.avatar === user.avatar &&
284
+ this.bot === Boolean(user.bot);
285
+
286
+ return equal;
287
+ }
288
+
289
+ /**
290
+ * When concatenated with a string, this automatically concatenates the user's mention instead of the User object.
291
+ * @returns {string}
292
+ * @example
293
+ * // logs: Hello from <@123456789>!
294
+ * console.log(`Hello from ${user}!`);
295
+ */
296
+ toString() {
297
+ return `<@${this.id}>`;
298
+ }
299
+
300
+ // These are here only for documentation purposes - they are implemented by TextBasedChannel
301
+ /* eslint-disable no-empty-function */
302
+ send() {}
303
+ sendMessage() {}
304
+ sendEmbed() {}
305
+ sendFile() {}
306
+ sendCode() {}
307
+ }
308
+
309
+ TextBasedChannel.applyToClass(User);
310
+
311
+ User.prototype.block =
312
+ util.deprecate(User.prototype.block, 'User#block: userbot methods will be removed');
313
+
314
+ User.prototype.unblock =
315
+ util.deprecate(User.prototype.unblock, 'User#unblock: userbot methods will be removed');
316
+
317
+ User.prototype.addFriend =
318
+ util.deprecate(User.prototype.addFriend, 'User#addFriend: userbot methods will be removed');
319
+
320
+ User.prototype.removeFriend =
321
+ util.deprecate(User.prototype.removeFriend, 'User#removeFriend: userbot methods will be removed');
322
+
323
+ User.prototype.setNote =
324
+ util.deprecate(User.prototype.setNote, 'User#setNote, userbot methods will be removed');
325
+
326
+ User.prototype.fetchProfile =
327
+ util.deprecate(User.prototype.fetchProfile, 'User#fetchProfile: userbot methods will be removed');
328
+
329
+ module.exports = User;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Represents a user connection (or "platform identity").
3
+ */
4
+ class UserConnection {
5
+ constructor(user, data) {
6
+ /**
7
+ * The user that owns the connection
8
+ * @type {User}
9
+ */
10
+ this.user = user;
11
+
12
+ this.setup(data);
13
+ }
14
+
15
+ setup(data) {
16
+ /**
17
+ * The type of the connection
18
+ * @type {string}
19
+ */
20
+ this.type = data.type;
21
+
22
+ /**
23
+ * The username of the connection account
24
+ * @type {string}
25
+ */
26
+ this.name = data.name;
27
+
28
+ /**
29
+ * The id of the connection account
30
+ * @type {string}
31
+ */
32
+ this.id = data.id;
33
+
34
+ /**
35
+ * Whether the connection is revoked
36
+ * @type {boolean}
37
+ */
38
+ this.revoked = data.revoked;
39
+
40
+ /**
41
+ * Partial server integrations (not yet implemented)
42
+ * @type {Object[]}
43
+ */
44
+ this.integrations = data.integrations;
45
+ }
46
+ }
47
+
48
+ module.exports = UserConnection;
@@ -0,0 +1,62 @@
1
+ const Collection = require('../util/Collection');
2
+ const UserConnection = require('./UserConnection');
3
+
4
+ /**
5
+ * Represents a user's profile on Discord.
6
+ */
7
+ class UserProfile {
8
+ constructor(user, data) {
9
+ /**
10
+ * The owner of the profile
11
+ * @type {User}
12
+ */
13
+ this.user = user;
14
+
15
+ /**
16
+ * The client that created the instance of the UserProfile
17
+ * @name UserProfile#client
18
+ * @type {Client}
19
+ * @readonly
20
+ */
21
+ Object.defineProperty(this, 'client', { value: user.client });
22
+
23
+ /**
24
+ * The guilds that the client user and the user share
25
+ * @type {Collection<Snowflake, Guild>}
26
+ */
27
+ this.mutualGuilds = new Collection();
28
+
29
+ /**
30
+ * The user's connections
31
+ * @type {Collection<Snowflake, UserConnection>}
32
+ */
33
+ this.connections = new Collection();
34
+
35
+ this.setup(data);
36
+ }
37
+
38
+ setup(data) {
39
+ /**
40
+ * If the user has Discord Premium
41
+ * @type {boolean}
42
+ */
43
+ this.premium = data.premium;
44
+
45
+ /**
46
+ * The date since which the user has had Discord Premium
47
+ * @type {?Date}
48
+ */
49
+ this.premiumSince = data.premium_since ? new Date(data.premium_since) : null;
50
+
51
+ for (const guild of data.mutual_guilds) {
52
+ if (this.client.guilds.has(guild.id)) {
53
+ this.mutualGuilds.set(guild.id, this.client.guilds.get(guild.id));
54
+ }
55
+ }
56
+ for (const connection of data.connected_accounts) {
57
+ this.connections.set(connection.id, new UserConnection(this.user, connection));
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = UserProfile;