@zygout/eris 0.19.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +109 -80
- package/esm.mjs +72 -72
- package/index.d.ts +4407 -4397
- package/index.js +75 -75
- package/lib/Client.js +4708 -4683
- package/lib/Constants.d.ts +990 -988
- package/lib/Constants.js +1163 -1161
- package/lib/command/Command.js +552 -552
- package/lib/command/CommandClient.js +460 -460
- package/lib/errors/DiscordHTTPError.js +63 -63
- package/lib/errors/DiscordRESTError.js +77 -77
- package/lib/gateway/Shard.js +3029 -3029
- package/lib/gateway/ShardManager.js +164 -164
- package/lib/rest/Endpoints.js +172 -172
- package/lib/rest/RequestHandler.js +459 -459
- package/lib/structures/ApplicationCommand.js +125 -125
- package/lib/structures/AutoModerationRule.js +143 -143
- package/lib/structures/AutocompleteInteraction.js +80 -80
- package/lib/structures/Base.js +81 -81
- package/lib/structures/CategoryChannel.js +77 -77
- package/lib/structures/Channel.js +98 -98
- package/lib/structures/CommandInteraction.js +473 -473
- package/lib/structures/ComponentInteraction.js +538 -538
- package/lib/structures/DMChannel.js +278 -278
- package/lib/structures/Entitlement.js +77 -77
- package/lib/structures/ExtendedUser.js +46 -46
- package/lib/structures/ForumChannel.js +24 -24
- package/lib/structures/GroupChannel.js +106 -106
- package/lib/structures/Guild.js +1677 -1677
- package/lib/structures/GuildAuditLogEntry.js +190 -190
- package/lib/structures/GuildChannel.js +128 -128
- package/lib/structures/GuildIntegration.js +99 -99
- package/lib/structures/GuildPreview.js +97 -97
- package/lib/structures/GuildScheduledEvent.js +176 -176
- package/lib/structures/GuildTemplate.js +76 -76
- package/lib/structures/GuildTextableChannel.js +260 -260
- package/lib/structures/Interaction.js +133 -133
- package/lib/structures/Invite.js +143 -143
- package/lib/structures/Lobby.js +108 -108
- package/lib/structures/LobbyMember.js +59 -59
- package/lib/structures/MediaChannel.js +216 -216
- package/lib/structures/Member.js +371 -371
- package/lib/structures/Message.js +708 -708
- package/lib/structures/ModalSubmitInteraction.js +478 -478
- package/lib/structures/NewsChannel.js +34 -34
- package/lib/structures/NewsThreadChannel.js +12 -12
- package/lib/structures/Permission.js +80 -80
- package/lib/structures/PermissionOverwrite.js +32 -32
- package/lib/structures/PingInteraction.js +39 -39
- package/lib/structures/PrivateThreadChannel.js +25 -25
- package/lib/structures/PublicThreadChannel.js +26 -26
- package/lib/structures/Role.js +163 -163
- package/lib/structures/SKU.js +80 -80
- package/lib/structures/SoundboardSound.js +79 -79
- package/lib/structures/StageChannel.js +59 -59
- package/lib/structures/StageInstance.js +55 -55
- package/lib/structures/Subscription.js +69 -69
- package/lib/structures/TextChannel.js +202 -202
- package/lib/structures/ThreadChannel.js +143 -143
- package/lib/structures/ThreadMember.js +59 -59
- package/lib/structures/UnavailableGuild.js +26 -26
- package/lib/structures/UnknownInteraction.js +502 -502
- package/lib/structures/User.js +296 -296
- package/lib/structures/VoiceChannel.js +166 -166
- package/lib/structures/VoiceState.js +84 -84
- package/lib/util/BrowserWebSocket.js +76 -76
- package/lib/util/Bucket.js +89 -89
- package/lib/util/Collection.js +202 -202
- package/lib/util/MultipartData.js +70 -70
- package/lib/util/Opus.js +33 -33
- package/lib/util/SequentialBucket.js +83 -83
- package/lib/util/emitDeprecation.js +26 -26
- package/lib/voice/Piper.js +300 -300
- package/lib/voice/SharedStream.js +238 -238
- package/lib/voice/VoiceConnection.js +1440 -1440
- package/lib/voice/VoiceConnectionManager.js +151 -151
- package/lib/voice/VoiceDataStream.js +22 -22
- package/lib/voice/streams/BaseTransformer.js +40 -40
- package/lib/voice/streams/DCAOpusTransformer.js +78 -78
- package/lib/voice/streams/FFmpegDuplex.js +192 -192
- package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
- package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
- package/lib/voice/streams/OggOpusTransformer.js +108 -108
- package/lib/voice/streams/PCMOpusTransformer.js +61 -61
- package/lib/voice/streams/VolumeTransformer.js +50 -50
- package/lib/voice/streams/WebmOpusTransformer.js +258 -258
- package/package.json +83 -82
package/lib/structures/User.js
CHANGED
|
@@ -1,296 +1,296 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const Base = require("./Base");
|
|
4
|
-
const Endpoints = require("../rest/Endpoints");
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Represents a user
|
|
8
|
-
* @prop {Number?} accentColor The user's banner color, or null if no banner color (REST only)
|
|
9
|
-
* @prop {String?} animatedNameplateURL The URL of the user's nameplate asset (always a WEBM)
|
|
10
|
-
* @prop {String?} avatar The hash of the user's avatar, or null if no avatar
|
|
11
|
-
* @prop {Object?} avatarDecorationData The data of the user's avatar decoration, including the asset and sku ID, or null if no avatar decoration
|
|
12
|
-
* @prop {String?} avatarDecorationURL The URL of the user's avatar decoration
|
|
13
|
-
* @prop {String} avatarURL The URL of the user's avatar which can be either a JPG or GIF
|
|
14
|
-
* @prop {String?} banner The hash of the user's banner, or null if no banner (REST only)
|
|
15
|
-
* @prop {String?} bannerURL The URL of the user's banner
|
|
16
|
-
* @prop {Boolean} bot Whether the user is an OAuth bot or not
|
|
17
|
-
* @prop {Object?} collectibles The data for the user's collectibles, including their nameplate, or null if no collectibles. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/user#collectibles) for object structure
|
|
18
|
-
* @prop {Number} createdAt Timestamp of the user's creation
|
|
19
|
-
* @prop {String} defaultAvatar The hash for the default avatar of a user if there is no avatar set
|
|
20
|
-
* @prop {String} defaultAvatarURL The URL of the user's default avatar
|
|
21
|
-
* @prop {String} discriminator The discriminator of the user. If they've migrated to the new username system, this will be "0"
|
|
22
|
-
* @prop {String?} globalName The user's display name, if it is set. For bots, this is the application name
|
|
23
|
-
* @prop {String?} guildTagBadgeURL The URL of the badge of the user's primary guild tag
|
|
24
|
-
* @prop {String} id The ID of the user
|
|
25
|
-
* @prop {String} mention A string that mentions the user
|
|
26
|
-
* @prop {Object?} primaryGuild The user's primary guild (guild tag), or null if not set
|
|
27
|
-
* @prop {String?} primaryGuild.badge The hash of the guild tag badge
|
|
28
|
-
* @prop {Boolean?} primaryGuild.identityEnabled Whether the user is displaying the primary guild's tag. `null` if the identity was cleared by the system
|
|
29
|
-
* @prop {String?} primaryGuild.identityGuildID The ID of the user's primary guild
|
|
30
|
-
* @prop {String?} primaryGuild.tag The text of the guild tag (up to 4 characters)
|
|
31
|
-
* @prop {Number?} publicFlags Publicly visible flags for this user
|
|
32
|
-
* @prop {String} staticAvatarURL The URL of the user's avatar (always a JPG)
|
|
33
|
-
* @prop {String?} staticNameplateURL The static URL of the user's nameplate asset (always a PNG)
|
|
34
|
-
* @prop {Boolean} system Whether the user is an official Discord system user (e.g. urgent messages)
|
|
35
|
-
* @prop {String} username The username of the user
|
|
36
|
-
*/
|
|
37
|
-
class User extends Base {
|
|
38
|
-
constructor(data, client) {
|
|
39
|
-
super(data.id);
|
|
40
|
-
if (!client) {
|
|
41
|
-
this._missingClientError = new Error("Missing client in constructor"); // Preserve constructor callstack
|
|
42
|
-
}
|
|
43
|
-
this._client = client;
|
|
44
|
-
this.bot = !!data.bot;
|
|
45
|
-
this.system = !!data.system;
|
|
46
|
-
this.update(data);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
update(data) {
|
|
50
|
-
if (data.avatar !== undefined) {
|
|
51
|
-
this.avatar = data.avatar;
|
|
52
|
-
}
|
|
53
|
-
if (data.username !== undefined) {
|
|
54
|
-
this.username = data.username;
|
|
55
|
-
}
|
|
56
|
-
if (data.global_name !== undefined) {
|
|
57
|
-
this.globalName = data.global_name;
|
|
58
|
-
}
|
|
59
|
-
if (data.discriminator !== undefined) {
|
|
60
|
-
this.discriminator = data.discriminator;
|
|
61
|
-
}
|
|
62
|
-
if (data.public_flags !== undefined) {
|
|
63
|
-
this.publicFlags = data.public_flags;
|
|
64
|
-
}
|
|
65
|
-
if (data.banner !== undefined) {
|
|
66
|
-
this.banner = data.banner;
|
|
67
|
-
}
|
|
68
|
-
if (data.accent_color !== undefined) {
|
|
69
|
-
this.accentColor = data.accent_color;
|
|
70
|
-
}
|
|
71
|
-
if (data.avatar_decoration_data !== undefined) {
|
|
72
|
-
this.avatarDecorationData = data.avatar_decoration_data;
|
|
73
|
-
}
|
|
74
|
-
if (data.collectibles !== undefined) {
|
|
75
|
-
this.collectibles = data.collectibles;
|
|
76
|
-
}
|
|
77
|
-
if (data.primary_guild !== undefined) {
|
|
78
|
-
this.primaryGuild = data.primary_guild
|
|
79
|
-
? {
|
|
80
|
-
badge: data.primary_guild.badge,
|
|
81
|
-
identityEnabled: data.primary_guild.identity_enabled,
|
|
82
|
-
identityGuildID: data.primary_guild.identity_guild_id,
|
|
83
|
-
tag: data.primary_guild.tag,
|
|
84
|
-
}
|
|
85
|
-
: null;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get animatedNameplateURL() {
|
|
90
|
-
if (!this.collectibles || !this.collectibles.nameplate) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "asset.webm");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
get avatarDecorationURL() {
|
|
97
|
-
if (!this.avatarDecorationData) {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
if (this._missingClientError) {
|
|
101
|
-
throw this._missingClientError;
|
|
102
|
-
}
|
|
103
|
-
return this._client._formatImage(Endpoints.USER_AVATAR_DECORATION(this.avatarDecorationData.asset), "png");
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get avatarURL() {
|
|
107
|
-
if (this._missingClientError) {
|
|
108
|
-
throw this._missingClientError;
|
|
109
|
-
}
|
|
110
|
-
return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar)) : this.defaultAvatarURL;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get bannerURL() {
|
|
114
|
-
if (!this.banner) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
if (this._missingClientError) {
|
|
118
|
-
throw this._missingClientError;
|
|
119
|
-
}
|
|
120
|
-
return this._client._formatImage(Endpoints.BANNER(this.id, this.banner));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
get defaultAvatar() {
|
|
124
|
-
return this.discriminator === "0" ? Base.getDiscordEpoch(this.id) % 6 : this.discriminator % 5;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
get defaultAvatarURL() {
|
|
128
|
-
return `${Endpoints.CDN_URL}${Endpoints.DEFAULT_USER_AVATAR(this.defaultAvatar)}.png`;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
get guildTagBadgeURL() {
|
|
132
|
-
if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
if (this._missingClientError) {
|
|
136
|
-
throw this._missingClientError;
|
|
137
|
-
}
|
|
138
|
-
return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), "png");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
get mention() {
|
|
142
|
-
return `<@${this.id}>`;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
get staticAvatarURL() {
|
|
146
|
-
if (this._missingClientError) {
|
|
147
|
-
throw this._missingClientError;
|
|
148
|
-
}
|
|
149
|
-
return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), "jpg") : this.defaultAvatarURL;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get staticNameplateURL() {
|
|
153
|
-
if (!this.collectibles || !this.collectibles.nameplate) {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "static.png");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Create a test entitlement for this user
|
|
161
|
-
* @arg {String} skuID The ID of the SKU to grant to the user
|
|
162
|
-
* @returns {Promise<Entitlement>}
|
|
163
|
-
*/
|
|
164
|
-
createTestEntitlement(skuID) {
|
|
165
|
-
return this._client.createTestEntitlement.call(this._client, {
|
|
166
|
-
ownerID: this.id,
|
|
167
|
-
ownerType: 2,
|
|
168
|
-
skuID: skuID,
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Delete an application identity of this user, along with its profile data
|
|
174
|
-
* @arg {String} providerType The type of the external account provider
|
|
175
|
-
* @arg {String} providerIssuedUserID The ID of the user in the external system
|
|
176
|
-
* @arg {String} [providerID] The ID used by the provider to tell identities with the same type and user ID apart
|
|
177
|
-
* @returns {Promise}
|
|
178
|
-
*/
|
|
179
|
-
deleteApplicationIdentity(providerType, providerIssuedUserID, providerID) {
|
|
180
|
-
return this._client.deleteApplicationIdentity.call(this._client, this.id, providerType, providerIssuedUserID, providerID);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Get the user's avatar with the given format and size
|
|
185
|
-
* @arg {String} [format] The filetype of the avatar ("jpg", "jpeg", "png", "gif", or "webp")
|
|
186
|
-
* @arg {Number} [size] The size of the avatar (any power of two between 16 and 4096)
|
|
187
|
-
* @returns {String}
|
|
188
|
-
*/
|
|
189
|
-
dynamicAvatarURL(format, size) {
|
|
190
|
-
if (!this.avatar) {
|
|
191
|
-
return this.defaultAvatarURL;
|
|
192
|
-
}
|
|
193
|
-
if (this._missingClientError) {
|
|
194
|
-
throw this._missingClientError;
|
|
195
|
-
}
|
|
196
|
-
return this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), format, size);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Get the user's banner with the given format and size
|
|
201
|
-
* @arg {String} [format] The filetype of the banner ("jpg", "jpeg", "png", "gif", or "webp")
|
|
202
|
-
* @arg {Number} [size] The size of the banner (any power of two between 16 and 4096)
|
|
203
|
-
* @returns {String?}
|
|
204
|
-
*/
|
|
205
|
-
dynamicBannerURL(format, size) {
|
|
206
|
-
if (!this.banner) {
|
|
207
|
-
return null;
|
|
208
|
-
}
|
|
209
|
-
if (this._missingClientError) {
|
|
210
|
-
throw this._missingClientError;
|
|
211
|
-
}
|
|
212
|
-
return this._client._formatImage(Endpoints.BANNER(this.id, this.banner), format, size);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Get the guild tag badge of the user with the given format and size
|
|
217
|
-
* @arg {String} [format] The filetype of the badge ("jpg", "jpeg", "png", or "webp")
|
|
218
|
-
* @arg {Number} [size] The size of the badge (any power of two between 16 and 4096)
|
|
219
|
-
* @returns {String?}
|
|
220
|
-
*/
|
|
221
|
-
dynamicGuildTagBadgeURL(format, size) {
|
|
222
|
-
if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
|
|
223
|
-
return null;
|
|
224
|
-
}
|
|
225
|
-
if (this._missingClientError) {
|
|
226
|
-
throw this._missingClientError;
|
|
227
|
-
}
|
|
228
|
-
return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), format, size);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Edit the game profile of this user, shown in the game stats widgets of their Discord profile
|
|
233
|
-
* @arg {String} providerIssuedUserID The ID of the user in your system
|
|
234
|
-
* @arg {Object} options The properties to edit. See `Client#editApplicationIdentityProfile` for the full list of options
|
|
235
|
-
* @returns {Promise<Object?>}
|
|
236
|
-
*/
|
|
237
|
-
editApplicationIdentityProfile(providerIssuedUserID, options) {
|
|
238
|
-
return this._client.editApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID, options);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Get the application identities of this user, without their profile data
|
|
243
|
-
* @returns {Promise<Array<Object>>}
|
|
244
|
-
*/
|
|
245
|
-
getApplicationIdentities() {
|
|
246
|
-
return this._client.getUserApplicationIdentities.call(this._client, this.id);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Get the game profile of this user, shown in the game stats widgets of their Discord profile
|
|
251
|
-
* @arg {String} providerIssuedUserID The ID of the user in your system
|
|
252
|
-
* @returns {Promise<Object>}
|
|
253
|
-
*/
|
|
254
|
-
getApplicationIdentityProfile(providerIssuedUserID) {
|
|
255
|
-
return this._client.getApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Get a DM channel with the user, or create one if it does not exist
|
|
260
|
-
* @returns {Promise<DMChannel>}
|
|
261
|
-
*/
|
|
262
|
-
getDMChannel() {
|
|
263
|
-
return this._client.getDMChannel.call(this._client, this.id);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Get the entitlements of this user
|
|
268
|
-
* @arg {Object} [options] Options for the request. See `Client#getEntitlements` for the full list of options (`userID` is ignored)
|
|
269
|
-
* @returns {Promise<Array<Entitlement>>}
|
|
270
|
-
*/
|
|
271
|
-
getEntitlements(options = {}) {
|
|
272
|
-
return this._client.getEntitlements.call(this._client, Object.assign({}, options, {
|
|
273
|
-
userID: this.id,
|
|
274
|
-
}));
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
toJSON(props = []) {
|
|
278
|
-
return super.toJSON([
|
|
279
|
-
"accentColor",
|
|
280
|
-
"avatar",
|
|
281
|
-
"avatarDecorationData",
|
|
282
|
-
"banner",
|
|
283
|
-
"bot",
|
|
284
|
-
"collectibles",
|
|
285
|
-
"discriminator",
|
|
286
|
-
"globalName",
|
|
287
|
-
"primaryGuild",
|
|
288
|
-
"publicFlags",
|
|
289
|
-
"system",
|
|
290
|
-
"username",
|
|
291
|
-
...props,
|
|
292
|
-
]);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
module.exports = User;
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Base = require("./Base");
|
|
4
|
+
const Endpoints = require("../rest/Endpoints");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a user
|
|
8
|
+
* @prop {Number?} accentColor The user's banner color, or null if no banner color (REST only)
|
|
9
|
+
* @prop {String?} animatedNameplateURL The URL of the user's nameplate asset (always a WEBM)
|
|
10
|
+
* @prop {String?} avatar The hash of the user's avatar, or null if no avatar
|
|
11
|
+
* @prop {Object?} avatarDecorationData The data of the user's avatar decoration, including the asset and sku ID, or null if no avatar decoration
|
|
12
|
+
* @prop {String?} avatarDecorationURL The URL of the user's avatar decoration
|
|
13
|
+
* @prop {String} avatarURL The URL of the user's avatar which can be either a JPG or GIF
|
|
14
|
+
* @prop {String?} banner The hash of the user's banner, or null if no banner (REST only)
|
|
15
|
+
* @prop {String?} bannerURL The URL of the user's banner
|
|
16
|
+
* @prop {Boolean} bot Whether the user is an OAuth bot or not
|
|
17
|
+
* @prop {Object?} collectibles The data for the user's collectibles, including their nameplate, or null if no collectibles. See [the official Discord API documentation entry](https://discord.com/developers/docs/resources/user#collectibles) for object structure
|
|
18
|
+
* @prop {Number} createdAt Timestamp of the user's creation
|
|
19
|
+
* @prop {String} defaultAvatar The hash for the default avatar of a user if there is no avatar set
|
|
20
|
+
* @prop {String} defaultAvatarURL The URL of the user's default avatar
|
|
21
|
+
* @prop {String} discriminator The discriminator of the user. If they've migrated to the new username system, this will be "0"
|
|
22
|
+
* @prop {String?} globalName The user's display name, if it is set. For bots, this is the application name
|
|
23
|
+
* @prop {String?} guildTagBadgeURL The URL of the badge of the user's primary guild tag
|
|
24
|
+
* @prop {String} id The ID of the user
|
|
25
|
+
* @prop {String} mention A string that mentions the user
|
|
26
|
+
* @prop {Object?} primaryGuild The user's primary guild (guild tag), or null if not set
|
|
27
|
+
* @prop {String?} primaryGuild.badge The hash of the guild tag badge
|
|
28
|
+
* @prop {Boolean?} primaryGuild.identityEnabled Whether the user is displaying the primary guild's tag. `null` if the identity was cleared by the system
|
|
29
|
+
* @prop {String?} primaryGuild.identityGuildID The ID of the user's primary guild
|
|
30
|
+
* @prop {String?} primaryGuild.tag The text of the guild tag (up to 4 characters)
|
|
31
|
+
* @prop {Number?} publicFlags Publicly visible flags for this user
|
|
32
|
+
* @prop {String} staticAvatarURL The URL of the user's avatar (always a JPG)
|
|
33
|
+
* @prop {String?} staticNameplateURL The static URL of the user's nameplate asset (always a PNG)
|
|
34
|
+
* @prop {Boolean} system Whether the user is an official Discord system user (e.g. urgent messages)
|
|
35
|
+
* @prop {String} username The username of the user
|
|
36
|
+
*/
|
|
37
|
+
class User extends Base {
|
|
38
|
+
constructor(data, client) {
|
|
39
|
+
super(data.id);
|
|
40
|
+
if (!client) {
|
|
41
|
+
this._missingClientError = new Error("Missing client in constructor"); // Preserve constructor callstack
|
|
42
|
+
}
|
|
43
|
+
this._client = client;
|
|
44
|
+
this.bot = !!data.bot;
|
|
45
|
+
this.system = !!data.system;
|
|
46
|
+
this.update(data);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
update(data) {
|
|
50
|
+
if (data.avatar !== undefined) {
|
|
51
|
+
this.avatar = data.avatar;
|
|
52
|
+
}
|
|
53
|
+
if (data.username !== undefined) {
|
|
54
|
+
this.username = data.username;
|
|
55
|
+
}
|
|
56
|
+
if (data.global_name !== undefined) {
|
|
57
|
+
this.globalName = data.global_name;
|
|
58
|
+
}
|
|
59
|
+
if (data.discriminator !== undefined) {
|
|
60
|
+
this.discriminator = data.discriminator;
|
|
61
|
+
}
|
|
62
|
+
if (data.public_flags !== undefined) {
|
|
63
|
+
this.publicFlags = data.public_flags;
|
|
64
|
+
}
|
|
65
|
+
if (data.banner !== undefined) {
|
|
66
|
+
this.banner = data.banner;
|
|
67
|
+
}
|
|
68
|
+
if (data.accent_color !== undefined) {
|
|
69
|
+
this.accentColor = data.accent_color;
|
|
70
|
+
}
|
|
71
|
+
if (data.avatar_decoration_data !== undefined) {
|
|
72
|
+
this.avatarDecorationData = data.avatar_decoration_data;
|
|
73
|
+
}
|
|
74
|
+
if (data.collectibles !== undefined) {
|
|
75
|
+
this.collectibles = data.collectibles;
|
|
76
|
+
}
|
|
77
|
+
if (data.primary_guild !== undefined) {
|
|
78
|
+
this.primaryGuild = data.primary_guild
|
|
79
|
+
? {
|
|
80
|
+
badge: data.primary_guild.badge,
|
|
81
|
+
identityEnabled: data.primary_guild.identity_enabled,
|
|
82
|
+
identityGuildID: data.primary_guild.identity_guild_id,
|
|
83
|
+
tag: data.primary_guild.tag,
|
|
84
|
+
}
|
|
85
|
+
: null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get animatedNameplateURL() {
|
|
90
|
+
if (!this.collectibles || !this.collectibles.nameplate) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "asset.webm");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
get avatarDecorationURL() {
|
|
97
|
+
if (!this.avatarDecorationData) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
if (this._missingClientError) {
|
|
101
|
+
throw this._missingClientError;
|
|
102
|
+
}
|
|
103
|
+
return this._client._formatImage(Endpoints.USER_AVATAR_DECORATION(this.avatarDecorationData.asset), "png");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get avatarURL() {
|
|
107
|
+
if (this._missingClientError) {
|
|
108
|
+
throw this._missingClientError;
|
|
109
|
+
}
|
|
110
|
+
return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar)) : this.defaultAvatarURL;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get bannerURL() {
|
|
114
|
+
if (!this.banner) {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
if (this._missingClientError) {
|
|
118
|
+
throw this._missingClientError;
|
|
119
|
+
}
|
|
120
|
+
return this._client._formatImage(Endpoints.BANNER(this.id, this.banner));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
get defaultAvatar() {
|
|
124
|
+
return this.discriminator === "0" ? Base.getDiscordEpoch(this.id) % 6 : this.discriminator % 5;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
get defaultAvatarURL() {
|
|
128
|
+
return `${Endpoints.CDN_URL}${Endpoints.DEFAULT_USER_AVATAR(this.defaultAvatar)}.png`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get guildTagBadgeURL() {
|
|
132
|
+
if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
if (this._missingClientError) {
|
|
136
|
+
throw this._missingClientError;
|
|
137
|
+
}
|
|
138
|
+
return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), "png");
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get mention() {
|
|
142
|
+
return `<@${this.id}>`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get staticAvatarURL() {
|
|
146
|
+
if (this._missingClientError) {
|
|
147
|
+
throw this._missingClientError;
|
|
148
|
+
}
|
|
149
|
+
return this.avatar ? this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), "jpg") : this.defaultAvatarURL;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get staticNameplateURL() {
|
|
153
|
+
if (!this.collectibles || !this.collectibles.nameplate) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return Endpoints.CDN_URL + Endpoints.USER_NAMEPLATE(this.collectibles.nameplate.asset, "static.png");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Create a test entitlement for this user
|
|
161
|
+
* @arg {String} skuID The ID of the SKU to grant to the user
|
|
162
|
+
* @returns {Promise<Entitlement>}
|
|
163
|
+
*/
|
|
164
|
+
createTestEntitlement(skuID) {
|
|
165
|
+
return this._client.createTestEntitlement.call(this._client, {
|
|
166
|
+
ownerID: this.id,
|
|
167
|
+
ownerType: 2,
|
|
168
|
+
skuID: skuID,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Delete an application identity of this user, along with its profile data
|
|
174
|
+
* @arg {String} providerType The type of the external account provider
|
|
175
|
+
* @arg {String} providerIssuedUserID The ID of the user in the external system
|
|
176
|
+
* @arg {String} [providerID] The ID used by the provider to tell identities with the same type and user ID apart
|
|
177
|
+
* @returns {Promise}
|
|
178
|
+
*/
|
|
179
|
+
deleteApplicationIdentity(providerType, providerIssuedUserID, providerID) {
|
|
180
|
+
return this._client.deleteApplicationIdentity.call(this._client, this.id, providerType, providerIssuedUserID, providerID);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get the user's avatar with the given format and size
|
|
185
|
+
* @arg {String} [format] The filetype of the avatar ("jpg", "jpeg", "png", "gif", or "webp")
|
|
186
|
+
* @arg {Number} [size] The size of the avatar (any power of two between 16 and 4096)
|
|
187
|
+
* @returns {String}
|
|
188
|
+
*/
|
|
189
|
+
dynamicAvatarURL(format, size) {
|
|
190
|
+
if (!this.avatar) {
|
|
191
|
+
return this.defaultAvatarURL;
|
|
192
|
+
}
|
|
193
|
+
if (this._missingClientError) {
|
|
194
|
+
throw this._missingClientError;
|
|
195
|
+
}
|
|
196
|
+
return this._client._formatImage(Endpoints.USER_AVATAR(this.id, this.avatar), format, size);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Get the user's banner with the given format and size
|
|
201
|
+
* @arg {String} [format] The filetype of the banner ("jpg", "jpeg", "png", "gif", or "webp")
|
|
202
|
+
* @arg {Number} [size] The size of the banner (any power of two between 16 and 4096)
|
|
203
|
+
* @returns {String?}
|
|
204
|
+
*/
|
|
205
|
+
dynamicBannerURL(format, size) {
|
|
206
|
+
if (!this.banner) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
if (this._missingClientError) {
|
|
210
|
+
throw this._missingClientError;
|
|
211
|
+
}
|
|
212
|
+
return this._client._formatImage(Endpoints.BANNER(this.id, this.banner), format, size);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Get the guild tag badge of the user with the given format and size
|
|
217
|
+
* @arg {String} [format] The filetype of the badge ("jpg", "jpeg", "png", or "webp")
|
|
218
|
+
* @arg {Number} [size] The size of the badge (any power of two between 16 and 4096)
|
|
219
|
+
* @returns {String?}
|
|
220
|
+
*/
|
|
221
|
+
dynamicGuildTagBadgeURL(format, size) {
|
|
222
|
+
if (!this.primaryGuild || !this.primaryGuild.badge || !this.primaryGuild.identityGuildID) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
if (this._missingClientError) {
|
|
226
|
+
throw this._missingClientError;
|
|
227
|
+
}
|
|
228
|
+
return this._client._formatImage(Endpoints.GUILD_TAG_BADGE(this.primaryGuild.identityGuildID, this.primaryGuild.badge), format, size);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Edit the game profile of this user, shown in the game stats widgets of their Discord profile
|
|
233
|
+
* @arg {String} providerIssuedUserID The ID of the user in your system
|
|
234
|
+
* @arg {Object} options The properties to edit. See `Client#editApplicationIdentityProfile` for the full list of options
|
|
235
|
+
* @returns {Promise<Object?>}
|
|
236
|
+
*/
|
|
237
|
+
editApplicationIdentityProfile(providerIssuedUserID, options) {
|
|
238
|
+
return this._client.editApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID, options);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Get the application identities of this user, without their profile data
|
|
243
|
+
* @returns {Promise<Array<Object>>}
|
|
244
|
+
*/
|
|
245
|
+
getApplicationIdentities() {
|
|
246
|
+
return this._client.getUserApplicationIdentities.call(this._client, this.id);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get the game profile of this user, shown in the game stats widgets of their Discord profile
|
|
251
|
+
* @arg {String} providerIssuedUserID The ID of the user in your system
|
|
252
|
+
* @returns {Promise<Object>}
|
|
253
|
+
*/
|
|
254
|
+
getApplicationIdentityProfile(providerIssuedUserID) {
|
|
255
|
+
return this._client.getApplicationIdentityProfile.call(this._client, this.id, providerIssuedUserID);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get a DM channel with the user, or create one if it does not exist
|
|
260
|
+
* @returns {Promise<DMChannel>}
|
|
261
|
+
*/
|
|
262
|
+
getDMChannel() {
|
|
263
|
+
return this._client.getDMChannel.call(this._client, this.id);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Get the entitlements of this user
|
|
268
|
+
* @arg {Object} [options] Options for the request. See `Client#getEntitlements` for the full list of options (`userID` is ignored)
|
|
269
|
+
* @returns {Promise<Array<Entitlement>>}
|
|
270
|
+
*/
|
|
271
|
+
getEntitlements(options = {}) {
|
|
272
|
+
return this._client.getEntitlements.call(this._client, Object.assign({}, options, {
|
|
273
|
+
userID: this.id,
|
|
274
|
+
}));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
toJSON(props = []) {
|
|
278
|
+
return super.toJSON([
|
|
279
|
+
"accentColor",
|
|
280
|
+
"avatar",
|
|
281
|
+
"avatarDecorationData",
|
|
282
|
+
"banner",
|
|
283
|
+
"bot",
|
|
284
|
+
"collectibles",
|
|
285
|
+
"discriminator",
|
|
286
|
+
"globalName",
|
|
287
|
+
"primaryGuild",
|
|
288
|
+
"publicFlags",
|
|
289
|
+
"system",
|
|
290
|
+
"username",
|
|
291
|
+
...props,
|
|
292
|
+
]);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
module.exports = User;
|