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,100 @@
|
|
1
|
+
const Collector = require('./interfaces/Collector');
|
2
|
+
const util = require('util');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @typedef {CollectorOptions} MessageCollectorOptions
|
6
|
+
* @property {number} max The maximum amount of messages to process
|
7
|
+
* @property {number} maxMatches The maximum amount of messages to collect
|
8
|
+
*/
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Collects messages on a channel.
|
12
|
+
* @extends {Collector}
|
13
|
+
*/
|
14
|
+
class MessageCollector extends Collector {
|
15
|
+
/**
|
16
|
+
* @param {TextChannel|DMChannel|GroupDMChannel} channel The channel
|
17
|
+
* @param {CollectorFilter} filter The filter to be applied to this collector
|
18
|
+
* @param {MessageCollectorOptions} options The options to be applied to this collector
|
19
|
+
* @emits MessageCollector#message
|
20
|
+
*/
|
21
|
+
constructor(channel, filter, options = {}) {
|
22
|
+
super(channel.client, filter, options);
|
23
|
+
|
24
|
+
/**
|
25
|
+
* The channel
|
26
|
+
* @type {TextBasedChannel}
|
27
|
+
*/
|
28
|
+
this.channel = channel;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Total number of messages that were received in the channel during message collection
|
32
|
+
* @type {number}
|
33
|
+
*/
|
34
|
+
this.received = 0;
|
35
|
+
|
36
|
+
this.client.setMaxListeners(this.client.getMaxListeners() + 1);
|
37
|
+
this.client.on('message', this.listener);
|
38
|
+
|
39
|
+
// For backwards compatibility (remove in v12)
|
40
|
+
if (this.options.max) this.options.maxProcessed = this.options.max;
|
41
|
+
if (this.options.maxMatches) this.options.max = this.options.maxMatches;
|
42
|
+
this._reEmitter = message => {
|
43
|
+
/**
|
44
|
+
* Emitted when the collector receives a message.
|
45
|
+
* @event MessageCollector#message
|
46
|
+
* @param {Message} message The message
|
47
|
+
* @deprecated
|
48
|
+
*/
|
49
|
+
this.emit('message', message);
|
50
|
+
};
|
51
|
+
this.on('collect', this._reEmitter);
|
52
|
+
}
|
53
|
+
|
54
|
+
// Remove in v12
|
55
|
+
on(eventName, listener) {
|
56
|
+
if (eventName === 'message') {
|
57
|
+
listener = util.deprecate(listener, 'MessageCollector will soon no longer emit "message", use "collect" instead');
|
58
|
+
}
|
59
|
+
super.on(eventName, listener);
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Handle an incoming message for possible collection.
|
64
|
+
* @param {Message} message The message that could be collected
|
65
|
+
* @returns {?{key: Snowflake, value: Message}}
|
66
|
+
* @private
|
67
|
+
*/
|
68
|
+
handle(message) {
|
69
|
+
if (message.channel.id !== this.channel.id) return null;
|
70
|
+
this.received++;
|
71
|
+
return {
|
72
|
+
key: message.id,
|
73
|
+
value: message,
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Check after collection to see if the collector is done.
|
79
|
+
* @returns {?string} Reason to end the collector, if any
|
80
|
+
* @private
|
81
|
+
*/
|
82
|
+
postCheck() {
|
83
|
+
// Consider changing the end reasons for v12
|
84
|
+
if (this.options.maxMatches && this.collected.size >= this.options.max) return 'matchesLimit';
|
85
|
+
if (this.options.max && this.received >= this.options.maxProcessed) return 'limit';
|
86
|
+
return null;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Removes event listeners.
|
91
|
+
* @private
|
92
|
+
*/
|
93
|
+
cleanup() {
|
94
|
+
this.removeListener('collect', this._reEmitter);
|
95
|
+
this.client.removeListener('message', this.listener);
|
96
|
+
this.client.setMaxListeners(this.client.getMaxListeners() - 1);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
module.exports = MessageCollector;
|
@@ -0,0 +1,386 @@
|
|
1
|
+
/**
|
2
|
+
* Represents an embed in a message (image/video preview, rich embed, etc.)
|
3
|
+
* <info>This class is only used for *received* embeds. If you wish to send one, use the {@link RichEmbed} class.</info>
|
4
|
+
*/
|
5
|
+
class MessageEmbed {
|
6
|
+
constructor(message, data) {
|
7
|
+
/**
|
8
|
+
* The client that instantiated this embed
|
9
|
+
* @name MessageEmbed#client
|
10
|
+
* @type {Client}
|
11
|
+
* @readonly
|
12
|
+
*/
|
13
|
+
Object.defineProperty(this, 'client', { value: message.client });
|
14
|
+
|
15
|
+
/**
|
16
|
+
* The message this embed is part of
|
17
|
+
* @type {Message}
|
18
|
+
*/
|
19
|
+
this.message = message;
|
20
|
+
|
21
|
+
this.setup(data);
|
22
|
+
}
|
23
|
+
|
24
|
+
setup(data) {
|
25
|
+
/**
|
26
|
+
* The type of this embed
|
27
|
+
* @type {string}
|
28
|
+
*/
|
29
|
+
this.type = data.type;
|
30
|
+
|
31
|
+
/**
|
32
|
+
* The title of this embed
|
33
|
+
* @type {?string}
|
34
|
+
*/
|
35
|
+
this.title = data.title;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The description of this embed
|
39
|
+
* @type {?string}
|
40
|
+
*/
|
41
|
+
this.description = data.description;
|
42
|
+
|
43
|
+
/**
|
44
|
+
* The URL of this embed
|
45
|
+
* @type {string}
|
46
|
+
*/
|
47
|
+
this.url = data.url;
|
48
|
+
|
49
|
+
/**
|
50
|
+
* The color of the embed
|
51
|
+
* @type {number}
|
52
|
+
*/
|
53
|
+
this.color = data.color;
|
54
|
+
|
55
|
+
/**
|
56
|
+
* The fields of this embed
|
57
|
+
* @type {MessageEmbedField[]}
|
58
|
+
*/
|
59
|
+
this.fields = [];
|
60
|
+
if (data.fields) for (const field of data.fields) this.fields.push(new MessageEmbedField(this, field));
|
61
|
+
|
62
|
+
/**
|
63
|
+
* The timestamp of this embed
|
64
|
+
* @type {number}
|
65
|
+
*/
|
66
|
+
this.timestamp = data.timestamp;
|
67
|
+
|
68
|
+
/**
|
69
|
+
* The thumbnail of this embed
|
70
|
+
* @type {?MessageEmbedThumbnail}
|
71
|
+
*/
|
72
|
+
this.thumbnail = data.thumbnail ? new MessageEmbedThumbnail(this, data.thumbnail) : null;
|
73
|
+
|
74
|
+
/**
|
75
|
+
* The image of this embed
|
76
|
+
* @type {?MessageEmbedImage}
|
77
|
+
*/
|
78
|
+
this.image = data.image ? new MessageEmbedImage(this, data.image) : null;
|
79
|
+
|
80
|
+
/**
|
81
|
+
* The video of this embed
|
82
|
+
* @type {?MessageEmbedVideo}
|
83
|
+
*/
|
84
|
+
this.video = data.video ? new MessageEmbedVideo(this, data.video) : null;
|
85
|
+
|
86
|
+
/**
|
87
|
+
* The author of this embed
|
88
|
+
* @type {?MessageEmbedAuthor}
|
89
|
+
*/
|
90
|
+
this.author = data.author ? new MessageEmbedAuthor(this, data.author) : null;
|
91
|
+
|
92
|
+
/**
|
93
|
+
* The provider of this embed
|
94
|
+
* @type {?MessageEmbedProvider}
|
95
|
+
*/
|
96
|
+
this.provider = data.provider ? new MessageEmbedProvider(this, data.provider) : null;
|
97
|
+
|
98
|
+
/**
|
99
|
+
* The footer of this embed
|
100
|
+
* @type {?MessageEmbedFooter}
|
101
|
+
*/
|
102
|
+
this.footer = data.footer ? new MessageEmbedFooter(this, data.footer) : null;
|
103
|
+
}
|
104
|
+
|
105
|
+
/**
|
106
|
+
* The date this embed was created
|
107
|
+
* @type {Date}
|
108
|
+
* @readonly
|
109
|
+
*/
|
110
|
+
get createdAt() {
|
111
|
+
return new Date(this.createdTimestamp);
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* The hexadecimal version of the embed color, with a leading hash
|
116
|
+
* @type {?string}
|
117
|
+
* @readonly
|
118
|
+
*/
|
119
|
+
get hexColor() {
|
120
|
+
if (!this.color) return null;
|
121
|
+
let col = this.color.toString(16);
|
122
|
+
while (col.length < 6) col = `0${col}`;
|
123
|
+
return `#${col}`;
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Represents a thumbnail for a message embed.
|
129
|
+
*/
|
130
|
+
class MessageEmbedThumbnail {
|
131
|
+
constructor(embed, data) {
|
132
|
+
/**
|
133
|
+
* The embed this thumbnail is part of
|
134
|
+
* @type {MessageEmbed}
|
135
|
+
*/
|
136
|
+
this.embed = embed;
|
137
|
+
|
138
|
+
this.setup(data);
|
139
|
+
}
|
140
|
+
|
141
|
+
setup(data) {
|
142
|
+
/**
|
143
|
+
* The URL for this thumbnail
|
144
|
+
* @type {string}
|
145
|
+
*/
|
146
|
+
this.url = data.url;
|
147
|
+
|
148
|
+
/**
|
149
|
+
* The Proxy URL for this thumbnail
|
150
|
+
* @type {string}
|
151
|
+
*/
|
152
|
+
this.proxyURL = data.proxy_url;
|
153
|
+
|
154
|
+
/**
|
155
|
+
* The height of the thumbnail
|
156
|
+
* @type {number}
|
157
|
+
*/
|
158
|
+
this.height = data.height;
|
159
|
+
|
160
|
+
/**
|
161
|
+
* The width of the thumbnail
|
162
|
+
* @type {number}
|
163
|
+
*/
|
164
|
+
this.width = data.width;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Represents an image for a message embed.
|
170
|
+
*/
|
171
|
+
class MessageEmbedImage {
|
172
|
+
constructor(embed, data) {
|
173
|
+
/**
|
174
|
+
* The embed this image is part of
|
175
|
+
* @type {MessageEmbed}
|
176
|
+
*/
|
177
|
+
this.embed = embed;
|
178
|
+
|
179
|
+
this.setup(data);
|
180
|
+
}
|
181
|
+
|
182
|
+
setup(data) {
|
183
|
+
/**
|
184
|
+
* The URL for this image
|
185
|
+
* @type {string}
|
186
|
+
*/
|
187
|
+
this.url = data.url;
|
188
|
+
|
189
|
+
/**
|
190
|
+
* The Proxy URL for this image
|
191
|
+
* @type {string}
|
192
|
+
*/
|
193
|
+
this.proxyURL = data.proxy_url;
|
194
|
+
|
195
|
+
/**
|
196
|
+
* The height of the image
|
197
|
+
* @type {number}
|
198
|
+
*/
|
199
|
+
this.height = data.height;
|
200
|
+
|
201
|
+
/**
|
202
|
+
* The width of the image
|
203
|
+
* @type {number}
|
204
|
+
*/
|
205
|
+
this.width = data.width;
|
206
|
+
}
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Represents a video for a message embed.
|
211
|
+
*/
|
212
|
+
class MessageEmbedVideo {
|
213
|
+
constructor(embed, data) {
|
214
|
+
/**
|
215
|
+
* The embed this video is part of
|
216
|
+
* @type {MessageEmbed}
|
217
|
+
*/
|
218
|
+
this.embed = embed;
|
219
|
+
|
220
|
+
this.setup(data);
|
221
|
+
}
|
222
|
+
|
223
|
+
setup(data) {
|
224
|
+
/**
|
225
|
+
* The source URL for this video
|
226
|
+
* @type {string}
|
227
|
+
*/
|
228
|
+
this.url = data.url;
|
229
|
+
|
230
|
+
/**
|
231
|
+
* The height of the video
|
232
|
+
* @type {number}
|
233
|
+
*/
|
234
|
+
this.height = data.height;
|
235
|
+
|
236
|
+
/**
|
237
|
+
* The width of the video
|
238
|
+
* @type {number}
|
239
|
+
*/
|
240
|
+
this.width = data.width;
|
241
|
+
}
|
242
|
+
}
|
243
|
+
|
244
|
+
/**
|
245
|
+
* Represents a provider for a message embed.
|
246
|
+
*/
|
247
|
+
class MessageEmbedProvider {
|
248
|
+
constructor(embed, data) {
|
249
|
+
/**
|
250
|
+
* The embed this provider is part of
|
251
|
+
* @type {MessageEmbed}
|
252
|
+
*/
|
253
|
+
this.embed = embed;
|
254
|
+
|
255
|
+
this.setup(data);
|
256
|
+
}
|
257
|
+
|
258
|
+
setup(data) {
|
259
|
+
/**
|
260
|
+
* The name of this provider
|
261
|
+
* @type {string}
|
262
|
+
*/
|
263
|
+
this.name = data.name;
|
264
|
+
|
265
|
+
/**
|
266
|
+
* The URL of this provider
|
267
|
+
* @type {string}
|
268
|
+
*/
|
269
|
+
this.url = data.url;
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
/**
|
274
|
+
* Represents an author for a message embed.
|
275
|
+
*/
|
276
|
+
class MessageEmbedAuthor {
|
277
|
+
constructor(embed, data) {
|
278
|
+
/**
|
279
|
+
* The embed this author is part of
|
280
|
+
* @type {MessageEmbed}
|
281
|
+
*/
|
282
|
+
this.embed = embed;
|
283
|
+
|
284
|
+
this.setup(data);
|
285
|
+
}
|
286
|
+
|
287
|
+
setup(data) {
|
288
|
+
/**
|
289
|
+
* The name of this author
|
290
|
+
* @type {string}
|
291
|
+
*/
|
292
|
+
this.name = data.name;
|
293
|
+
|
294
|
+
/**
|
295
|
+
* The URL of this author
|
296
|
+
* @type {string}
|
297
|
+
*/
|
298
|
+
this.url = data.url;
|
299
|
+
|
300
|
+
/**
|
301
|
+
* The icon URL of this author
|
302
|
+
* @type {string}
|
303
|
+
*/
|
304
|
+
this.iconURL = data.icon_url;
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Represents a field for a message embed.
|
310
|
+
*/
|
311
|
+
class MessageEmbedField {
|
312
|
+
constructor(embed, data) {
|
313
|
+
/**
|
314
|
+
* The embed this footer is part of
|
315
|
+
* @type {MessageEmbed}
|
316
|
+
*/
|
317
|
+
this.embed = embed;
|
318
|
+
|
319
|
+
this.setup(data);
|
320
|
+
}
|
321
|
+
|
322
|
+
setup(data) {
|
323
|
+
/**
|
324
|
+
* The name of this field
|
325
|
+
* @type {string}
|
326
|
+
*/
|
327
|
+
this.name = data.name;
|
328
|
+
|
329
|
+
/**
|
330
|
+
* The value of this field
|
331
|
+
* @type {string}
|
332
|
+
*/
|
333
|
+
this.value = data.value;
|
334
|
+
|
335
|
+
/**
|
336
|
+
* If this field is displayed inline
|
337
|
+
* @type {boolean}
|
338
|
+
*/
|
339
|
+
this.inline = data.inline;
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
/**
|
344
|
+
* Represents the footer of a message embed.
|
345
|
+
*/
|
346
|
+
class MessageEmbedFooter {
|
347
|
+
constructor(embed, data) {
|
348
|
+
/**
|
349
|
+
* The embed this footer is part of
|
350
|
+
* @type {MessageEmbed}
|
351
|
+
*/
|
352
|
+
this.embed = embed;
|
353
|
+
|
354
|
+
this.setup(data);
|
355
|
+
}
|
356
|
+
|
357
|
+
setup(data) {
|
358
|
+
/**
|
359
|
+
* The text in this footer
|
360
|
+
* @type {string}
|
361
|
+
*/
|
362
|
+
this.text = data.text;
|
363
|
+
|
364
|
+
/**
|
365
|
+
* The icon URL of this footer
|
366
|
+
* @type {string}
|
367
|
+
*/
|
368
|
+
this.iconURL = data.icon_url;
|
369
|
+
|
370
|
+
/**
|
371
|
+
* The proxy icon URL of this footer
|
372
|
+
* @type {string}
|
373
|
+
*/
|
374
|
+
this.proxyIconUrl = data.proxy_icon_url;
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
MessageEmbed.Thumbnail = MessageEmbedThumbnail;
|
379
|
+
MessageEmbed.Image = MessageEmbedImage;
|
380
|
+
MessageEmbed.Video = MessageEmbedVideo;
|
381
|
+
MessageEmbed.Provider = MessageEmbedProvider;
|
382
|
+
MessageEmbed.Author = MessageEmbedAuthor;
|
383
|
+
MessageEmbed.Field = MessageEmbedField;
|
384
|
+
MessageEmbed.Footer = MessageEmbedFooter;
|
385
|
+
|
386
|
+
module.exports = MessageEmbed;
|
@@ -0,0 +1,144 @@
|
|
1
|
+
const Collection = require('../util/Collection');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Keeps track of mentions in a {@link Message}.
|
5
|
+
*/
|
6
|
+
class MessageMentions {
|
7
|
+
constructor(message, users, roles, everyone) {
|
8
|
+
/**
|
9
|
+
* Whether `@everyone` or `@here` were mentioned
|
10
|
+
* @type {boolean}
|
11
|
+
*/
|
12
|
+
this.everyone = Boolean(everyone);
|
13
|
+
|
14
|
+
if (users) {
|
15
|
+
if (users instanceof Collection) {
|
16
|
+
/**
|
17
|
+
* Any users that were mentioned
|
18
|
+
* @type {Collection<Snowflake, User>}
|
19
|
+
*/
|
20
|
+
this.users = new Collection(users);
|
21
|
+
} else {
|
22
|
+
this.users = new Collection();
|
23
|
+
for (const mention of users) {
|
24
|
+
let user = message.client.users.get(mention.id);
|
25
|
+
if (!user) user = message.client.dataManager.newUser(mention);
|
26
|
+
this.users.set(user.id, user);
|
27
|
+
}
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
this.users = new Collection();
|
31
|
+
}
|
32
|
+
|
33
|
+
if (roles) {
|
34
|
+
if (roles instanceof Collection) {
|
35
|
+
/**
|
36
|
+
* Any roles that were mentioned
|
37
|
+
* @type {Collection<Snowflake, Role>}
|
38
|
+
*/
|
39
|
+
this.roles = new Collection(roles);
|
40
|
+
} else {
|
41
|
+
this.roles = new Collection();
|
42
|
+
for (const mention of roles) {
|
43
|
+
const role = message.channel.guild.roles.get(mention);
|
44
|
+
if (role) this.roles.set(role.id, role);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
} else {
|
48
|
+
this.roles = new Collection();
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Content of the message
|
53
|
+
* @type {Message}
|
54
|
+
* @private
|
55
|
+
*/
|
56
|
+
this._content = message.content;
|
57
|
+
|
58
|
+
/**
|
59
|
+
* The client the message is from
|
60
|
+
* @type {Client}
|
61
|
+
* @private
|
62
|
+
*/
|
63
|
+
this._client = message.client;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* The guild the message is in
|
67
|
+
* @type {?Guild}
|
68
|
+
* @private
|
69
|
+
*/
|
70
|
+
this._guild = message.channel.guild;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Cached members for {@MessageMention#members}
|
74
|
+
* @type {?Collection<Snowflake, GuildMember>}
|
75
|
+
* @private
|
76
|
+
*/
|
77
|
+
this._members = null;
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Cached channels for {@MessageMention#channels}
|
81
|
+
* @type {?Collection<Snowflake, GuildChannel>}
|
82
|
+
* @private
|
83
|
+
*/
|
84
|
+
this._channels = null;
|
85
|
+
}
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Any members that were mentioned (only in {@link TextChannel}s)
|
89
|
+
* @type {?Collection<Snowflake, GuildMember>}
|
90
|
+
* @readonly
|
91
|
+
*/
|
92
|
+
get members() {
|
93
|
+
if (this._members) return this._members;
|
94
|
+
if (!this._guild) return null;
|
95
|
+
this._members = new Collection();
|
96
|
+
this.users.forEach(user => {
|
97
|
+
const member = this._guild.member(user);
|
98
|
+
if (member) this._members.set(member.user.id, member);
|
99
|
+
});
|
100
|
+
return this._members;
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* Any channels that were mentioned
|
105
|
+
* @type {Collection<Snowflake, GuildChannel>}
|
106
|
+
* @readonly
|
107
|
+
*/
|
108
|
+
get channels() {
|
109
|
+
if (this._channels) return this._channels;
|
110
|
+
this._channels = new Collection();
|
111
|
+
let matches;
|
112
|
+
while ((matches = this.constructor.CHANNELS_PATTERN.exec(this._content)) !== null) {
|
113
|
+
const chan = this._client.channels.get(matches[1]);
|
114
|
+
if (chan) this._channels.set(chan.id, chan);
|
115
|
+
}
|
116
|
+
return this._channels;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Regular expression that globally matches `@everyone` and `@here`
|
122
|
+
* @type {RegExp}
|
123
|
+
*/
|
124
|
+
MessageMentions.EVERYONE_PATTERN = /@(everyone|here)/g;
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Regular expression that globally matches user mentions like `<@81440962496172032>`
|
128
|
+
* @type {RegExp}
|
129
|
+
*/
|
130
|
+
MessageMentions.USERS_PATTERN = /<@!?[0-9]+>/g;
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Regular expression that globally matches role mentions like `<@&297577916114403338>`
|
134
|
+
* @type {RegExp}
|
135
|
+
*/
|
136
|
+
MessageMentions.ROLES_PATTERN = /<@&[0-9]+>/g;
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Regular expression that globally matches channel mentions like `<#222079895583457280>`
|
140
|
+
* @type {RegExp}
|
141
|
+
*/
|
142
|
+
MessageMentions.CHANNELS_PATTERN = /<#([0-9]+)>/g;
|
143
|
+
|
144
|
+
module.exports = MessageMentions;
|
@@ -0,0 +1,96 @@
|
|
1
|
+
const Collection = require('../util/Collection');
|
2
|
+
const Emoji = require('./Emoji');
|
3
|
+
const ReactionEmoji = require('./ReactionEmoji');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Represents a reaction to a message.
|
7
|
+
*/
|
8
|
+
class MessageReaction {
|
9
|
+
constructor(message, emoji, count, me) {
|
10
|
+
/**
|
11
|
+
* The message that this reaction refers to
|
12
|
+
* @type {Message}
|
13
|
+
*/
|
14
|
+
this.message = message;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Whether the client has given this reaction
|
18
|
+
* @type {boolean}
|
19
|
+
*/
|
20
|
+
this.me = me;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* The number of people that have given the same reaction
|
24
|
+
* @type {number}
|
25
|
+
*/
|
26
|
+
this.count = count || 0;
|
27
|
+
|
28
|
+
/**
|
29
|
+
* The users that have given this reaction, mapped by their ID
|
30
|
+
* @type {Collection<Snowflake, User>}
|
31
|
+
*/
|
32
|
+
this.users = new Collection();
|
33
|
+
|
34
|
+
this._emoji = new ReactionEmoji(this, emoji.name, emoji.id);
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* The emoji of this reaction, either an Emoji object for known custom emojis, or a ReactionEmoji
|
39
|
+
* object which has fewer properties. Whatever the prototype of the emoji, it will still have
|
40
|
+
* `name`, `id`, `identifier` and `toString()`
|
41
|
+
* @type {Emoji|ReactionEmoji}
|
42
|
+
* @readonly
|
43
|
+
*/
|
44
|
+
get emoji() {
|
45
|
+
if (this._emoji instanceof Emoji) return this._emoji;
|
46
|
+
// Check to see if the emoji has become known to the client
|
47
|
+
if (this._emoji.id) {
|
48
|
+
const emojis = this.message.client.emojis;
|
49
|
+
if (emojis.has(this._emoji.id)) {
|
50
|
+
const emoji = emojis.get(this._emoji.id);
|
51
|
+
this._emoji = emoji;
|
52
|
+
return emoji;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
return this._emoji;
|
56
|
+
}
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Removes a user from this reaction.
|
60
|
+
* @param {UserResolvable} [user=this.message.client.user] The user to remove the reaction of
|
61
|
+
* @returns {Promise<MessageReaction>}
|
62
|
+
*/
|
63
|
+
remove(user = this.message.client.user) {
|
64
|
+
const message = this.message;
|
65
|
+
const userID = this.message.client.resolver.resolveUserID(user);
|
66
|
+
if (!userID) return Promise.reject(new Error('Couldn\'t resolve the user ID to remove from the reaction.'));
|
67
|
+
return message.client.rest.methods.removeMessageReaction(
|
68
|
+
message, this.emoji.identifier, userID
|
69
|
+
);
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Fetch all the users that gave this reaction. Resolves with a collection of users, mapped by their IDs.
|
74
|
+
* @param {number} [limit=100] The maximum amount of users to fetch, defaults to 100
|
75
|
+
* @param {Object} [options] Options to fetch users
|
76
|
+
* @param {Snowflake} [options.before] Limit fetching users to those with an id lower than the supplied id
|
77
|
+
* @param {Snowflake} [options.after] Limit fetching users to those with an id greater than the supplied id
|
78
|
+
* @returns {Promise<Collection<Snowflake, User>>}
|
79
|
+
*/
|
80
|
+
fetchUsers(limit = 100, { after, before } = {}) {
|
81
|
+
const message = this.message;
|
82
|
+
return message.client.rest.methods.getMessageReactionUsers(
|
83
|
+
message, this.emoji.identifier, { after, before, limit }
|
84
|
+
).then(data => {
|
85
|
+
const users = new Collection();
|
86
|
+
for (const rawUser of data) {
|
87
|
+
const user = this.message.client.dataManager.newUser(rawUser);
|
88
|
+
this.users.set(user.id, user);
|
89
|
+
users.set(user.id, user);
|
90
|
+
}
|
91
|
+
return users;
|
92
|
+
});
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
module.exports = MessageReaction;
|