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,447 @@
1
+ const User = require('./User');
2
+ const Collection = require('../util/Collection');
3
+ const ClientUserSettings = require('./ClientUserSettings');
4
+ const ClientUserGuildSettings = require('./ClientUserGuildSettings');
5
+ const Constants = require('../util/Constants');
6
+ const util = require('util');
7
+
8
+ /**
9
+ * Represents the logged in client's Discord user.
10
+ * @extends {User}
11
+ */
12
+ class ClientUser extends User {
13
+ setup(data) {
14
+ super.setup(data);
15
+
16
+ /**
17
+ * Whether or not this account has been verified
18
+ * @type {boolean}
19
+ */
20
+ this.verified = data.verified;
21
+
22
+ /**
23
+ * The email of this account
24
+ * <warn>This is only filled when using a user account.</warn>
25
+ * @type {?string}
26
+ * @deprecated
27
+ */
28
+ this.email = data.email;
29
+ this.localPresence = {};
30
+ this._typing = new Map();
31
+
32
+ /**
33
+ * A Collection of friends for the logged in user
34
+ * <warn>This is only filled when using a user account.</warn>
35
+ * @type {Collection<Snowflake, User>}
36
+ * @deprecated
37
+ */
38
+ this.friends = new Collection();
39
+
40
+ /**
41
+ * A Collection of blocked users for the logged in user
42
+ * <warn>This is only filled when using a user account.</warn>
43
+ * @type {Collection<Snowflake, User>}
44
+ * @deprecated
45
+ */
46
+ this.blocked = new Collection();
47
+
48
+ /**
49
+ * A Collection of notes for the logged in user
50
+ * <warn>This is only filled when using a user account.</warn>
51
+ * @type {Collection<Snowflake, string>}
52
+ * @deprecated
53
+ */
54
+ this.notes = new Collection();
55
+
56
+ /**
57
+ * If the user has Discord premium (nitro)
58
+ * <warn>This is only filled when using a user account.</warn>
59
+ * @type {?boolean}
60
+ * @deprecated
61
+ */
62
+ this.premium = typeof data.premium === 'boolean' ? data.premium : null;
63
+
64
+ /**
65
+ * If the user has MFA enabled on their account
66
+ * @type {boolean}
67
+ */
68
+ this.mfaEnabled = data.mfa_enabled;
69
+
70
+ /**
71
+ * If the user has ever used a mobile device on Discord
72
+ * <warn>This is only filled when using a user account.</warn>
73
+ * @type {?boolean}
74
+ * @deprecated
75
+ */
76
+ this.mobile = typeof data.mobile === 'boolean' ? data.mobile : null;
77
+
78
+ /**
79
+ * Various settings for this user
80
+ * <warn>This is only filled when using a user account.</warn>
81
+ * @type {?ClientUserSettings}
82
+ * @deprecated
83
+ */
84
+ this.settings = data.user_settings ? new ClientUserSettings(this, data.user_settings) : null;
85
+
86
+ /**
87
+ * All of the user's guild settings
88
+ * <warn>This is only filled when using a user account</warn>
89
+ * @type {Collection<Snowflake, ClientUserGuildSettings>}
90
+ * @deprecated
91
+ */
92
+ this.guildSettings = new Collection();
93
+ if (data.user_guild_settings) {
94
+ for (const settings of data.user_guild_settings) {
95
+ this.guildSettings.set(settings.guild_id, new ClientUserGuildSettings(settings, this.client));
96
+ }
97
+ }
98
+ }
99
+
100
+ edit(data) {
101
+ return this.client.rest.methods.updateCurrentUser(data);
102
+ }
103
+
104
+ /**
105
+ * Set the username of the logged in client.
106
+ * <info>Changing usernames in Discord is heavily rate limited, with only 2 requests
107
+ * every hour. Use this sparingly!</info>
108
+ * @param {string} username The new username
109
+ * @param {string} [password] Current password (only for user accounts)
110
+ * @returns {Promise<ClientUser>}
111
+ * @example
112
+ * // Set username
113
+ * client.user.setUsername('discordjs')
114
+ * .then(user => console.log(`My new username is ${user.username}`))
115
+ * .catch(console.error);
116
+ */
117
+ setUsername(username, password) {
118
+ return this.client.rest.methods.updateCurrentUser({ username }, password);
119
+ }
120
+
121
+ /**
122
+ * Changes the email for the client user's account.
123
+ * <warn>This is only available when using a user account.</warn>
124
+ * @param {string} email New email to change to
125
+ * @param {string} password Current password
126
+ * @returns {Promise<ClientUser>}
127
+ * @deprecated
128
+ * @example
129
+ * // Set email
130
+ * client.user.setEmail('bob@gmail.com', 'some amazing password 123')
131
+ * .then(user => console.log(`My new email is ${user.email}`))
132
+ * .catch(console.error);
133
+ */
134
+ setEmail(email, password) {
135
+ return this.client.rest.methods.updateCurrentUser({ email }, password);
136
+ }
137
+
138
+ /**
139
+ * Changes the password for the client user's account.
140
+ * <warn>This is only available when using a user account.</warn>
141
+ * @param {string} newPassword New password to change to
142
+ * @param {string} oldPassword Current password
143
+ * @returns {Promise<ClientUser>}
144
+ * @deprecated
145
+ * @example
146
+ * // Set password
147
+ * client.user.setPassword('some new amazing password 456', 'some amazing password 123')
148
+ * .then(user => console.log('New password set!'))
149
+ * .catch(console.error);
150
+ */
151
+ setPassword(newPassword, oldPassword) {
152
+ return this.client.rest.methods.updateCurrentUser({ password: newPassword }, oldPassword);
153
+ }
154
+
155
+ /**
156
+ * Set the avatar of the logged in client.
157
+ * @param {BufferResolvable|Base64Resolvable} avatar The new avatar
158
+ * @returns {Promise<ClientUser>}
159
+ * @example
160
+ * // Set avatar
161
+ * client.user.setAvatar('./avatar.png')
162
+ * .then(user => console.log(`New avatar set!`))
163
+ * .catch(console.error);
164
+ */
165
+ setAvatar(avatar) {
166
+ return this.client.resolver.resolveImage(avatar).then(data =>
167
+ this.client.rest.methods.updateCurrentUser({ avatar: data })
168
+ );
169
+ }
170
+
171
+ /**
172
+ * Data resembling a raw Discord presence.
173
+ * @typedef {Object} PresenceData
174
+ * @property {PresenceStatus} [status] Status of the user
175
+ * @property {boolean} [afk] Whether the user is AFK
176
+ * @property {Object} [game] Game the user is playing
177
+ * @property {string} [game.name] Name of the game
178
+ * @property {string} [game.url] Twitch stream URL
179
+ * @property {?ActivityType|number} [game.type] Type of the activity
180
+ */
181
+
182
+ /**
183
+ * Sets the full presence of the client user.
184
+ * @param {PresenceData} data Data for the presence
185
+ * @returns {Promise<ClientUser>}
186
+ * @example
187
+ * // Set the client user's presence
188
+ * client.user.setPresence({ game: { name: 'with discord.js' }, status: 'idle' })
189
+ * .then(console.log)
190
+ * .catch(console.error);
191
+ */
192
+ setPresence(data) {
193
+ // {"op":3,"d":{"status":"dnd","since":0,"game":null,"afk":false}}
194
+ return new Promise(resolve => {
195
+ let status = this.localPresence.status || this.presence.status;
196
+ let game = this.localPresence.game;
197
+ let afk = this.localPresence.afk || this.presence.afk;
198
+
199
+ if (!game && this.presence.game) {
200
+ game = {
201
+ name: this.presence.game.name,
202
+ type: this.presence.game.type,
203
+ url: this.presence.game.url,
204
+ };
205
+ }
206
+
207
+ if (data.status) {
208
+ if (typeof data.status !== 'string') throw new TypeError('Status must be a string');
209
+ if (this.bot) {
210
+ status = data.status;
211
+ } else {
212
+ this.settings.update(Constants.UserSettingsMap.status, data.status);
213
+ status = 'invisible';
214
+ }
215
+ }
216
+
217
+ if (data.game) {
218
+ game = data.game;
219
+ game.type = game.url && typeof game.type === 'undefined' ? 1 : game.type || 0;
220
+ if (typeof game.type === 'string') {
221
+ game.type = Constants.ActivityTypes.indexOf(game.type.toUpperCase());
222
+ }
223
+ } else if (typeof data.game !== 'undefined') {
224
+ game = null;
225
+ }
226
+
227
+ if (typeof data.afk !== 'undefined') afk = data.afk;
228
+ afk = Boolean(afk);
229
+
230
+ this.localPresence = { status, game, afk };
231
+ this.localPresence.since = 0;
232
+ this.localPresence.game = this.localPresence.game || null;
233
+
234
+ this.client.ws.send({
235
+ op: 3,
236
+ d: this.localPresence,
237
+ });
238
+
239
+ this.client._setPresence(this.id, this.localPresence);
240
+
241
+ resolve(this);
242
+ });
243
+ }
244
+
245
+ /**
246
+ * A user's status. Must be one of:
247
+ * * `online`
248
+ * * `idle`
249
+ * * `invisible`
250
+ * * `dnd` (do not disturb)
251
+ * @typedef {string} PresenceStatus
252
+ */
253
+
254
+ /**
255
+ * Sets the status of the client user.
256
+ * @param {PresenceStatus} status Status to change to
257
+ * @returns {Promise<ClientUser>}
258
+ * @example
259
+ * // Set the client user's status
260
+ * client.user.setStatus('idle')
261
+ * .then(console.log)
262
+ * .catch(console.error);
263
+ */
264
+ setStatus(status) {
265
+ return this.setPresence({ status });
266
+ }
267
+
268
+ /**
269
+ * Sets the game the client user is playing.
270
+ * @param {?string} game Game being played
271
+ * @param {?string} [streamingURL] Twitch stream URL
272
+ * @returns {Promise<ClientUser>}
273
+ * @deprecated
274
+ */
275
+ setGame(game, streamingURL) {
276
+ if (!game) return this.setPresence({ game: null });
277
+ return this.setPresence({
278
+ game: {
279
+ name: game,
280
+ url: streamingURL,
281
+ },
282
+ });
283
+ }
284
+
285
+ /**
286
+ * Sets the activity the client user is playing.
287
+ * @param {?string} name Activity being played
288
+ * @param {Object} [options] Options for setting the activity
289
+ * @param {string} [options.url] Twitch stream URL
290
+ * @param {ActivityType|number} [options.type] Type of the activity
291
+ * @returns {Promise<Presence>}
292
+ * @example
293
+ * client.user.setActivity('YouTube', { type: 'WATCHING' })
294
+ * .then(presence => console.log(`Activity set to ${presence.game ? presence.game.name : 'none'}`))
295
+ * .catch(console.error);
296
+ */
297
+ setActivity(name, { url, type } = {}) {
298
+ if (!name) return this.setPresence({ game: null });
299
+ return this.setPresence({
300
+ game: { name, type, url },
301
+ }).then(clientUser => clientUser.presence);
302
+ }
303
+
304
+ /**
305
+ * Sets/removes the AFK flag for the client user.
306
+ * @param {boolean} afk Whether or not the user is AFK
307
+ * @returns {Promise<ClientUser>}
308
+ */
309
+ setAFK(afk) {
310
+ return this.setPresence({ afk });
311
+ }
312
+
313
+ /**
314
+ * Fetches messages that mentioned the client's user.
315
+ * <warn>This is only available when using a user account.</warn>
316
+ * @param {Object} [options] Options for the fetch
317
+ * @param {number} [options.limit=25] Maximum number of mentions to retrieve
318
+ * @param {boolean} [options.roles=true] Whether to include role mentions
319
+ * @param {boolean} [options.everyone=true] Whether to include everyone/here mentions
320
+ * @param {GuildResolvable} [options.guild] Limit the search to a specific guild
321
+ * @returns {Promise<Message[]>}
322
+ * @deprecated
323
+ * @example
324
+ * // Fetch mentions
325
+ * client.user.fetchMentions()
326
+ * .then(console.log)
327
+ * .catch(console.error);
328
+ * @example
329
+ * // Fetch mentions from a guild
330
+ * client.user.fetchMentions({ guild: '222078108977594368' })
331
+ * .then(console.log)
332
+ * .catch(console.error);
333
+ */
334
+ fetchMentions(options = {}) {
335
+ return this.client.rest.methods.fetchMentions(options);
336
+ }
337
+
338
+ /**
339
+ * Send a friend request.
340
+ * <warn>This is only available when using a user account.</warn>
341
+ * @param {UserResolvable} user The user to send the friend request to
342
+ * @returns {Promise<User>} The user the friend request was sent to
343
+ * @deprecated
344
+ */
345
+ addFriend(user) {
346
+ user = this.client.resolver.resolveUser(user);
347
+ return this.client.rest.methods.addFriend(user);
348
+ }
349
+
350
+ /**
351
+ * Remove a friend.
352
+ * <warn>This is only available when using a user account.</warn>
353
+ * @param {UserResolvable} user The user to remove from your friends
354
+ * @returns {Promise<User>} The user that was removed
355
+ * @deprecated
356
+ */
357
+ removeFriend(user) {
358
+ user = this.client.resolver.resolveUser(user);
359
+ return this.client.rest.methods.removeFriend(user);
360
+ }
361
+
362
+ /**
363
+ * Creates a guild.
364
+ * <warn>This is only available to bots in less than 10 guilds and user accounts.</warn>
365
+ * @param {string} name The name of the guild
366
+ * @param {string} [region] The region for the server
367
+ * @param {BufferResolvable|Base64Resolvable} [icon=null] The icon for the guild
368
+ * @returns {Promise<Guild>} The guild that was created
369
+ */
370
+ createGuild(name, region, icon = null) {
371
+ if (typeof icon === 'string' && icon.startsWith('data:')) {
372
+ return this.client.rest.methods.createGuild({ name, icon, region });
373
+ } else {
374
+ return this.client.resolver.resolveImage(icon).then(data =>
375
+ this.client.rest.methods.createGuild({ name, icon: data, region })
376
+ );
377
+ }
378
+ }
379
+
380
+ /**
381
+ * An object containing either a user or access token, and an optional nickname.
382
+ * @typedef {Object} GroupDMRecipientOptions
383
+ * @property {UserResolvable|Snowflake} [user] User to add to the Group DM
384
+ * (only available if a user is creating the DM)
385
+ * @property {string} [accessToken] Access token to use to add a user to the Group DM
386
+ * (only available if a bot is creating the DM)
387
+ * @property {string} [nick] Permanent nickname (only available if a bot is creating the DM)
388
+ */
389
+
390
+ /**
391
+ * Creates a Group DM.
392
+ * @param {GroupDMRecipientOptions[]} recipients The recipients
393
+ * @returns {Promise<GroupDMChannel>}
394
+ * @example
395
+ * // Create a Group DM with a token provided from OAuth
396
+ * client.user.createGroupDM([{
397
+ * user: '66564597481480192',
398
+ * accessToken: token
399
+ * }])
400
+ * .then(console.log)
401
+ * .catch(console.error);
402
+ */
403
+ createGroupDM(recipients) {
404
+ return this.client.rest.methods.createGroupDM({
405
+ recipients: recipients.map(u => this.client.resolver.resolveUserID(u.user)),
406
+ accessTokens: recipients.map(u => u.accessToken),
407
+ nicks: recipients.reduce((o, r) => {
408
+ if (r.nick) o[r.user ? r.user.id : r.id] = r.nick;
409
+ return o;
410
+ }, {}),
411
+ });
412
+ }
413
+
414
+ /**
415
+ * Accepts an invite to join a guild.
416
+ * <warn>This is only available when using a user account.</warn>
417
+ * @param {Invite|string} invite Invite or code to accept
418
+ * @returns {Promise<Guild>} Joined guild
419
+ * @deprecated
420
+ */
421
+ acceptInvite(invite) {
422
+ return this.client.rest.methods.acceptInvite(invite);
423
+ }
424
+ }
425
+
426
+ ClientUser.prototype.acceptInvite =
427
+ util.deprecate(ClientUser.prototype.acceptInvite, 'ClientUser#acceptInvite: userbot methods will be removed');
428
+
429
+ ClientUser.prototype.setGame =
430
+ util.deprecate(ClientUser.prototype.setGame, 'ClientUser#setGame: use ClientUser#setActivity instead');
431
+
432
+ ClientUser.prototype.addFriend =
433
+ util.deprecate(ClientUser.prototype.addFriend, 'ClientUser#addFriend: userbot methods will be removed');
434
+
435
+ ClientUser.prototype.removeFriend =
436
+ util.deprecate(ClientUser.prototype.removeFriend, 'ClientUser#removeFriend: userbot methods will be removed');
437
+
438
+ ClientUser.prototype.setPassword =
439
+ util.deprecate(ClientUser.prototype.setPassword, 'ClientUser#setPassword: userbot methods will be removed');
440
+
441
+ ClientUser.prototype.setEmail =
442
+ util.deprecate(ClientUser.prototype.setEmail, 'ClientUser#setEmail: userbot methods will be removed');
443
+
444
+ ClientUser.prototype.fetchMentions =
445
+ util.deprecate(ClientUser.prototype.fetchMentions, 'ClientUser#fetchMentions: userbot methods will be removed');
446
+
447
+ module.exports = ClientUser;
@@ -0,0 +1,30 @@
1
+ const Constants = require('../util/Constants');
2
+
3
+ /**
4
+ * A wrapper around the ClientUser's channel overrides.
5
+ */
6
+ class ClientUserChannelOverride {
7
+ constructor(data) {
8
+ this.patch(data);
9
+ }
10
+
11
+ /**
12
+ * Patch the data contained in this class with new partial data.
13
+ * @param {Object} data Data to patch this with
14
+ * @returns {void}
15
+ * @private
16
+ */
17
+ patch(data) {
18
+ for (const key of Object.keys(Constants.UserChannelOverrideMap)) {
19
+ const value = Constants.UserChannelOverrideMap[key];
20
+ if (!data.hasOwnProperty(key)) continue;
21
+ if (typeof value === 'function') {
22
+ this[value.name] = value(data[key]);
23
+ } else {
24
+ this[value] = data[key];
25
+ }
26
+ }
27
+ }
28
+ }
29
+
30
+ module.exports = ClientUserChannelOverride;
@@ -0,0 +1,60 @@
1
+ const Constants = require('../util/Constants');
2
+ const Collection = require('../util/Collection');
3
+ const ClientUserChannelOverride = require('./ClientUserChannelOverride');
4
+
5
+ /**
6
+ * A wrapper around the ClientUser's guild settings.
7
+ */
8
+ class ClientUserGuildSettings {
9
+ constructor(data, client) {
10
+ /**
11
+ * The client that created the instance of the ClientUserGuildSettings
12
+ * @name ClientUserGuildSettings#client
13
+ * @type {Client}
14
+ * @readonly
15
+ */
16
+ Object.defineProperty(this, 'client', { value: client });
17
+ /**
18
+ * The ID of the guild this settings are for
19
+ * @type {Snowflake}
20
+ */
21
+ this.guildID = data.guild_id;
22
+ this.channelOverrides = new Collection();
23
+ this.patch(data);
24
+ }
25
+
26
+ /**
27
+ * Patch the data contained in this class with new partial data.
28
+ * @param {Object} data Data to patch this with
29
+ * @returns {void}
30
+ * @private
31
+ */
32
+ patch(data) {
33
+ for (const key of Object.keys(Constants.UserGuildSettingsMap)) {
34
+ const value = Constants.UserGuildSettingsMap[key];
35
+ if (!data.hasOwnProperty(key)) continue;
36
+ if (key === 'channel_overrides') {
37
+ for (const channel of data[key]) {
38
+ this.channelOverrides.set(channel.channel_id,
39
+ new ClientUserChannelOverride(channel));
40
+ }
41
+ } else if (typeof value === 'function') {
42
+ this[value.name] = value(data[key]);
43
+ } else {
44
+ this[value] = data[key];
45
+ }
46
+ }
47
+ }
48
+
49
+ /**
50
+ * Update a specific property of the guild settings.
51
+ * @param {string} name Name of property
52
+ * @param {value} value Value to patch
53
+ * @returns {Promise<Object>}
54
+ */
55
+ update(name, value) {
56
+ return this.client.rest.methods.patchClientUserGuildSettings(this.guildID, { [name]: value });
57
+ }
58
+ }
59
+
60
+ module.exports = ClientUserGuildSettings;
@@ -0,0 +1,80 @@
1
+ const Constants = require('../util/Constants');
2
+ const Util = require('../util/Util');
3
+
4
+ /**
5
+ * A wrapper around the ClientUser's settings.
6
+ */
7
+ class ClientUserSettings {
8
+ constructor(user, data) {
9
+ this.user = user;
10
+ this.patch(data);
11
+ }
12
+
13
+ /**
14
+ * Patch the data contained in this class with new partial data.
15
+ * @param {Object} data Data to patch this with
16
+ * @returns {void}
17
+ * @private
18
+ */
19
+ patch(data) {
20
+ for (const key of Object.keys(Constants.UserSettingsMap)) {
21
+ const value = Constants.UserSettingsMap[key];
22
+ if (!data.hasOwnProperty(key)) continue;
23
+ if (typeof value === 'function') {
24
+ this[value.name] = value(data[key]);
25
+ } else {
26
+ this[value] = data[key];
27
+ }
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Update a specific property of of user settings.
33
+ * @param {string} name Name of property
34
+ * @param {*} value Value to patch
35
+ * @returns {Promise<Object>}
36
+ */
37
+ update(name, value) {
38
+ return this.user.client.rest.methods.patchUserSettings({ [name]: value });
39
+ }
40
+
41
+ /**
42
+ * Sets the position at which this guild will appear in the Discord client.
43
+ * @param {Guild} guild The guild to move
44
+ * @param {number} position Absolute or relative position
45
+ * @param {boolean} [relative=false] Whether to position relatively or absolutely
46
+ * @returns {Promise<Guild>}
47
+ */
48
+ setGuildPosition(guild, position, relative) {
49
+ const temp = Object.assign([], this.guildPositions);
50
+ Util.moveElementInArray(temp, guild.id, position, relative);
51
+ return this.update('guild_positions', temp).then(() => guild);
52
+ }
53
+
54
+ /**
55
+ * Add a guild to the list of restricted guilds.
56
+ * @param {Guild} guild The guild to add
57
+ * @returns {Promise<Guild>}
58
+ */
59
+ addRestrictedGuild(guild) {
60
+ const temp = Object.assign([], this.restrictedGuilds);
61
+ if (temp.includes(guild.id)) return Promise.reject(new Error('Guild is already restricted'));
62
+ temp.push(guild.id);
63
+ return this.update('restricted_guilds', temp).then(() => guild);
64
+ }
65
+
66
+ /**
67
+ * Remove a guild from the list of restricted guilds.
68
+ * @param {Guild} guild The guild to remove
69
+ * @returns {Promise<Guild>}
70
+ */
71
+ removeRestrictedGuild(guild) {
72
+ const temp = Object.assign([], this.restrictedGuilds);
73
+ const index = temp.indexOf(guild.id);
74
+ if (index < 0) return Promise.reject(new Error('Guild is not restricted'));
75
+ temp.splice(index, 1);
76
+ return this.update('restricted_guilds', temp).then(() => guild);
77
+ }
78
+ }
79
+
80
+ module.exports = ClientUserSettings;
@@ -0,0 +1,76 @@
1
+ const Channel = require('./Channel');
2
+ const TextBasedChannel = require('./interfaces/TextBasedChannel');
3
+ const Collection = require('../util/Collection');
4
+
5
+ /**
6
+ * Represents a direct message channel between two users.
7
+ * @extends {Channel}
8
+ * @implements {TextBasedChannel}
9
+ */
10
+ class DMChannel extends Channel {
11
+ constructor(client, data) {
12
+ super(client, data);
13
+ this.type = 'dm';
14
+ this.messages = new Collection();
15
+ this._typing = new Map();
16
+ }
17
+
18
+ setup(data) {
19
+ super.setup(data);
20
+
21
+ /**
22
+ * The recipient on the other end of the DM
23
+ * @type {User}
24
+ */
25
+ this.recipient = this.client.dataManager.newUser(data.recipients[0]);
26
+
27
+ /**
28
+ * The ID of the last message in the channel, if one was sent
29
+ * @type {?Snowflake}
30
+ */
31
+ this.lastMessageID = data.last_message_id;
32
+
33
+ /**
34
+ * The timestamp when the last pinned message was pinned, if there was one
35
+ * @type {?number}
36
+ */
37
+ this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
38
+ }
39
+
40
+ /**
41
+ * When concatenated with a string, this automatically concatenates the recipient's mention instead of the
42
+ * DM channel object.
43
+ * @returns {string}
44
+ */
45
+ toString() {
46
+ return this.recipient.toString();
47
+ }
48
+
49
+ // These are here only for documentation purposes - they are implemented by TextBasedChannel
50
+ /* eslint-disable no-empty-function */
51
+ get lastPinAt() {}
52
+ send() {}
53
+ sendMessage() {}
54
+ sendEmbed() {}
55
+ sendFile() {}
56
+ sendFiles() {}
57
+ sendCode() {}
58
+ fetchMessage() {}
59
+ fetchMessages() {}
60
+ fetchPinnedMessages() {}
61
+ search() {}
62
+ startTyping() {}
63
+ stopTyping() {}
64
+ get typing() {}
65
+ get typingCount() {}
66
+ createCollector() {}
67
+ createMessageCollector() {}
68
+ awaitMessages() {}
69
+ // Doesn't work on DM channels; bulkDelete() {}
70
+ acknowledge() {}
71
+ _cacheMessage() {}
72
+ }
73
+
74
+ TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete']);
75
+
76
+ module.exports = DMChannel;