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.
- package/.dccache +1 -0
- package/LICENSE +190 -0
- package/README.md +87 -0
- package/browser.js +9 -0
- package/deploy/deploy-key.enc +0 -0
- package/deploy/deploy.sh +90 -0
- package/deploy/test.sh +34 -0
- package/docs/README.md +1 -0
- package/docs/examples/attachments.md +163 -0
- package/docs/examples/avatars.js +29 -0
- package/docs/examples/embed.js +38 -0
- package/docs/examples/greeting.js +30 -0
- package/docs/examples/moderation.md +145 -0
- package/docs/examples/ping.js +29 -0
- package/docs/examples/webhook.js +12 -0
- package/docs/general/faq.md +23 -0
- package/docs/general/updating.md +181 -0
- package/docs/general/welcome.md +95 -0
- package/docs/index.yml +30 -0
- package/docs/logo.svg +19 -0
- package/docs/topics/voice.md +113 -0
- package/docs/topics/web.md +38 -0
- package/package.json +147 -0
- package/src/client/Client.js +564 -0
- package/src/client/ClientDataManager.js +150 -0
- package/src/client/ClientDataResolver.js +376 -0
- package/src/client/ClientManager.js +74 -0
- package/src/client/WebhookClient.js +118 -0
- package/src/client/actions/Action.js +23 -0
- package/src/client/actions/ActionsManager.js +40 -0
- package/src/client/actions/ChannelCreate.js +11 -0
- package/src/client/actions/ChannelDelete.js +30 -0
- package/src/client/actions/ChannelUpdate.js +74 -0
- package/src/client/actions/GuildBanRemove.js +13 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
- package/src/client/actions/GuildDelete.js +57 -0
- package/src/client/actions/GuildEmojiCreate.js +17 -0
- package/src/client/actions/GuildEmojiDelete.js +18 -0
- package/src/client/actions/GuildEmojiUpdate.js +17 -0
- package/src/client/actions/GuildEmojisUpdate.js +38 -0
- package/src/client/actions/GuildMemberGet.js +10 -0
- package/src/client/actions/GuildMemberRemove.js +41 -0
- package/src/client/actions/GuildRoleCreate.js +26 -0
- package/src/client/actions/GuildRoleDelete.js +42 -0
- package/src/client/actions/GuildRoleUpdate.js +41 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
- package/src/client/actions/GuildSync.js +29 -0
- package/src/client/actions/GuildUpdate.js +34 -0
- package/src/client/actions/MessageCreate.js +53 -0
- package/src/client/actions/MessageDelete.js +35 -0
- package/src/client/actions/MessageDeleteBulk.js +26 -0
- package/src/client/actions/MessageReactionAdd.js +37 -0
- package/src/client/actions/MessageReactionRemove.js +37 -0
- package/src/client/actions/MessageReactionRemoveAll.js +25 -0
- package/src/client/actions/MessageUpdate.js +40 -0
- package/src/client/actions/Ready.js +1 -0
- package/src/client/actions/Ready.js.bak +65 -0
- package/src/client/actions/UserGet.js +11 -0
- package/src/client/actions/UserNoteUpdate.js +30 -0
- package/src/client/actions/UserUpdate.js +33 -0
- package/src/client/rest/APIRequest.js +56 -0
- package/src/client/rest/DiscordAPIError.js +60 -0
- package/src/client/rest/RESTManager.js +58 -0
- package/src/client/rest/RESTMethods.js +1006 -0
- package/src/client/rest/RequestHandlers/Burst.js +90 -0
- package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
- package/src/client/rest/RequestHandlers/Sequential.js +132 -0
- package/src/client/rest/UserAgentManager.js +25 -0
- package/src/client/voice/ClientVoiceManager.js +81 -0
- package/src/client/voice/VoiceBroadcast.js +366 -0
- package/src/client/voice/VoiceConnection.js +530 -0
- package/src/client/voice/VoiceUDPClient.js +127 -0
- package/src/client/voice/VoiceWebSocket.js +246 -0
- package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
- package/src/client/voice/opus/BaseOpusEngine.js +60 -0
- package/src/client/voice/opus/NodeOpusEngine.js +40 -0
- package/src/client/voice/opus/OpusEngineList.js +28 -0
- package/src/client/voice/opus/OpusScriptEngine.js +45 -0
- package/src/client/voice/player/AudioPlayer.js +170 -0
- package/src/client/voice/receiver/VoiceReadable.js +17 -0
- package/src/client/voice/receiver/VoiceReceiver.js +219 -0
- package/src/client/voice/util/SecretKey.js +16 -0
- package/src/client/voice/util/Secretbox.js +33 -0
- package/src/client/voice/util/VolumeInterface.js +86 -0
- package/src/client/websocket/WebSocketConnection.js +506 -0
- package/src/client/websocket/WebSocketManager.js +90 -0
- package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
- package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
- package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
- package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
- package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
- package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
- package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
- package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
- package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
- package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
- package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
- package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
- package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
- package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
- package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
- package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
- package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
- package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
- package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
- package/src/client/websocket/packets/handlers/Ready.js +83 -0
- package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
- package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
- package/src/client/websocket/packets/handlers/Resumed.js +28 -0
- package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
- package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
- package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
- package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
- package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
- package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
- package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
- package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
- package/src/index.js +66 -0
- package/src/sharding/Shard.js +282 -0
- package/src/sharding/ShardClientUtil.js +146 -0
- package/src/sharding/ShardingManager.js +220 -0
- package/src/structures/Attachment.js +75 -0
- package/src/structures/CategoryChannel.js +22 -0
- package/src/structures/Channel.js +78 -0
- package/src/structures/ClientUser.js +447 -0
- package/src/structures/ClientUserChannelOverride.js +30 -0
- package/src/structures/ClientUserGuildSettings.js +60 -0
- package/src/structures/ClientUserSettings.js +80 -0
- package/src/structures/DMChannel.js +76 -0
- package/src/structures/Emoji.js +256 -0
- package/src/structures/GroupDMChannel.js +246 -0
- package/src/structures/Guild.js +1461 -0
- package/src/structures/GuildAuditLogs.js +371 -0
- package/src/structures/GuildChannel.js +537 -0
- package/src/structures/GuildMember.js +613 -0
- package/src/structures/Invite.js +164 -0
- package/src/structures/Message.js +605 -0
- package/src/structures/MessageAttachment.js +68 -0
- package/src/structures/MessageCollector.js +100 -0
- package/src/structures/MessageEmbed.js +386 -0
- package/src/structures/MessageMentions.js +144 -0
- package/src/structures/MessageReaction.js +96 -0
- package/src/structures/NewsChannel.js +24 -0
- package/src/structures/OAuth2Application.js +148 -0
- package/src/structures/PartialGuild.js +51 -0
- package/src/structures/PartialGuildChannel.js +44 -0
- package/src/structures/PermissionOverwrites.js +69 -0
- package/src/structures/Presence.js +241 -0
- package/src/structures/ReactionCollector.js +85 -0
- package/src/structures/ReactionEmoji.js +49 -0
- package/src/structures/RichEmbed.js +295 -0
- package/src/structures/Role.js +376 -0
- package/src/structures/StoreChannel.js +25 -0
- package/src/structures/TextChannel.js +154 -0
- package/src/structures/User.js +329 -0
- package/src/structures/UserConnection.js +48 -0
- package/src/structures/UserProfile.js +62 -0
- package/src/structures/VoiceChannel.js +146 -0
- package/src/structures/VoiceRegion.js +50 -0
- package/src/structures/Webhook.js +304 -0
- package/src/structures/interfaces/Collector.js +179 -0
- package/src/structures/interfaces/TextBasedChannel.js +635 -0
- package/src/structures/shared/resolvePermissions.js +26 -0
- package/src/util/Collection.js +532 -0
- package/src/util/Constants.js +845 -0
- package/src/util/Permissions.js +306 -0
- package/src/util/Snowflake.js +82 -0
- package/src/util/Util.js +221 -0
- package/test/random.js +207 -0
- package/test/shard.js +31 -0
- package/test/sharder.js +7 -0
- package/test/voice.js +78 -0
- package/test/webpack.html +31 -0
- package/tsconfig.json +13 -0
- package/tslint.json +62 -0
- package/typings/discord.js-test.ts +69 -0
- package/typings/index.d.ts +2190 -0
- package/webpack.config.js +62 -0
@@ -0,0 +1,256 @@
|
|
1
|
+
const Constants = require('../util/Constants');
|
2
|
+
const Collection = require('../util/Collection');
|
3
|
+
const Permissions = require('../util/Permissions');
|
4
|
+
const Snowflake = require('../util/Snowflake');
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Represents a custom emoji.
|
8
|
+
*/
|
9
|
+
class Emoji {
|
10
|
+
constructor(guild, data) {
|
11
|
+
/**
|
12
|
+
* The client that instantiated this object
|
13
|
+
* @name Emoji#client
|
14
|
+
* @type {Client}
|
15
|
+
* @readonly
|
16
|
+
*/
|
17
|
+
Object.defineProperty(this, 'client', { value: guild.client });
|
18
|
+
|
19
|
+
/**
|
20
|
+
* The guild this emoji is part of
|
21
|
+
* @type {Guild}
|
22
|
+
*/
|
23
|
+
this.guild = guild;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Whether this emoji has been deleted
|
27
|
+
* @type {boolean}
|
28
|
+
*/
|
29
|
+
this.deleted = false;
|
30
|
+
|
31
|
+
this.setup(data);
|
32
|
+
}
|
33
|
+
|
34
|
+
setup(data) {
|
35
|
+
/**
|
36
|
+
* The ID of the emoji
|
37
|
+
* @type {Snowflake}
|
38
|
+
*/
|
39
|
+
this.id = data.id;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* The name of the emoji
|
43
|
+
* @type {string}
|
44
|
+
*/
|
45
|
+
this.name = data.name;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Whether or not this emoji requires colons surrounding it
|
49
|
+
* @type {boolean}
|
50
|
+
*/
|
51
|
+
this.requiresColons = data.require_colons;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Whether this emoji is managed by an external service
|
55
|
+
* @type {boolean}
|
56
|
+
*/
|
57
|
+
this.managed = data.managed;
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Whether this emoji is animated
|
61
|
+
* @type {boolean}
|
62
|
+
*/
|
63
|
+
this.animated = data.animated;
|
64
|
+
|
65
|
+
this._roles = data.roles;
|
66
|
+
}
|
67
|
+
|
68
|
+
/**
|
69
|
+
* The timestamp the emoji was created at
|
70
|
+
* @type {number}
|
71
|
+
* @readonly
|
72
|
+
*/
|
73
|
+
get createdTimestamp() {
|
74
|
+
return Snowflake.deconstruct(this.id).timestamp;
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* The time the emoji was created
|
79
|
+
* @type {Date}
|
80
|
+
* @readonly
|
81
|
+
*/
|
82
|
+
get createdAt() {
|
83
|
+
return new Date(this.createdTimestamp);
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Whether the emoji is deletable by the client user
|
88
|
+
* @type {boolean}
|
89
|
+
* @readonly
|
90
|
+
*/
|
91
|
+
get deletable() {
|
92
|
+
return !this.managed && this.guild.me.hasPermission(Permissions.FLAGS.MANAGE_EMOJIS);
|
93
|
+
}
|
94
|
+
|
95
|
+
/**
|
96
|
+
* A collection of roles this emoji is active for (empty if all), mapped by role ID
|
97
|
+
* @type {Collection<Snowflake, Role>}
|
98
|
+
* @readonly
|
99
|
+
*/
|
100
|
+
get roles() {
|
101
|
+
const roles = new Collection();
|
102
|
+
for (const role of this._roles) {
|
103
|
+
if (this.guild.roles.has(role)) roles.set(role, this.guild.roles.get(role));
|
104
|
+
}
|
105
|
+
return roles;
|
106
|
+
}
|
107
|
+
|
108
|
+
/**
|
109
|
+
* The URL to the emoji file
|
110
|
+
* @type {string}
|
111
|
+
* @readonly
|
112
|
+
*/
|
113
|
+
get url() {
|
114
|
+
return Constants.Endpoints.CDN(this.client.options.http.cdn).Emoji(this.id, this.animated ? 'gif' : 'png');
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* The identifier of this emoji, used for message reactions
|
119
|
+
* @type {string}
|
120
|
+
* @readonly
|
121
|
+
*/
|
122
|
+
get identifier() {
|
123
|
+
if (this.id) return `${this.name}:${this.id}`;
|
124
|
+
return encodeURIComponent(this.name);
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Data for editing an emoji.
|
129
|
+
* @typedef {Object} EmojiEditData
|
130
|
+
* @property {string} [name] The name of the emoji
|
131
|
+
* @property {Collection<Snowflake, Role>|Array<Snowflake|Role>} [roles] Roles to restrict emoji to
|
132
|
+
*/
|
133
|
+
|
134
|
+
/**
|
135
|
+
* Edits the emoji.
|
136
|
+
* @param {EmojiEditData} data The new data for the emoji
|
137
|
+
* @param {string} [reason] Reason for editing this emoji
|
138
|
+
* @returns {Promise<Emoji>}
|
139
|
+
* @example
|
140
|
+
* // Edit an emoji
|
141
|
+
* emoji.edit({name: 'newemoji'})
|
142
|
+
* .then(e => console.log(`Edited emoji ${e}`))
|
143
|
+
* .catch(console.error);
|
144
|
+
*/
|
145
|
+
edit(data, reason) {
|
146
|
+
return this.client.rest.methods.updateEmoji(this, data, reason);
|
147
|
+
}
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Set the name of the emoji.
|
151
|
+
* @param {string} name The new name for the emoji
|
152
|
+
* @param {string} [reason] The reason for changing the emoji's name
|
153
|
+
* @returns {Promise<Emoji>}
|
154
|
+
*/
|
155
|
+
setName(name, reason) {
|
156
|
+
return this.edit({ name }, reason);
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Fetches the author for this emoji
|
161
|
+
* @returns {Promise<User>}
|
162
|
+
*/
|
163
|
+
fetchAuthor() {
|
164
|
+
if (this.managed) return Promise.reject(new Error('Emoji is managed and has no Author.'));
|
165
|
+
if (!this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_EMOJIS)) {
|
166
|
+
return Promise.reject(
|
167
|
+
new Error(`Client must have Manage Emoji permission in guild ${this.guild} to see emoji authors.`)
|
168
|
+
);
|
169
|
+
}
|
170
|
+
return this.client.rest.makeRequest('get', Constants.Endpoints.Guild(this.guild).Emoji(this.id), true)
|
171
|
+
.then(emoji => this.client.dataManager.newUser(emoji.user));
|
172
|
+
}
|
173
|
+
|
174
|
+
/**
|
175
|
+
* Add a role to the list of roles that can use this emoji.
|
176
|
+
* @param {Role} role The role to add
|
177
|
+
* @returns {Promise<Emoji>}
|
178
|
+
*/
|
179
|
+
addRestrictedRole(role) {
|
180
|
+
return this.addRestrictedRoles([role]);
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Add multiple roles to the list of roles that can use this emoji.
|
185
|
+
* @param {Role[]} roles Roles to add
|
186
|
+
* @returns {Promise<Emoji>}
|
187
|
+
*/
|
188
|
+
addRestrictedRoles(roles) {
|
189
|
+
const newRoles = new Collection(this.roles);
|
190
|
+
for (const role of roles) {
|
191
|
+
if (this.guild.roles.has(role.id)) newRoles.set(role.id, role);
|
192
|
+
}
|
193
|
+
return this.edit({ roles: newRoles });
|
194
|
+
}
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Remove a role from the list of roles that can use this emoji.
|
198
|
+
* @param {Role} role The role to remove
|
199
|
+
* @returns {Promise<Emoji>}
|
200
|
+
*/
|
201
|
+
removeRestrictedRole(role) {
|
202
|
+
return this.removeRestrictedRoles([role]);
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* Remove multiple roles from the list of roles that can use this emoji.
|
207
|
+
* @param {Role[]} roles Roles to remove
|
208
|
+
* @returns {Promise<Emoji>}
|
209
|
+
*/
|
210
|
+
removeRestrictedRoles(roles) {
|
211
|
+
const newRoles = new Collection(this.roles);
|
212
|
+
for (const role of roles) {
|
213
|
+
if (newRoles.has(role.id)) newRoles.delete(role.id);
|
214
|
+
}
|
215
|
+
return this.edit({ roles: newRoles });
|
216
|
+
}
|
217
|
+
|
218
|
+
/**
|
219
|
+
* When concatenated with a string, this automatically returns the emoji mention rather than the object.
|
220
|
+
* @returns {string}
|
221
|
+
* @example
|
222
|
+
* // Send an emoji:
|
223
|
+
* const emoji = guild.emojis.first();
|
224
|
+
* msg.reply(`Hello! ${emoji}`);
|
225
|
+
*/
|
226
|
+
toString() {
|
227
|
+
if (!this.id || !this.requiresColons) {
|
228
|
+
return this.name;
|
229
|
+
}
|
230
|
+
|
231
|
+
return `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>`;
|
232
|
+
}
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Whether this emoji is the same as another one.
|
236
|
+
* @param {Emoji|Object} other The emoji to compare it to
|
237
|
+
* @returns {boolean} Whether the emoji is equal to the given emoji or not
|
238
|
+
*/
|
239
|
+
equals(other) {
|
240
|
+
if (other instanceof Emoji) {
|
241
|
+
return (
|
242
|
+
other.id === this.id &&
|
243
|
+
other.name === this.name &&
|
244
|
+
other.managed === this.managed &&
|
245
|
+
other.requiresColons === this.requiresColons
|
246
|
+
);
|
247
|
+
} else {
|
248
|
+
return (
|
249
|
+
other.id === this.id &&
|
250
|
+
other.name === this.name
|
251
|
+
);
|
252
|
+
}
|
253
|
+
}
|
254
|
+
}
|
255
|
+
|
256
|
+
module.exports = Emoji;
|
@@ -0,0 +1,246 @@
|
|
1
|
+
const Channel = require('./Channel');
|
2
|
+
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
3
|
+
const Collection = require('../util/Collection');
|
4
|
+
const Constants = require('../util/Constants');
|
5
|
+
|
6
|
+
/*
|
7
|
+
{ type: 3,
|
8
|
+
recipients:
|
9
|
+
[ { username: 'Charlie',
|
10
|
+
id: '123',
|
11
|
+
discriminator: '6631',
|
12
|
+
avatar: '123' },
|
13
|
+
{ username: 'Ben',
|
14
|
+
id: '123',
|
15
|
+
discriminator: '2055',
|
16
|
+
avatar: '123' },
|
17
|
+
{ username: 'Adam',
|
18
|
+
id: '123',
|
19
|
+
discriminator: '2406',
|
20
|
+
avatar: '123' } ],
|
21
|
+
owner_id: '123',
|
22
|
+
name: null,
|
23
|
+
last_message_id: '123',
|
24
|
+
id: '123',
|
25
|
+
icon: null }
|
26
|
+
*/
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Represents a Group DM on Discord.
|
30
|
+
* @extends {Channel}
|
31
|
+
* @implements {TextBasedChannel}
|
32
|
+
*/
|
33
|
+
class GroupDMChannel extends Channel {
|
34
|
+
constructor(client, data) {
|
35
|
+
super(client, data);
|
36
|
+
this.type = 'group';
|
37
|
+
this.messages = new Collection();
|
38
|
+
this._typing = new Map();
|
39
|
+
}
|
40
|
+
|
41
|
+
setup(data) {
|
42
|
+
super.setup(data);
|
43
|
+
|
44
|
+
/**
|
45
|
+
* The name of this Group DM, can be null if one isn't set
|
46
|
+
* @type {string}
|
47
|
+
*/
|
48
|
+
this.name = data.name;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* A hash of this Group DM icon
|
52
|
+
* @type {?string}
|
53
|
+
*/
|
54
|
+
this.icon = data.icon;
|
55
|
+
|
56
|
+
/**
|
57
|
+
* The user ID of this Group DM's owner
|
58
|
+
* @type {string}
|
59
|
+
*/
|
60
|
+
this.ownerID = data.owner_id;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* If the DM is managed by an application
|
64
|
+
* @type {boolean}
|
65
|
+
*/
|
66
|
+
this.managed = data.managed;
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Application ID of the application that made this Group DM, if applicable
|
70
|
+
* @type {?string}
|
71
|
+
*/
|
72
|
+
this.applicationID = data.application_id;
|
73
|
+
|
74
|
+
if (data.nicks) {
|
75
|
+
/**
|
76
|
+
* Nicknames for group members
|
77
|
+
* @type {?Collection<Snowflake, string>}
|
78
|
+
*/
|
79
|
+
this.nicks = new Collection(data.nicks.map(n => [n.id, n.nick]));
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!this.recipients) {
|
83
|
+
/**
|
84
|
+
* A collection of the recipients of this DM, mapped by their ID
|
85
|
+
* @type {Collection<Snowflake, User>}
|
86
|
+
*/
|
87
|
+
this.recipients = new Collection();
|
88
|
+
}
|
89
|
+
|
90
|
+
if (data.recipients) {
|
91
|
+
for (const recipient of data.recipients) {
|
92
|
+
const user = this.client.dataManager.newUser(recipient);
|
93
|
+
this.recipients.set(user.id, user);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
/**
|
98
|
+
* The ID of the last message in the channel, if one was sent
|
99
|
+
* @type {?Snowflake}
|
100
|
+
*/
|
101
|
+
this.lastMessageID = data.last_message_id;
|
102
|
+
|
103
|
+
/**
|
104
|
+
* The timestamp when the last pinned message was pinned, if there was one
|
105
|
+
* @type {?number}
|
106
|
+
*/
|
107
|
+
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
108
|
+
}
|
109
|
+
|
110
|
+
/**
|
111
|
+
* The owner of this Group DM
|
112
|
+
* @type {User}
|
113
|
+
* @readonly
|
114
|
+
*/
|
115
|
+
get owner() {
|
116
|
+
return this.client.users.get(this.ownerID);
|
117
|
+
}
|
118
|
+
|
119
|
+
/**
|
120
|
+
* The URL to this guild's icon
|
121
|
+
* @type {?string}
|
122
|
+
* @readonly
|
123
|
+
*/
|
124
|
+
get iconURL() {
|
125
|
+
if (!this.icon) return null;
|
126
|
+
return Constants.Endpoints.Channel(this).Icon(this.client.options.http.cdn, this.icon);
|
127
|
+
}
|
128
|
+
|
129
|
+
edit(data) {
|
130
|
+
const _data = {};
|
131
|
+
if (data.name) _data.name = data.name;
|
132
|
+
if (typeof data.icon !== 'undefined') _data.icon = data.icon;
|
133
|
+
return this.client.rest.methods.updateGroupDMChannel(this, _data);
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Whether this channel equals another channel. It compares all properties, so for most operations
|
138
|
+
* it is advisable to just compare `channel.id === channel2.id` as it is much faster and is often
|
139
|
+
* what most users need.
|
140
|
+
* @param {GroupDMChannel} channel Channel to compare with
|
141
|
+
* @returns {boolean}
|
142
|
+
*/
|
143
|
+
equals(channel) {
|
144
|
+
const equal = channel &&
|
145
|
+
this.id === channel.id &&
|
146
|
+
this.name === channel.name &&
|
147
|
+
this.icon === channel.icon &&
|
148
|
+
this.ownerID === channel.ownerID;
|
149
|
+
|
150
|
+
if (equal) {
|
151
|
+
return this.recipients.equals(channel.recipients);
|
152
|
+
}
|
153
|
+
|
154
|
+
return equal;
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Add a user to the DM
|
159
|
+
* @param {UserResolvable|string} accessTokenOrID Access token or user resolvable
|
160
|
+
* @param {string} [nick] Permanent nickname to give the user (only available if a bot is creating the DM)
|
161
|
+
* @returns {Promise<GroupDMChannel>}
|
162
|
+
*/
|
163
|
+
|
164
|
+
addUser(accessTokenOrID, nick) {
|
165
|
+
return this.client.rest.methods.addUserToGroupDM(this, {
|
166
|
+
nick,
|
167
|
+
id: this.client.resolver.resolveUserID(accessTokenOrID),
|
168
|
+
accessToken: accessTokenOrID,
|
169
|
+
});
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Set a new GroupDMChannel icon.
|
174
|
+
* @param {Base64Resolvable|BufferResolvable} icon The new icon of the group dm
|
175
|
+
* @returns {Promise<GroupDMChannel>}
|
176
|
+
* @example
|
177
|
+
* // Edit the group dm icon
|
178
|
+
* channel.setIcon('./icon.png')
|
179
|
+
* .then(updated => console.log('Updated the channel icon'))
|
180
|
+
* .catch(console.error);
|
181
|
+
*/
|
182
|
+
setIcon(icon) {
|
183
|
+
return this.client.resolver.resolveImage(icon).then(data => this.edit({ icon: data }));
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Sets a new name for this Group DM.
|
188
|
+
* @param {string} name New name for this Group DM
|
189
|
+
* @returns {Promise<GroupDMChannel>}
|
190
|
+
*/
|
191
|
+
setName(name) {
|
192
|
+
return this.edit({ name });
|
193
|
+
}
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Removes a user from this Group DM.
|
197
|
+
* @param {UserResolvable} user User to remove
|
198
|
+
* @returns {Promise<GroupDMChannel>}
|
199
|
+
*/
|
200
|
+
removeUser(user) {
|
201
|
+
const id = this.client.resolver.resolveUserID(user);
|
202
|
+
return this.client.rest.methods.removeUserFromGroupDM(this, id);
|
203
|
+
}
|
204
|
+
|
205
|
+
/**
|
206
|
+
* When concatenated with a string, this automatically concatenates the channel's name instead of the Channel object.
|
207
|
+
* @returns {string}
|
208
|
+
* @example
|
209
|
+
* // Logs: Hello from My Group DM!
|
210
|
+
* console.log(`Hello from ${channel}!`);
|
211
|
+
* @example
|
212
|
+
* // Logs: Hello from My Group DM!
|
213
|
+
* console.log(`Hello from ' + channel + '!');
|
214
|
+
*/
|
215
|
+
toString() {
|
216
|
+
return this.name;
|
217
|
+
}
|
218
|
+
|
219
|
+
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
220
|
+
/* eslint-disable no-empty-function */
|
221
|
+
get lastPinAt() {}
|
222
|
+
send() {}
|
223
|
+
sendMessage() {}
|
224
|
+
sendEmbed() {}
|
225
|
+
sendFile() {}
|
226
|
+
sendFiles() {}
|
227
|
+
sendCode() {}
|
228
|
+
fetchMessage() {}
|
229
|
+
fetchMessages() {}
|
230
|
+
fetchPinnedMessages() {}
|
231
|
+
search() {}
|
232
|
+
startTyping() {}
|
233
|
+
stopTyping() {}
|
234
|
+
get typing() {}
|
235
|
+
get typingCount() {}
|
236
|
+
createCollector() {}
|
237
|
+
createMessageCollector() {}
|
238
|
+
awaitMessages() {}
|
239
|
+
// Doesn't work on Group DMs; bulkDelete() {}
|
240
|
+
acknowledge() {}
|
241
|
+
_cacheMessage() {}
|
242
|
+
}
|
243
|
+
|
244
|
+
TextBasedChannel.applyToClass(GroupDMChannel, true, ['bulkDelete']);
|
245
|
+
|
246
|
+
module.exports = GroupDMChannel;
|