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,90 @@
|
|
1
|
+
const RequestHandler = require('./RequestHandler');
|
2
|
+
const DiscordAPIError = require('../DiscordAPIError');
|
3
|
+
const { Events: { RATE_LIMIT } } = require('../../../util/Constants');
|
4
|
+
|
5
|
+
class BurstRequestHandler extends RequestHandler {
|
6
|
+
constructor(restManager, endpoint) {
|
7
|
+
super(restManager, endpoint);
|
8
|
+
|
9
|
+
this.client = restManager.client;
|
10
|
+
|
11
|
+
this.limit = Infinity;
|
12
|
+
this.resetTime = null;
|
13
|
+
this.remaining = 1;
|
14
|
+
this.timeDifference = 0;
|
15
|
+
|
16
|
+
this.resetTimeout = null;
|
17
|
+
}
|
18
|
+
|
19
|
+
push(request) {
|
20
|
+
super.push(request);
|
21
|
+
this.handle();
|
22
|
+
}
|
23
|
+
|
24
|
+
execute(item) {
|
25
|
+
if (!item) return;
|
26
|
+
item.request.gen().end((err, res) => {
|
27
|
+
if (res && res.headers) {
|
28
|
+
this.limit = Number(res.headers['x-ratelimit-limit']);
|
29
|
+
this.resetTime = Number(res.headers['x-ratelimit-reset']) * 1000;
|
30
|
+
this.remaining = Number(res.headers['x-ratelimit-remaining']);
|
31
|
+
this.timeDifference = Date.now() - new Date(res.headers.date).getTime();
|
32
|
+
}
|
33
|
+
if (err) {
|
34
|
+
if (err.status === 429) {
|
35
|
+
this.queue.unshift(item);
|
36
|
+
if (res.headers['x-ratelimit-global']) this.globalLimit = true;
|
37
|
+
if (this.resetTimeout) return;
|
38
|
+
this.resetTimeout = this.client.setTimeout(() => {
|
39
|
+
this.remaining = this.limit;
|
40
|
+
this.globalLimit = false;
|
41
|
+
this.handle();
|
42
|
+
this.resetTimeout = null;
|
43
|
+
}, Number(res.headers['retry-after']) + this.client.options.restTimeOffset);
|
44
|
+
} else if (err.status >= 500 && err.status < 600) {
|
45
|
+
if (item.retries === this.client.options.retryLimit) {
|
46
|
+
item.reject(err);
|
47
|
+
this.handle();
|
48
|
+
} else {
|
49
|
+
item.retries++;
|
50
|
+
this.queue.unshift(item);
|
51
|
+
this.resetTimeout = this.client.setTimeout(() => {
|
52
|
+
this.handle();
|
53
|
+
this.resetTimeout = null;
|
54
|
+
}, 1e3 + this.client.options.restTimeOffset);
|
55
|
+
}
|
56
|
+
} else {
|
57
|
+
item.reject(err.status >= 400 && err.status < 500 ?
|
58
|
+
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
|
59
|
+
this.handle();
|
60
|
+
}
|
61
|
+
} else {
|
62
|
+
if (this.remaining === 0) {
|
63
|
+
if (this.client.listenerCount(RATE_LIMIT)) {
|
64
|
+
this.client.emit(RATE_LIMIT, {
|
65
|
+
limit: this.limit,
|
66
|
+
timeDifference: this.timeDifference,
|
67
|
+
path: item.request.path,
|
68
|
+
method: item.request.method,
|
69
|
+
});
|
70
|
+
}
|
71
|
+
}
|
72
|
+
this.globalLimit = false;
|
73
|
+
const data = res && res.body ? res.body : {};
|
74
|
+
item.resolve(data);
|
75
|
+
this.handle();
|
76
|
+
}
|
77
|
+
});
|
78
|
+
}
|
79
|
+
|
80
|
+
handle() {
|
81
|
+
super.handle();
|
82
|
+
if (this.queue.length === 0) return;
|
83
|
+
if ((this.remaining <= 0 || this.globalLimit) && Date.now() - this.timeDifference < this.resetTime) return;
|
84
|
+
this.execute(this.queue.shift());
|
85
|
+
this.remaining--;
|
86
|
+
this.handle();
|
87
|
+
}
|
88
|
+
}
|
89
|
+
|
90
|
+
module.exports = BurstRequestHandler;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/**
|
2
|
+
* A base class for different types of rate limiting handlers for the REST API.
|
3
|
+
* @private
|
4
|
+
*/
|
5
|
+
class RequestHandler {
|
6
|
+
/**
|
7
|
+
* @param {RESTManager} restManager The REST manager to use
|
8
|
+
*/
|
9
|
+
constructor(restManager) {
|
10
|
+
/**
|
11
|
+
* The RESTManager that instantiated this RequestHandler
|
12
|
+
* @type {RESTManager}
|
13
|
+
*/
|
14
|
+
this.restManager = restManager;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* A list of requests that have yet to be processed
|
18
|
+
* @type {APIRequest[]}
|
19
|
+
*/
|
20
|
+
this.queue = [];
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Whether or not the client is being rate limited on every endpoint
|
25
|
+
* @type {boolean}
|
26
|
+
* @readonly
|
27
|
+
*/
|
28
|
+
get globalLimit() {
|
29
|
+
return this.restManager.globallyRateLimited;
|
30
|
+
}
|
31
|
+
|
32
|
+
set globalLimit(value) {
|
33
|
+
this.restManager.globallyRateLimited = value;
|
34
|
+
}
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Push a new API request into this bucket.
|
38
|
+
* @param {APIRequest} request The new request to push into the queue
|
39
|
+
*/
|
40
|
+
push(request) {
|
41
|
+
this.queue.push(request);
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Attempts to get this RequestHandler to process its current queue.
|
46
|
+
*/
|
47
|
+
handle() {} // eslint-disable-line no-empty-function
|
48
|
+
|
49
|
+
destroy() {
|
50
|
+
this.queue = [];
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
module.exports = RequestHandler;
|
@@ -0,0 +1,132 @@
|
|
1
|
+
const RequestHandler = require('./RequestHandler');
|
2
|
+
const DiscordAPIError = require('../DiscordAPIError');
|
3
|
+
const { Events: { RATE_LIMIT } } = require('../../../util/Constants');
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Handles API Requests sequentially, i.e. we wait until the current request is finished before moving onto
|
7
|
+
* the next. This plays a _lot_ nicer in terms of avoiding 429's when there is more than one session of the account,
|
8
|
+
* but it can be slower.
|
9
|
+
* @extends {RequestHandler}
|
10
|
+
* @private
|
11
|
+
*/
|
12
|
+
class SequentialRequestHandler extends RequestHandler {
|
13
|
+
/**
|
14
|
+
* @param {RESTManager} restManager The REST manager to use
|
15
|
+
* @param {string} endpoint The endpoint to handle
|
16
|
+
*/
|
17
|
+
constructor(restManager, endpoint) {
|
18
|
+
super(restManager, endpoint);
|
19
|
+
|
20
|
+
/**
|
21
|
+
* The client that instantiated this handler
|
22
|
+
* @type {Client}
|
23
|
+
*/
|
24
|
+
this.client = restManager.client;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* The endpoint that this handler is handling
|
28
|
+
* @type {string}
|
29
|
+
*/
|
30
|
+
this.endpoint = endpoint;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* The time difference between Discord's Dates and the local computer's Dates. A positive number means the local
|
34
|
+
* computer's time is ahead of Discord's
|
35
|
+
* @type {number}
|
36
|
+
*/
|
37
|
+
this.timeDifference = 0;
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Whether the queue is being processed or not
|
41
|
+
* @type {boolean}
|
42
|
+
*/
|
43
|
+
this.busy = false;
|
44
|
+
}
|
45
|
+
|
46
|
+
push(request) {
|
47
|
+
super.push(request);
|
48
|
+
this.handle();
|
49
|
+
}
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Performs a request then resolves a promise to indicate its readiness for a new request.
|
53
|
+
* @param {APIRequest} item The item to execute
|
54
|
+
* @returns {Promise<?Object|Error>}
|
55
|
+
*/
|
56
|
+
execute(item) {
|
57
|
+
this.busy = true;
|
58
|
+
return new Promise(resolve => {
|
59
|
+
item.request.gen().end((err, res) => {
|
60
|
+
if (res && res.headers) {
|
61
|
+
this.requestLimit = Number(res.headers['x-ratelimit-limit']);
|
62
|
+
this.requestResetTime = Number(res.headers['x-ratelimit-reset']) * 1000;
|
63
|
+
this.requestRemaining = Number(res.headers['x-ratelimit-remaining']);
|
64
|
+
this.timeDifference = Date.now() - new Date(res.headers.date).getTime();
|
65
|
+
}
|
66
|
+
if (err) {
|
67
|
+
if (err.status === 429) {
|
68
|
+
this.queue.unshift(item);
|
69
|
+
this.client.setTimeout(() => {
|
70
|
+
this.globalLimit = false;
|
71
|
+
resolve();
|
72
|
+
}, Number(res.headers['retry-after']) + this.client.options.restTimeOffset);
|
73
|
+
if (res.headers['x-ratelimit-global']) this.globalLimit = true;
|
74
|
+
} else if (err.status >= 500 && err.status < 600) {
|
75
|
+
if (item.retries === this.client.options.retryLimit) {
|
76
|
+
item.reject(err);
|
77
|
+
resolve();
|
78
|
+
} else {
|
79
|
+
item.retries++;
|
80
|
+
this.queue.unshift(item);
|
81
|
+
this.client.setTimeout(resolve, 1e3 + this.client.options.restTimeOffset);
|
82
|
+
}
|
83
|
+
} else {
|
84
|
+
item.reject(err.status >= 400 && err.status < 500 ?
|
85
|
+
new DiscordAPIError(res.request.path, res.body, res.request.method) : err);
|
86
|
+
resolve(err);
|
87
|
+
}
|
88
|
+
} else {
|
89
|
+
this.globalLimit = false;
|
90
|
+
const data = res && res.body ? res.body : {};
|
91
|
+
item.resolve(data);
|
92
|
+
if (this.requestRemaining === 0) {
|
93
|
+
if (this.client.listenerCount(RATE_LIMIT)) {
|
94
|
+
/**
|
95
|
+
* Emitted when the client hits a rate limit while making a request
|
96
|
+
* @event Client#rateLimit
|
97
|
+
* @param {Object} rateLimitInfo Object containing the rate limit info
|
98
|
+
* @param {number} rateLimitInfo.limit Number of requests that can be made to this endpoint
|
99
|
+
* @param {number} rateLimitInfo.timeDifference Delta-T in ms between your system and Discord servers
|
100
|
+
* @param {string} rateLimitInfo.path Path used for request that triggered this event
|
101
|
+
* @param {string} rateLimitInfo.method HTTP method used for request that triggered this event
|
102
|
+
*/
|
103
|
+
this.client.emit(RATE_LIMIT, {
|
104
|
+
limit: this.requestLimit,
|
105
|
+
timeDifference: this.timeDifference,
|
106
|
+
path: item.request.path,
|
107
|
+
method: item.request.method,
|
108
|
+
});
|
109
|
+
}
|
110
|
+
this.client.setTimeout(
|
111
|
+
() => resolve(data),
|
112
|
+
this.requestResetTime - Date.now() + this.timeDifference + this.client.options.restTimeOffset
|
113
|
+
);
|
114
|
+
} else {
|
115
|
+
resolve(data);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
});
|
119
|
+
});
|
120
|
+
}
|
121
|
+
|
122
|
+
handle() {
|
123
|
+
super.handle();
|
124
|
+
if (this.busy || this.remaining === 0 || this.queue.length === 0 || this.globalLimit) return;
|
125
|
+
this.execute(this.queue.shift()).then(() => {
|
126
|
+
this.busy = false;
|
127
|
+
this.handle();
|
128
|
+
});
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
module.exports = SequentialRequestHandler;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
const Constants = require('../../util/Constants');
|
2
|
+
|
3
|
+
class UserAgentManager {
|
4
|
+
constructor() {
|
5
|
+
this.build(this.constructor.DEFAULT);
|
6
|
+
}
|
7
|
+
|
8
|
+
set({ url, version } = {}) {
|
9
|
+
this.build({
|
10
|
+
url: url || this.constructor.DFEAULT.url,
|
11
|
+
version: version || this.constructor.DEFAULT.version,
|
12
|
+
});
|
13
|
+
}
|
14
|
+
|
15
|
+
build(ua) {
|
16
|
+
this.userAgent = `Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36`;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
UserAgentManager.DEFAULT = {
|
21
|
+
url: Constants.Package.homepage.split('#')[0],
|
22
|
+
version: Constants.Package.version,
|
23
|
+
};
|
24
|
+
|
25
|
+
module.exports = UserAgentManager;
|
@@ -0,0 +1,81 @@
|
|
1
|
+
const Collection = require('../../util/Collection');
|
2
|
+
const VoiceConnection = require('./VoiceConnection');
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Manages all the voice stuff for the client.
|
6
|
+
* @private
|
7
|
+
*/
|
8
|
+
class ClientVoiceManager {
|
9
|
+
constructor(client) {
|
10
|
+
/**
|
11
|
+
* The client that instantiated this voice manager
|
12
|
+
* @type {Client}
|
13
|
+
*/
|
14
|
+
this.client = client;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* A collection mapping connection IDs to the Connection objects
|
18
|
+
* @type {Collection<Snowflake, VoiceConnection>}
|
19
|
+
*/
|
20
|
+
this.connections = new Collection();
|
21
|
+
|
22
|
+
this.client.on('self.voiceServer', this.onVoiceServer.bind(this));
|
23
|
+
this.client.on('self.voiceStateUpdate', this.onVoiceStateUpdate.bind(this));
|
24
|
+
}
|
25
|
+
|
26
|
+
onVoiceServer({ guild_id, token, endpoint }) {
|
27
|
+
const connection = this.connections.get(guild_id);
|
28
|
+
if (connection) connection.setTokenAndEndpoint(token, endpoint);
|
29
|
+
}
|
30
|
+
|
31
|
+
onVoiceStateUpdate({ guild_id, session_id, channel_id }) {
|
32
|
+
const connection = this.connections.get(guild_id);
|
33
|
+
if (connection) {
|
34
|
+
connection.channel = this.client.channels.get(channel_id);
|
35
|
+
connection.setSessionID(session_id);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Sets up a request to join a voice channel.
|
41
|
+
* @param {VoiceChannel} channel The voice channel to join
|
42
|
+
* @returns {Promise<VoiceConnection>}
|
43
|
+
*/
|
44
|
+
joinChannel(channel) {
|
45
|
+
return new Promise((resolve, reject) => {
|
46
|
+
if (!channel.joinable) {
|
47
|
+
if (channel.full) {
|
48
|
+
throw new Error('You do not have permission to join this voice channel; it is full.');
|
49
|
+
} else {
|
50
|
+
throw new Error('You do not have permission to join this voice channel.');
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
let connection = this.connections.get(channel.guild.id);
|
55
|
+
|
56
|
+
if (connection) {
|
57
|
+
if (connection.channel.id !== channel.id) {
|
58
|
+
this.connections.get(channel.guild.id).updateChannel(channel);
|
59
|
+
}
|
60
|
+
resolve(connection);
|
61
|
+
return;
|
62
|
+
} else {
|
63
|
+
connection = new VoiceConnection(this, channel);
|
64
|
+
this.connections.set(channel.guild.id, connection);
|
65
|
+
}
|
66
|
+
|
67
|
+
connection.once('failed', reason => {
|
68
|
+
this.connections.delete(channel.guild.id);
|
69
|
+
reject(reason);
|
70
|
+
});
|
71
|
+
|
72
|
+
connection.once('authenticated', () => {
|
73
|
+
connection.once('ready', () => resolve(connection));
|
74
|
+
connection.once('error', reject);
|
75
|
+
connection.once('disconnect', () => this.connections.delete(channel.guild.id));
|
76
|
+
});
|
77
|
+
});
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
module.exports = ClientVoiceManager;
|