distube 3.0.0-beta.35 → 3.0.0-beta.39
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/README.md +4 -3
- package/dist/DisTube.d.ts +78 -57
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +87 -87
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +43 -10
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +45 -11
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeBase.d.ts +7 -13
- package/dist/core/DisTubeBase.d.ts.map +1 -1
- package/dist/core/DisTubeBase.js +4 -9
- package/dist/core/DisTubeBase.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +9 -4
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +56 -10
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeOptions.d.ts +0 -18
- package/dist/core/DisTubeOptions.d.ts.map +1 -1
- package/dist/core/DisTubeOptions.js +4 -1
- package/dist/core/DisTubeOptions.js.map +1 -1
- package/dist/core/DisTubeStream.d.ts +5 -2
- package/dist/core/DisTubeStream.d.ts.map +1 -1
- package/dist/core/DisTubeStream.js +23 -21
- package/dist/core/DisTubeStream.js.map +1 -1
- package/dist/core/manager/BaseManager.d.ts +2 -3
- package/dist/core/manager/BaseManager.d.ts.map +1 -1
- package/dist/core/manager/BaseManager.js +3 -3
- package/dist/core/manager/BaseManager.js.map +1 -1
- package/dist/core/manager/QueueManager.d.ts +2 -2
- package/dist/core/manager/QueueManager.d.ts.map +1 -1
- package/dist/core/manager/QueueManager.js +25 -22
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts +15 -15
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +27 -16
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.js +1 -1
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
- package/dist/plugin/http.js +2 -2
- package/dist/plugin/http.js.map +1 -1
- package/dist/plugin/https.js +3 -3
- package/dist/plugin/https.js.map +1 -1
- package/dist/plugin/youtube-dl.js +3 -3
- package/dist/plugin/youtube-dl.js.map +1 -1
- package/dist/struct/CustomPlugin.d.ts +17 -14
- package/dist/struct/CustomPlugin.d.ts.map +1 -1
- package/dist/struct/CustomPlugin.js +16 -16
- package/dist/struct/CustomPlugin.js.map +1 -1
- package/dist/struct/DisTubeError.d.ts +12 -3
- package/dist/struct/DisTubeError.d.ts.map +1 -1
- package/dist/struct/DisTubeError.js +11 -12
- package/dist/struct/DisTubeError.js.map +1 -1
- package/dist/struct/ExtractorPlugin.d.ts +16 -8
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
- package/dist/struct/ExtractorPlugin.js +13 -12
- package/dist/struct/ExtractorPlugin.js.map +1 -1
- package/dist/struct/Playlist.d.ts +2 -3
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +9 -6
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Plugin.d.ts +62 -9
- package/dist/struct/Plugin.d.ts.map +1 -1
- package/dist/struct/Plugin.js +73 -14
- package/dist/struct/Plugin.js.map +1 -1
- package/dist/struct/Queue.d.ts +17 -15
- package/dist/struct/Queue.d.ts.map +1 -1
- package/dist/struct/Queue.js +31 -16
- package/dist/struct/Queue.js.map +1 -1
- package/dist/struct/SearchResult.js +2 -2
- package/dist/struct/SearchResult.js.map +1 -1
- package/dist/struct/Song.d.ts +6 -8
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +17 -15
- package/dist/struct/Song.js.map +1 -1
- package/dist/struct/__mocks__/Queue.d.ts +12 -0
- package/dist/struct/__mocks__/Queue.d.ts.map +1 -0
- package/dist/struct/__mocks__/Queue.js +22 -0
- package/dist/struct/__mocks__/Queue.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +76 -20
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +16 -7
- package/dist/util.js.map +1 -1
- package/package.json +30 -28
|
@@ -30,13 +30,13 @@ class BaseManager extends DisTubeBase_1.default {
|
|
|
30
30
|
return data;
|
|
31
31
|
}
|
|
32
32
|
get(idOrInstance) {
|
|
33
|
-
return this.collection.get(__1.resolveGuildID(idOrInstance));
|
|
33
|
+
return this.collection.get((0, __1.resolveGuildID)(idOrInstance));
|
|
34
34
|
}
|
|
35
35
|
delete(idOrInstance) {
|
|
36
|
-
this.collection.delete(__1.resolveGuildID(idOrInstance));
|
|
36
|
+
this.collection.delete((0, __1.resolveGuildID)(idOrInstance));
|
|
37
37
|
}
|
|
38
38
|
has(idOrInstance) {
|
|
39
|
-
return this.collection.has(__1.resolveGuildID(idOrInstance));
|
|
39
|
+
return this.collection.has((0, __1.resolveGuildID)(idOrInstance));
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
exports.BaseManager = BaseManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseManager.js","sourceRoot":"","sources":["../../../src/core/manager/BaseManager.ts"],"names":[],"mappings":";;;;;;AAAA,iEAAyC;AACzC,6BAAuC;AACvC,2CAAwC;
|
|
1
|
+
{"version":3,"file":"BaseManager.js","sourceRoot":"","sources":["../../../src/core/manager/BaseManager.ts"],"names":[],"mappings":";;;;;;AAAA,iEAAyC;AACzC,6BAAuC;AACvC,2CAAwC;AAGxC;;;;GAIG;AACH,MAAsB,WAAe,SAAQ,qBAAW;IAEtD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf;;;WAGG;QACH,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,EAAE,CAAC;IACrC,CAAC;IACD,GAAG,CAAC,EAAU,EAAE,IAAO;QACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC9B,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC;SACjB;QACD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,GAAG,CAAC,YAA+B;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAA,kBAAc,EAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,CAAC,YAA+B;QACpC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAA,kBAAc,EAAC,YAAY,CAAC,CAAC,CAAC;IACvD,CAAC;IACD,GAAG,CAAC,YAA+B;QACjC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAA,kBAAc,EAAC,YAAY,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF;AA3BD,kCA2BC;AAED,kBAAe,WAAW,CAAC","sourcesContent":["import DisTubeBase from \"../DisTubeBase\";\nimport { resolveGuildID } from \"../..\";\nimport { Collection } from \"discord.js\";\nimport type { DisTube, GuildIDResolvable } from \"../..\";\n\n/**\n * Manages the collection of a data model.\n * @abstract\n * @private\n */\nexport abstract class BaseManager<V> extends DisTubeBase {\n collection: Collection<string, V>;\n constructor(distube: DisTube) {\n super(distube);\n /**\n * Collection of of a data model.\n * @type {Discord.Collection}\n */\n this.collection = new Collection();\n }\n add(id: string, data: V) {\n const existing = this.get(id);\n if (existing) {\n return existing;\n }\n this.collection.set(id, data);\n return data;\n }\n get(idOrInstance: GuildIDResolvable): V | undefined {\n return this.collection.get(resolveGuildID(idOrInstance));\n }\n delete(idOrInstance: GuildIDResolvable): void {\n this.collection.delete(resolveGuildID(idOrInstance));\n }\n has(idOrInstance: GuildIDResolvable): boolean {\n return this.collection.has(resolveGuildID(idOrInstance));\n }\n}\n\nexport default BaseManager;\n"]}
|
|
@@ -16,10 +16,10 @@ export declare class QueueManager extends BaseManager<Queue> {
|
|
|
16
16
|
*/
|
|
17
17
|
create(channel: VoiceChannel | StageChannel, song: Song[] | Song, textChannel?: TextChannel): Promise<Queue | true>;
|
|
18
18
|
/**
|
|
19
|
-
* Get a Queue from
|
|
19
|
+
* Get a Queue from this QueueManager.
|
|
20
20
|
* @method get
|
|
21
21
|
* @memberof QueueManager#
|
|
22
|
-
* @param {GuildIDResolvable} queue
|
|
22
|
+
* @param {GuildIDResolvable} queue Resolvable thing from a guild
|
|
23
23
|
* @returns {Queue?}
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueManager.d.ts","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAChC,OAAO,EAAgB,KAAK,
|
|
1
|
+
{"version":3,"file":"QueueManager.d.ts","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,CAAC;AAChC,OAAO,EAAgB,KAAK,EAAc,MAAM,OAAO,CAAC;AACxD,OAAO,KAAK,EAAsB,IAAI,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1E;;GAEG;AACH,qBAAa,YAAa,SAAQ,WAAW,CAAC,KAAK,CAAC;IAClD;;;;;;;OAOG;IACG,MAAM,CACV,OAAO,EAAE,YAAY,GAAG,YAAY,EACpC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EACnB,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAgBxB;;;;;;OAMG;IACH;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;;;;OAKG;YACW,iBAAiB;IAyC/B;;;;;OAKG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAiC9C;;;;;OAKG;IACH,OAAO,CAAC,aAAa;CAOtB"}
|
|
@@ -26,18 +26,18 @@ class QueueManager extends _1.BaseManager {
|
|
|
26
26
|
this._voiceEventHandler(queue);
|
|
27
27
|
this.add(queue.id, queue);
|
|
28
28
|
this.emit("initQueue", queue);
|
|
29
|
-
const err = await this.
|
|
30
|
-
return err
|
|
29
|
+
const err = await this.playSong(queue);
|
|
30
|
+
return err || queue;
|
|
31
31
|
}
|
|
32
32
|
finally {
|
|
33
33
|
queue.taskQueue.resolve();
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Get a Queue from
|
|
37
|
+
* Get a Queue from this QueueManager.
|
|
38
38
|
* @method get
|
|
39
39
|
* @memberof QueueManager#
|
|
40
|
-
* @param {GuildIDResolvable} queue
|
|
40
|
+
* @param {GuildIDResolvable} queue Resolvable thing from a guild
|
|
41
41
|
* @returns {Queue?}
|
|
42
42
|
*/
|
|
43
43
|
/**
|
|
@@ -46,20 +46,19 @@ class QueueManager extends _1.BaseManager {
|
|
|
46
46
|
* @param {Queue} queue Queue
|
|
47
47
|
*/
|
|
48
48
|
_voiceEventHandler(queue) {
|
|
49
|
-
queue.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (!error)
|
|
49
|
+
queue.listeners = {
|
|
50
|
+
disconnect: error => {
|
|
51
|
+
queue.delete();
|
|
53
52
|
this.emit("disconnect", queue);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
53
|
+
if (error)
|
|
54
|
+
this.emitError(error, queue.textChannel);
|
|
55
|
+
},
|
|
56
|
+
error: error => this._handlePlayingError(queue, error),
|
|
57
|
+
finish: () => this._handleSongFinish(queue),
|
|
58
|
+
};
|
|
59
|
+
for (const event of Object.keys(queue.listeners)) {
|
|
60
|
+
queue.voice.on(event, queue.listeners[event]);
|
|
61
|
+
}
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
64
|
* Handle the queue when a Song finish
|
|
@@ -73,15 +72,15 @@ class QueueManager extends _1.BaseManager {
|
|
|
73
72
|
try {
|
|
74
73
|
if (queue.stopped)
|
|
75
74
|
return;
|
|
76
|
-
if (queue.repeatMode ===
|
|
75
|
+
if (queue.repeatMode === __1.RepeatMode.QUEUE && !queue.prev)
|
|
77
76
|
queue.songs.push(queue.songs[0]);
|
|
78
77
|
if (queue.prev) {
|
|
79
|
-
if (queue.repeatMode ===
|
|
78
|
+
if (queue.repeatMode === __1.RepeatMode.QUEUE)
|
|
80
79
|
queue.songs.unshift(queue.songs.pop());
|
|
81
80
|
else
|
|
82
81
|
queue.songs.unshift(queue.previousSongs.pop());
|
|
83
82
|
}
|
|
84
|
-
if (queue.songs.length <= 1 && (queue.next ||
|
|
83
|
+
if (queue.songs.length <= 1 && (queue.next || queue.repeatMode === __1.RepeatMode.DISABLED)) {
|
|
85
84
|
if (queue.autoplay) {
|
|
86
85
|
try {
|
|
87
86
|
await queue.addRelatedSong();
|
|
@@ -100,7 +99,7 @@ class QueueManager extends _1.BaseManager {
|
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
const emitPlaySong = this._emitPlaySong(queue);
|
|
103
|
-
if (!queue.prev && (queue.repeatMode !==
|
|
102
|
+
if (!queue.prev && (queue.repeatMode !== __1.RepeatMode.SONG || queue.next)) {
|
|
104
103
|
const prev = queue.songs.shift();
|
|
105
104
|
delete prev.formats;
|
|
106
105
|
delete prev.streamURL;
|
|
@@ -156,6 +155,8 @@ class QueueManager extends _1.BaseManager {
|
|
|
156
155
|
queue.stop();
|
|
157
156
|
return true;
|
|
158
157
|
}
|
|
158
|
+
if (queue.stopped)
|
|
159
|
+
return false;
|
|
159
160
|
queue.playing = true;
|
|
160
161
|
queue.paused = false;
|
|
161
162
|
const song = queue.songs[0];
|
|
@@ -192,7 +193,9 @@ class QueueManager extends _1.BaseManager {
|
|
|
192
193
|
*/
|
|
193
194
|
_emitPlaySong(queue) {
|
|
194
195
|
var _a, _b;
|
|
195
|
-
return !this.options.emitNewSongOnly ||
|
|
196
|
+
return (!this.options.emitNewSongOnly ||
|
|
197
|
+
(queue.repeatMode === __1.RepeatMode.SONG && queue.next) ||
|
|
198
|
+
(queue.repeatMode !== __1.RepeatMode.SONG && ((_a = queue.songs[0]) === null || _a === void 0 ? void 0 : _a.id) !== ((_b = queue.songs[1]) === null || _b === void 0 ? void 0 : _b.id)));
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
exports.QueueManager = QueueManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":";;;AAAA,wBAAgC;AAChC,6BAA4C;AAI5C;;GAEG;AACH,MAAa,YAAa,SAAQ,cAAkB;IAClD;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,OAAoC,EACpC,IAAmB,EACnB,WAAyB;QAEzB,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,aAAa,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,SAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI;YACF,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,kBAAkB,C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MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,CAAU,CAAC;wBAC9E,MAAM,MAAM,GAAU,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;wBAC9C,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;wBAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;wBACzB,MAAM;qBACP;iBACF;aACF;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAChD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,CAAC,EAAE;YACV,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IACD;;;;;OAKG;IACK,aAAa,CAAC,KAAY;;QAChC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,KAAK,CAAC,UAAU,KAAK,CAAC,IAAI,CAAA,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,OAAK,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,CAAA,CAAC,CAAC;IAChH,CAAC;CACF;AA3KD,oCA2KC","sourcesContent":["import { BaseManager } from \".\";\nimport { DisTubeError, Queue } from \"../..\";\nimport type { Song } from \"../..\";\nimport type { StageChannel, TextChannel, VoiceChannel } from \"discord.js\";\n\n/**\n * Queue manager\n */\nexport class QueueManager extends BaseManager<Queue> {\n /**\n * Create a {@link Queue}\n * @private\n * @param {Discord.VoiceChannel|Discord.StageChannel} channel A voice channel\n * @param {Song|Song[]} song First song\n * @param {Discord.TextChannel} textChannel Default text channel\n * @returns {Promise<Queue|true>} Returns `true` if encounter an error\n */\n async create(\n channel: VoiceChannel | StageChannel,\n song: Song[] | Song,\n textChannel?: TextChannel,\n ): Promise<Queue | true> {\n if (this.has(channel.guild.id)) throw new DisTubeError(\"QUEUE_EXIST\");\n const voice = this.voices.create(channel);\n const queue = new Queue(this.distube, voice, song, textChannel);\n await queue.taskQueue.queuing();\n try {\n await voice.join();\n this._voiceEventHandler(queue);\n this.add(queue.id, queue);\n this.emit(\"initQueue\", queue);\n const err = await this.queues.playSong(queue);\n return err ? err : queue;\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Get a Queue from a QueueManager with a GuildIDResolvable.\n * @method get\n * @memberof QueueManager#\n * @param {GuildIDResolvable} queue The queue resolvable to resolve\n * @returns {Queue?}\n */\n /**\n * Listen to DisTubeVoice events and handle the Queue\n * @private\n * @param {Queue} queue Queue\n */\n private _voiceEventHandler(queue: Queue) {\n queue.voice\n .on(\"disconnect\", error => {\n queue.delete();\n if (!error) this.emit(\"disconnect\", queue);\n else this.emitError(error, queue.textChannel);\n })\n .on(\"error\", error => {\n this._handlePlayingError(queue, error);\n })\n .on(\"finish\", () => {\n this._handleSongFinish(queue);\n });\n }\n /**\n * Handle the queue when a Song finish\n * @private\n * @param {Queue} queue queue\n * @returns {Promise<void>}\n */\n private async _handleSongFinish(queue: Queue): Promise<void> {\n this.emit(\"finishSong\", queue, queue.songs[0]);\n await queue.taskQueue.queuing();\n try {\n if (queue.stopped) return;\n if (queue.repeatMode === 2 && !queue.prev) queue.songs.push(queue.songs[0]);\n if (queue.prev) {\n if (queue.repeatMode === 2) queue.songs.unshift(queue.songs.pop() as Song);\n else queue.songs.unshift(queue.previousSongs.pop() as Song);\n }\n if (queue.songs.length <= 1 && (queue.next || !queue.repeatMode)) {\n if (queue.autoplay) {\n try {\n await queue.addRelatedSong();\n } catch {\n this.emit(\"noRelated\", queue);\n }\n }\n if (queue.songs.length <= 1) {\n if (this.options.leaveOnFinish) queue.voice.leave();\n if (!queue.autoplay) this.emit(\"finish\", queue);\n queue.delete();\n return;\n }\n }\n const emitPlaySong = this._emitPlaySong(queue);\n if (!queue.prev && (queue.repeatMode !== 1 || queue.next)) {\n const prev = queue.songs.shift() as Song;\n delete prev.formats;\n delete prev.streamURL;\n if (this.options.savePreviousSongs) queue.previousSongs.push(prev);\n else queue.previousSongs.push({ id: prev.id } as Song);\n }\n queue.next = queue.prev = false;\n queue.beginTime = 0;\n const err = await this.playSong(queue);\n if (!err && emitPlaySong) this.emit(\"playSong\", queue, queue.songs[0]);\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Handle error while playing\n * @private\n * @param {Queue} queue queue\n * @param {Error} error error\n */\n private _handlePlayingError(queue: Queue, error: Error) {\n const song = queue.songs.shift() as Song;\n try {\n error.name = \"PlayingError\";\n error.message = `${error.message}\\nID: ${song.id}\\nName: ${song.name}`;\n } catch {}\n this.emitError(error, queue.textChannel);\n if (queue.songs.length > 0) {\n this.playSong(queue).then(e => {\n if (!e) this.emit(\"playSong\", queue, queue.songs[0]);\n });\n } else {\n queue.stop();\n }\n }\n\n /**\n * Play a song on voice connection\n * @private\n * @param {Queue} queue The guild queue\n * @returns {Promise<boolean>} error?\n */\n async playSong(queue: Queue): Promise<boolean> {\n if (!queue) return true;\n if (!queue.songs.length) {\n queue.stop();\n return true;\n }\n queue.playing = true;\n queue.paused = false;\n const song = queue.songs[0];\n try {\n const { url, source, formats, streamURL } = song;\n if (source === \"youtube\" && !formats) song._patchYouTube(await this.handler.getYouTubeInfo(url));\n if (source !== \"youtube\" && !streamURL) {\n for (const plugin of [...this.distube.extractorPlugins, ...this.distube.customPlugins]) {\n if (await plugin.validate(url)) {\n const info = [plugin.getStreamURL(url), plugin.getRelatedSongs(url)] as const;\n const result: any[] = await Promise.all(info);\n song.streamURL = result[0];\n song.related = result[1];\n break;\n }\n }\n }\n const stream = this.handler.createStream(queue);\n queue.voice.play(stream);\n song.streamURL = stream.url;\n return false;\n } catch (e) {\n this._handlePlayingError(queue, e);\n return true;\n }\n }\n /**\n * Whether or not emit playSong event\n * @param {Queue} queue Queue\n * @private\n * @returns {boolean}\n */\n private _emitPlaySong(queue: Queue): boolean {\n return !this.options.emitNewSongOnly || (queue.repeatMode !== 1 && queue.songs[0]?.id !== queue.songs[1]?.id);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":";;;AAAA,wBAAgC;AAChC,6BAAwD;AAIxD;;GAEG;AACH,MAAa,YAAa,SAAQ,cAAkB;IAClD;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,OAAoC,EACpC,IAAmB,EACnB,WAAyB;QAEzB,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,aAAa,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,SAAK,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAChE,MAAM,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAChC,IAAI;YACF,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAC/B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;YAC1B,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9B,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACvC,OAAO,GAAG,IAAI,KAAK,CAAC;SACrB;gBAAS;YACR,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IACD;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,CAAC;wBAC3B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;wBACzB,MAAM;qBACP;iBACF;aACF;YACD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAChD,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC;YAC5B,OAAO,KAAK,CAAC;SACd;QAAC,OAAO,CAAM,EAAE;YACf,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC;SACb;IACH,CAAC;IACD;;;;;OAKG;IACK,aAAa,CAAC,KAAY;;QAChC,OAAO,CACL,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;YAC7B,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;YACpD,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,CAAA,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,OAAK,MAAA,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,0CAAE,EAAE,CAAA,CAAC,CACpF,CAAC;IACJ,CAAC;CACF;AAhLD,oCAgLC","sourcesContent":["import { BaseManager } from \".\";\nimport { DisTubeError, Queue, RepeatMode } from \"../..\";\nimport type { DisTubeVoiceEvents, Song } from \"../..\";\nimport type { StageChannel, TextChannel, VoiceChannel } from \"discord.js\";\n\n/**\n * Queue manager\n */\nexport class QueueManager extends BaseManager<Queue> {\n /**\n * Create a {@link Queue}\n * @private\n * @param {Discord.VoiceChannel|Discord.StageChannel} channel A voice channel\n * @param {Song|Song[]} song First song\n * @param {Discord.TextChannel} textChannel Default text channel\n * @returns {Promise<Queue|true>} Returns `true` if encounter an error\n */\n async create(\n channel: VoiceChannel | StageChannel,\n song: Song[] | Song,\n textChannel?: TextChannel,\n ): Promise<Queue | true> {\n if (this.has(channel.guild.id)) throw new DisTubeError(\"QUEUE_EXIST\");\n const voice = this.voices.create(channel);\n const queue = new Queue(this.distube, voice, song, textChannel);\n await queue.taskQueue.queuing();\n try {\n await voice.join();\n this._voiceEventHandler(queue);\n this.add(queue.id, queue);\n this.emit(\"initQueue\", queue);\n const err = await this.playSong(queue);\n return err || queue;\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Get a Queue from this QueueManager.\n * @method get\n * @memberof QueueManager#\n * @param {GuildIDResolvable} queue Resolvable thing from a guild\n * @returns {Queue?}\n */\n /**\n * Listen to DisTubeVoice events and handle the Queue\n * @private\n * @param {Queue} queue Queue\n */\n private _voiceEventHandler(queue: Queue) {\n queue.listeners = {\n disconnect: error => {\n queue.delete();\n this.emit(\"disconnect\", queue);\n if (error) this.emitError(error, queue.textChannel);\n },\n error: error => this._handlePlayingError(queue, error),\n finish: () => this._handleSongFinish(queue),\n };\n for (const event of Object.keys(queue.listeners) as (keyof DisTubeVoiceEvents)[]) {\n queue.voice.on(event, queue.listeners[event]);\n }\n }\n /**\n * Handle the queue when a Song finish\n * @private\n * @param {Queue} queue queue\n * @returns {Promise<void>}\n */\n private async _handleSongFinish(queue: Queue): Promise<void> {\n this.emit(\"finishSong\", queue, queue.songs[0]);\n await queue.taskQueue.queuing();\n try {\n if (queue.stopped) return;\n if (queue.repeatMode === RepeatMode.QUEUE && !queue.prev) queue.songs.push(queue.songs[0]);\n if (queue.prev) {\n if (queue.repeatMode === RepeatMode.QUEUE) queue.songs.unshift(queue.songs.pop() as Song);\n else queue.songs.unshift(queue.previousSongs.pop() as Song);\n }\n if (queue.songs.length <= 1 && (queue.next || queue.repeatMode === RepeatMode.DISABLED)) {\n if (queue.autoplay) {\n try {\n await queue.addRelatedSong();\n } catch {\n this.emit(\"noRelated\", queue);\n }\n }\n if (queue.songs.length <= 1) {\n if (this.options.leaveOnFinish) queue.voice.leave();\n if (!queue.autoplay) this.emit(\"finish\", queue);\n queue.delete();\n return;\n }\n }\n const emitPlaySong = this._emitPlaySong(queue);\n if (!queue.prev && (queue.repeatMode !== RepeatMode.SONG || queue.next)) {\n const prev = queue.songs.shift() as Song;\n delete prev.formats;\n delete prev.streamURL;\n if (this.options.savePreviousSongs) queue.previousSongs.push(prev);\n else queue.previousSongs.push({ id: prev.id } as Song);\n }\n queue.next = queue.prev = false;\n queue.beginTime = 0;\n const err = await this.playSong(queue);\n if (!err && emitPlaySong) this.emit(\"playSong\", queue, queue.songs[0]);\n } finally {\n queue.taskQueue.resolve();\n }\n }\n /**\n * Handle error while playing\n * @private\n * @param {Queue} queue queue\n * @param {Error} error error\n */\n private _handlePlayingError(queue: Queue, error: Error) {\n const song = queue.songs.shift() as Song;\n try {\n error.name = \"PlayingError\";\n error.message = `${error.message}\\nID: ${song.id}\\nName: ${song.name}`;\n } catch {}\n this.emitError(error, queue.textChannel);\n if (queue.songs.length > 0) {\n this.playSong(queue).then(e => {\n if (!e) this.emit(\"playSong\", queue, queue.songs[0]);\n });\n } else {\n queue.stop();\n }\n }\n\n /**\n * Play a song on voice connection\n * @private\n * @param {Queue} queue The guild queue\n * @returns {Promise<boolean>} error?\n */\n async playSong(queue: Queue): Promise<boolean> {\n if (!queue) return true;\n if (!queue.songs.length) {\n queue.stop();\n return true;\n }\n if (queue.stopped) return false;\n queue.playing = true;\n queue.paused = false;\n const song = queue.songs[0];\n try {\n const { url, source, formats, streamURL } = song;\n if (source === \"youtube\" && !formats) song._patchYouTube(await this.handler.getYouTubeInfo(url));\n if (source !== \"youtube\" && !streamURL) {\n for (const plugin of [...this.distube.extractorPlugins, ...this.distube.customPlugins]) {\n if (await plugin.validate(url)) {\n const info = [plugin.getStreamURL(url), plugin.getRelatedSongs(url)] as const;\n const result: any[] = await Promise.all(info);\n song.streamURL = result[0];\n song.related = result[1];\n break;\n }\n }\n }\n const stream = this.handler.createStream(queue);\n queue.voice.play(stream);\n song.streamURL = stream.url;\n return false;\n } catch (e: any) {\n this._handlePlayingError(queue, e);\n return true;\n }\n }\n /**\n * Whether or not emit playSong event\n * @param {Queue} queue Queue\n * @private\n * @returns {boolean}\n */\n private _emitPlaySong(queue: Queue): boolean {\n return (\n !this.options.emitNewSongOnly ||\n (queue.repeatMode === RepeatMode.SONG && queue.next) ||\n (queue.repeatMode !== RepeatMode.SONG && queue.songs[0]?.id !== queue.songs[1]?.id)\n );\n }\n}\n"]}
|
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import type DisTubeStream from "../DisTubeStream";
|
|
4
|
-
import type { DisTubeVoiceManager } from "./DisTubeVoiceManager";
|
|
5
|
-
import type { Snowflake, StageChannel, VoiceChannel } from "discord.js";
|
|
1
|
+
import { TypedEmitter } from "tiny-typed-emitter";
|
|
2
|
+
import type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from "../..";
|
|
6
3
|
import type { AudioPlayer, AudioResource, VoiceConnection } from "@discordjs/voice";
|
|
7
|
-
|
|
4
|
+
import type { Snowflake, StageChannel, VoiceChannel, VoiceState } from "discord.js";
|
|
5
|
+
/**
|
|
6
|
+
* Create a voice connection to the voice channel
|
|
7
|
+
*/
|
|
8
|
+
export declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
|
|
8
9
|
id: Snowflake;
|
|
9
10
|
voices: DisTubeVoiceManager;
|
|
10
11
|
audioPlayer: AudioPlayer;
|
|
11
12
|
connection: VoiceConnection;
|
|
12
13
|
audioResource?: AudioResource;
|
|
13
14
|
emittedError: boolean;
|
|
14
|
-
|
|
15
|
-
on(event: "error", listener: (error: Error) => void): this;
|
|
16
|
-
on(event: "finish", listener: () => void): this;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Create a voice connection to the voice channel
|
|
20
|
-
*/
|
|
21
|
-
export declare class DisTubeVoice extends EventEmitter {
|
|
15
|
+
isDisconnected: boolean;
|
|
22
16
|
private _channel;
|
|
23
17
|
private _volume;
|
|
24
18
|
constructor(voiceManager: DisTubeVoiceManager, channel: VoiceChannel | StageChannel);
|
|
@@ -34,8 +28,9 @@ export declare class DisTubeVoice extends EventEmitter {
|
|
|
34
28
|
join(channel?: VoiceChannel | StageChannel): Promise<DisTubeVoice>;
|
|
35
29
|
/**
|
|
36
30
|
* Leave the voice channel of this connection
|
|
31
|
+
* @param {Error} [error] Optional, an error to emit with 'error' event.
|
|
37
32
|
*/
|
|
38
|
-
leave(): void;
|
|
33
|
+
leave(error?: Error): void;
|
|
39
34
|
/**
|
|
40
35
|
* Stop the playing stream
|
|
41
36
|
* @private
|
|
@@ -78,6 +73,11 @@ export declare class DisTubeVoice extends EventEmitter {
|
|
|
78
73
|
* @returns {boolean} true if the voice state was successfully updated, otherwise false
|
|
79
74
|
*/
|
|
80
75
|
setSelfMute(selfMute: boolean): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* The voice state of this connection
|
|
78
|
+
* @type {Discord.VoiceState?}
|
|
79
|
+
*/
|
|
80
|
+
get voiceState(): VoiceState | undefined;
|
|
81
81
|
}
|
|
82
82
|
export default DisTubeVoice;
|
|
83
83
|
//# sourceMappingURL=DisTubeVoice.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoice.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DisTubeVoice.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAWlD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAAE,SAAS,EAAE,YAA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AAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAEvC;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DisTubeVoice = void 0;
|
|
4
|
-
const
|
|
4
|
+
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
5
5
|
const __1 = require("../..");
|
|
6
6
|
const voice_1 = require("@discordjs/voice");
|
|
7
7
|
/**
|
|
8
8
|
* Create a voice connection to the voice channel
|
|
9
9
|
*/
|
|
10
|
-
class DisTubeVoice extends
|
|
10
|
+
class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
11
11
|
constructor(voiceManager, channel) {
|
|
12
12
|
super();
|
|
13
|
-
if (!__1.isSupportedVoiceChannel(channel))
|
|
13
|
+
if (!(0, __1.isSupportedVoiceChannel)(channel))
|
|
14
14
|
throw new __1.DisTubeError("NOT_SUPPORTED_VOICE");
|
|
15
15
|
if (!channel.joinable) {
|
|
16
16
|
if (channel.full)
|
|
@@ -18,6 +18,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
18
18
|
else
|
|
19
19
|
throw new __1.DisTubeError("VOICE_MISSING_PERMS");
|
|
20
20
|
}
|
|
21
|
+
this.isDisconnected = false;
|
|
21
22
|
this.id = channel.guild.id;
|
|
22
23
|
this.channel = channel;
|
|
23
24
|
/**
|
|
@@ -27,7 +28,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
27
28
|
this.voices = voiceManager;
|
|
28
29
|
this.voices.add(this.id, this);
|
|
29
30
|
this._volume = 0.5;
|
|
30
|
-
this.audioPlayer = voice_1.createAudioPlayer()
|
|
31
|
+
this.audioPlayer = (0, voice_1.createAudioPlayer)()
|
|
31
32
|
.on(voice_1.AudioPlayerStatus.Idle, oldState => {
|
|
32
33
|
if (oldState.status !== voice_1.AudioPlayerStatus.Idle) {
|
|
33
34
|
delete this.audioResource;
|
|
@@ -43,8 +44,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
43
44
|
this.connection
|
|
44
45
|
.on(voice_1.VoiceConnectionStatus.Disconnected, (_, newState) => {
|
|
45
46
|
if (newState.reason === voice_1.VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {
|
|
46
|
-
voice_1.entersState(this.connection, voice_1.VoiceConnectionStatus.Connecting,
|
|
47
|
-
this.emit("disconnect");
|
|
47
|
+
(0, voice_1.entersState)(this.connection, voice_1.VoiceConnectionStatus.Connecting, 5e3).catch(() => {
|
|
48
48
|
this.leave();
|
|
49
49
|
});
|
|
50
50
|
}
|
|
@@ -54,8 +54,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
54
54
|
}, (this.connection.rejoinAttempts + 1) * 5e3).unref();
|
|
55
55
|
}
|
|
56
56
|
else if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
|
|
57
|
-
this.
|
|
58
|
-
this.leave();
|
|
57
|
+
this.leave(new __1.DisTubeError("VOICE_RECONNECT_FAILED"));
|
|
59
58
|
}
|
|
60
59
|
})
|
|
61
60
|
.on(voice_1.VoiceConnectionStatus.Destroyed, () => {
|
|
@@ -74,7 +73,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
74
73
|
return this._channel;
|
|
75
74
|
}
|
|
76
75
|
set channel(channel) {
|
|
77
|
-
if (!__1.isSupportedVoiceChannel(channel))
|
|
76
|
+
if (!(0, __1.isSupportedVoiceChannel)(channel))
|
|
78
77
|
throw new __1.DisTubeError("NOT_SUPPORTED_VOICE");
|
|
79
78
|
if (channel.guild.id !== this.id)
|
|
80
79
|
throw new __1.DisTubeError("VOICE_CHANGE_GUILD");
|
|
@@ -82,10 +81,10 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
82
81
|
this._channel = channel;
|
|
83
82
|
}
|
|
84
83
|
_join(channel) {
|
|
85
|
-
return voice_1.joinVoiceChannel({
|
|
84
|
+
return (0, voice_1.joinVoiceChannel)({
|
|
86
85
|
channelId: channel.id,
|
|
87
86
|
guildId: this.id,
|
|
88
|
-
adapterCreator: channel.guild.voiceAdapterCreator || __1.createDiscordJSAdapter(channel),
|
|
87
|
+
adapterCreator: channel.guild.voiceAdapterCreator || (0, __1.createDiscordJSAdapter)(channel),
|
|
89
88
|
});
|
|
90
89
|
}
|
|
91
90
|
/**
|
|
@@ -100,7 +99,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
100
99
|
this.channel = channel;
|
|
101
100
|
}
|
|
102
101
|
try {
|
|
103
|
-
await voice_1.entersState(this.connection, voice_1.VoiceConnectionStatus.Ready, TIMEOUT);
|
|
102
|
+
await (0, voice_1.entersState)(this.connection, voice_1.VoiceConnectionStatus.Ready, TIMEOUT);
|
|
104
103
|
}
|
|
105
104
|
catch {
|
|
106
105
|
if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
|
|
@@ -113,12 +112,16 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* Leave the voice channel of this connection
|
|
115
|
+
* @param {Error} [error] Optional, an error to emit with 'error' event.
|
|
116
116
|
*/
|
|
117
|
-
leave() {
|
|
117
|
+
leave(error) {
|
|
118
118
|
this.stop();
|
|
119
|
-
if (this.
|
|
120
|
-
this.
|
|
119
|
+
if (!this.isDisconnected) {
|
|
120
|
+
this.emit("disconnect", error);
|
|
121
|
+
this.isDisconnected = true;
|
|
121
122
|
}
|
|
123
|
+
if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed)
|
|
124
|
+
this.connection.destroy();
|
|
122
125
|
this.voices.delete(this.id);
|
|
123
126
|
}
|
|
124
127
|
/**
|
|
@@ -141,7 +144,7 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
141
144
|
this.emittedError = true;
|
|
142
145
|
this.emit("error", error);
|
|
143
146
|
});
|
|
144
|
-
this.audioResource = voice_1.createAudioResource(stream.stream, {
|
|
147
|
+
this.audioResource = (0, voice_1.createAudioResource)(stream.stream, {
|
|
145
148
|
inputType: stream.type,
|
|
146
149
|
inlineVolume: true,
|
|
147
150
|
});
|
|
@@ -219,6 +222,14 @@ class DisTubeVoice extends events_1.EventEmitter {
|
|
|
219
222
|
selfMute,
|
|
220
223
|
});
|
|
221
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* The voice state of this connection
|
|
227
|
+
* @type {Discord.VoiceState?}
|
|
228
|
+
*/
|
|
229
|
+
get voiceState() {
|
|
230
|
+
var _a, _b, _c;
|
|
231
|
+
return (_c = (_b = (_a = this.channel) === null || _a === void 0 ? void 0 : _a.guild) === null || _b === void 0 ? void 0 : _b.me) === null || _c === void 0 ? void 0 : _c.voice;
|
|
232
|
+
}
|
|
222
233
|
}
|
|
223
234
|
exports.DisTubeVoice = DisTubeVoice;
|
|
224
235
|
exports.default = DisTubeVoice;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AACtC,6BAAsF;AACtF,4CAQ0B;AAiB1B;;GAEG;AACH,MAAa,YAAa,SAAQ,qBAAY;IAG5C,YAAY,YAAiC,EAAE,OAAoC;QACjF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,2BAAuB,CAAC,OAAO,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;QACrF,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,gBAAY,CAAC,YAAY,CAAC,CAAC;;gBAClD,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC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B;;QAClB,OAAO,CAAC,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,gBAAgB,KAAI,CAAC,CAAC,GAAG,IAAI,CAAC;IAC5D,CAAC;IACD,KAAK;QACH,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IACD;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD;;;;OAIG;IACH,WAAW,CAAC,QAAiB;QAC3B,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IACD;;;;OAIG;IACH,WAAW,CAAC,QAAiB;QAC3B,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF;AA1MD,oCA0MC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { EventEmitter } from \"events\";\nimport { DisTubeError, createDiscordJSAdapter, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n entersState,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type DisTubeStream from \"../DisTubeStream\";\nimport type { DisTubeVoiceManager } from \"./DisTubeVoiceManager\";\nimport type { Snowflake, StageChannel, VoiceChannel } from \"discord.js\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\n\nexport declare interface DisTubeVoice {\n id: Snowflake;\n voices: DisTubeVoiceManager;\n audioPlayer: AudioPlayer;\n connection: VoiceConnection;\n audioResource?: AudioResource;\n emittedError: boolean;\n on(event: \"disconnect\", listener: (error?: Error) => void): this;\n on(event: \"error\", listener: (error: Error) => void): this;\n on(event: \"finish\", listener: () => void): this;\n}\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends EventEmitter {\n private _channel!: VoiceChannel | StageChannel;\n private _volume: number;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceChannel | StageChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.id = channel.guild.id;\n this.channel = channel;\n /**\n * The voice manager that instantiated this connection\n * @type {DisTubeVoiceManager}\n */\n this.voices = voiceManager;\n this.voices.add(this.id, this);\n this._volume = 0.5;\n this.audioPlayer = createAudioPlayer()\n .on(AudioPlayerStatus.Idle, oldState => {\n if (oldState.status !== AudioPlayerStatus.Idle) {\n delete this.audioResource;\n this.emit(\"finish\");\n }\n })\n .on(\"error\", error => {\n if (this.emittedError) return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.connection\n .on(VoiceConnectionStatus.Disconnected, (_, newState) => {\n if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {\n entersState(this.connection, VoiceConnectionStatus.Connecting, 3e3).catch(() => {\n this.emit(\"disconnect\");\n this.leave();\n });\n } else if (this.connection.rejoinAttempts < 5) {\n setTimeout(() => {\n this.connection.rejoin();\n }, (this.connection.rejoinAttempts + 1) * 5e3).unref();\n } else if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.emit(\"disconnect\", new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n this.leave();\n }\n })\n .on(VoiceConnectionStatus.Destroyed, () => {\n this.leave();\n })\n // eslint-disable-next-line no-console\n .on(\"error\", console.warn);\n this.connection.subscribe(this.audioPlayer);\n /**\n * Get or set the volume percentage\n * @name DisTubeVoice#volume\n * @type {number}\n */\n }\n get channel() {\n return this._channel;\n }\n set channel(channel: VoiceChannel | StageChannel) {\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (channel.guild.id !== this.id) throw new DisTubeError(\"VOICE_CHANGE_GUILD\");\n this.connection = this._join(channel);\n this._channel = channel;\n }\n private _join(channel: VoiceChannel | StageChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: channel.guild.voiceAdapterCreator || createDiscordJSAdapter(channel as any),\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.VoiceChannel|Discord.StageChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceChannel | StageChannel): Promise<DisTubeVoice> {\n const TIMEOUT = 30e3;\n if (channel) {\n this.channel = channel;\n }\n try {\n await entersState(this.connection, VoiceConnectionStatus.Ready, TIMEOUT);\n } catch {\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.connection.destroy();\n }\n this.voices.delete(this.id);\n throw new DisTubeError(\"VOICE_CONNECT_FAILED\", TIMEOUT / 1e3);\n }\n return this;\n }\n /**\n * Leave the voice channel of this connection\n */\n leave() {\n this.stop();\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.connection.destroy();\n }\n this.voices.delete(this.id);\n }\n /**\n * Stop the playing stream\n * @private\n */\n stop() {\n this.audioPlayer.stop();\n }\n /**\n * Play a readable stream\n * @private\n * @param {DisTubeStream} stream Readable stream\n */\n play(stream: DisTubeStream) {\n this.emittedError = false;\n stream.stream.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (this.emittedError || error.code === \"ERR_STREAM_PREMATURE_CLOSE\") return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.audioResource = createAudioResource(stream.stream, {\n inputType: stream.type,\n inlineVolume: true,\n });\n // eslint-disable-next-line no-self-assign\n this.volume = this.volume;\n this.audioPlayer.play(this.audioResource);\n }\n set volume(volume: number) {\n if (typeof volume !== \"number\" || isNaN(volume)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"number\", volume, \"volume\");\n }\n if (volume < 0) {\n throw new DisTubeError(\"NUMBER_COMPARE\", \"Volume\", \"bigger or equal to\", 0);\n }\n this._volume = volume / 100;\n this.audioResource?.volume?.setVolume(Math.pow(this._volume, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this._volume * 100;\n }\n /**\n * Playback duration of the audio resource in seconds\n * @type {number}\n */\n get playbackDuration() {\n return (this.audioResource?.playbackDuration || 0) / 1000;\n }\n pause() {\n this.audioPlayer.pause();\n }\n unpause() {\n this.audioPlayer.unpause();\n }\n /**\n * Whether the bot is self-deafened\n * @type {boolean}\n */\n get selfDeaf(): boolean {\n return this.connection.joinConfig.selfDeaf;\n }\n /**\n * Whether the bot is self-muted\n * @type {boolean}\n */\n get selfMute(): boolean {\n return this.connection.joinConfig.selfMute;\n }\n /**\n * Self-deafens/undeafens the bot.\n * @param {boolean} selfDeaf Whether or not the bot should be self-deafened\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfDeaf(selfDeaf: boolean): boolean {\n if (typeof selfDeaf !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfDeaf, \"selfDeaf\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfDeaf,\n });\n }\n /**\n * Self-mutes/unmutes the bot.\n * @param {boolean} selfMute Whether or not the bot should be self-muted\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfMute(selfMute: boolean): boolean {\n if (typeof selfMute !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfMute, \"selfMute\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfMute,\n });\n }\n}\n\nexport default DisTubeVoice;\n"]}
|
|
1
|
+
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;AAAA,2DAAkD;AAClD,6BAAsF;AACtF,4CAQ0B;AAK1B;;GAEG;AACH,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAAoC;QACjF,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC;YAAE,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;QACrF,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACrB,IAAI,OAAO,CAAC,IAAI;gBAAE,MAAM,IAAI,gBAAY,CAAC,YAAY,CAAC,CAAC;;gBAClD,MAAM,IAAI,gBAAY,CAAC,qBAAqB,CAAC,CAAC;SACpD;QACD,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC;QAC5B,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;QACnB,IAAI,CAAC,WAAW,GAAG,IAAA,yBAAiB,GAAE;aAC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AAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO;QACL,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IACD;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD;;;OAGG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC;IAC7C,CAAC;IACD;;;;OAIG;IACH,WAAW,CAAC,QAAiB;QAC3B,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IACD;;;;OAIG;IACH,WAAW,CAAC,QAAiB;QAC3B,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE;YACjC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;SACzE;QACD,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YAC5B,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU;YAC7B,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IACD;;;OAGG;IACH,IAAI,UAAU;;QACZ,OAAO,MAAA,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,KAAK,0CAAE,EAAE,0CAAE,KAAK,CAAC;IACxC,CAAC;CACF;AA1ND,oCA0NC;AAED,kBAAe,YAAY,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, createDiscordJSAdapter, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n entersState,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, StageChannel, VoiceChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n id: Snowflake;\n voices: DisTubeVoiceManager;\n audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected: boolean;\n private _channel!: VoiceChannel | StageChannel;\n private _volume: number;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceChannel | StageChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (!channel.joinable) {\n if (channel.full) throw new DisTubeError(\"VOICE_FULL\");\n else throw new DisTubeError(\"VOICE_MISSING_PERMS\");\n }\n this.isDisconnected = false;\n this.id = channel.guild.id;\n this.channel = channel;\n /**\n * The voice manager that instantiated this connection\n * @type {DisTubeVoiceManager}\n */\n this.voices = voiceManager;\n this.voices.add(this.id, this);\n this._volume = 0.5;\n this.audioPlayer = createAudioPlayer()\n .on(AudioPlayerStatus.Idle, oldState => {\n if (oldState.status !== AudioPlayerStatus.Idle) {\n delete this.audioResource;\n this.emit(\"finish\");\n }\n })\n .on(\"error\", error => {\n if (this.emittedError) return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.connection\n .on(VoiceConnectionStatus.Disconnected, (_, newState) => {\n if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode === 4014) {\n entersState(this.connection, VoiceConnectionStatus.Connecting, 5e3).catch(() => {\n this.leave();\n });\n } else if (this.connection.rejoinAttempts < 5) {\n setTimeout(() => {\n this.connection.rejoin();\n }, (this.connection.rejoinAttempts + 1) * 5e3).unref();\n } else if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.leave(new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n }\n })\n .on(VoiceConnectionStatus.Destroyed, () => {\n this.leave();\n })\n // eslint-disable-next-line no-console\n .on(\"error\", console.warn);\n this.connection.subscribe(this.audioPlayer);\n /**\n * Get or set the volume percentage\n * @name DisTubeVoice#volume\n * @type {number}\n */\n }\n get channel() {\n return this._channel;\n }\n set channel(channel: VoiceChannel | StageChannel) {\n if (!isSupportedVoiceChannel(channel)) throw new DisTubeError(\"NOT_SUPPORTED_VOICE\");\n if (channel.guild.id !== this.id) throw new DisTubeError(\"VOICE_CHANGE_GUILD\");\n this.connection = this._join(channel);\n this._channel = channel;\n }\n private _join(channel: VoiceChannel | StageChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: channel.guild.voiceAdapterCreator || createDiscordJSAdapter(channel as any),\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.VoiceChannel|Discord.StageChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceChannel | StageChannel): Promise<DisTubeVoice> {\n const TIMEOUT = 30e3;\n if (channel) {\n this.channel = channel;\n }\n try {\n await entersState(this.connection, VoiceConnectionStatus.Ready, TIMEOUT);\n } catch {\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) {\n this.connection.destroy();\n }\n this.voices.delete(this.id);\n throw new DisTubeError(\"VOICE_CONNECT_FAILED\", TIMEOUT / 1e3);\n }\n return this;\n }\n /**\n * Leave the voice channel of this connection\n * @param {Error} [error] Optional, an error to emit with 'error' event.\n */\n leave(error?: Error) {\n this.stop();\n if (!this.isDisconnected) {\n this.emit(\"disconnect\", error);\n this.isDisconnected = true;\n }\n if (this.connection.state.status !== VoiceConnectionStatus.Destroyed) this.connection.destroy();\n this.voices.delete(this.id);\n }\n /**\n * Stop the playing stream\n * @private\n */\n stop() {\n this.audioPlayer.stop();\n }\n /**\n * Play a readable stream\n * @private\n * @param {DisTubeStream} stream Readable stream\n */\n play(stream: DisTubeStream) {\n this.emittedError = false;\n stream.stream.on(\"error\", (error: NodeJS.ErrnoException) => {\n if (this.emittedError || error.code === \"ERR_STREAM_PREMATURE_CLOSE\") return;\n this.emittedError = true;\n this.emit(\"error\", error);\n });\n this.audioResource = createAudioResource(stream.stream, {\n inputType: stream.type,\n inlineVolume: true,\n });\n // eslint-disable-next-line no-self-assign\n this.volume = this.volume;\n this.audioPlayer.play(this.audioResource);\n }\n set volume(volume: number) {\n if (typeof volume !== \"number\" || isNaN(volume)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"number\", volume, \"volume\");\n }\n if (volume < 0) {\n throw new DisTubeError(\"NUMBER_COMPARE\", \"Volume\", \"bigger or equal to\", 0);\n }\n this._volume = volume / 100;\n this.audioResource?.volume?.setVolume(Math.pow(this._volume, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this._volume * 100;\n }\n /**\n * Playback duration of the audio resource in seconds\n * @type {number}\n */\n get playbackDuration() {\n return (this.audioResource?.playbackDuration || 0) / 1000;\n }\n pause() {\n this.audioPlayer.pause();\n }\n unpause() {\n this.audioPlayer.unpause();\n }\n /**\n * Whether the bot is self-deafened\n * @type {boolean}\n */\n get selfDeaf(): boolean {\n return this.connection.joinConfig.selfDeaf;\n }\n /**\n * Whether the bot is self-muted\n * @type {boolean}\n */\n get selfMute(): boolean {\n return this.connection.joinConfig.selfMute;\n }\n /**\n * Self-deafens/undeafens the bot.\n * @param {boolean} selfDeaf Whether or not the bot should be self-deafened\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfDeaf(selfDeaf: boolean): boolean {\n if (typeof selfDeaf !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfDeaf, \"selfDeaf\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfDeaf,\n });\n }\n /**\n * Self-mutes/unmutes the bot.\n * @param {boolean} selfMute Whether or not the bot should be self-muted\n * @returns {boolean} true if the voice state was successfully updated, otherwise false\n */\n setSelfMute(selfMute: boolean): boolean {\n if (typeof selfMute !== \"boolean\") {\n throw new DisTubeError(\"INVALID_TYPE\", \"boolean\", selfMute, \"selfMute\");\n }\n return this.connection.rejoin({\n ...this.connection.joinConfig,\n selfMute,\n });\n }\n /**\n * The voice state of this connection\n * @type {Discord.VoiceState?}\n */\n get voiceState(): VoiceState | undefined {\n return this.channel?.guild?.me?.voice;\n }\n}\n\nexport default DisTubeVoice;\n"]}
|
|
@@ -55,7 +55,7 @@ class DisTubeVoiceManager extends manager_1.BaseManager {
|
|
|
55
55
|
voice.leave();
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
const connection = voice_1.getVoiceConnection(__1.resolveGuildID(guild));
|
|
58
|
+
const connection = (0, voice_1.getVoiceConnection)((0, __1.resolveGuildID)(guild));
|
|
59
59
|
if (connection && connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
|
|
60
60
|
connection.destroy();
|
|
61
61
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoiceManager.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,6BAAuC;AACvC,wCAAyC;AACzC,4CAA6E;AAI7E;;GAEG;AACH,MAAa,mBAAoB,SAAQ,qBAAyB;IAChE;;;;;;OAMG;IACH;;;;OAIG;IACH;;;;;OAKG;IACH,MAAM,CAAC,OAAoC;QACzC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ,EAAE;YACZ,OAAO,QAAQ,CAAC;SACjB;QACD,OAAO,IAAI,eAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzC,CA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AAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IACD;;;OAGG;IACH,KAAK,CAAC,KAAwB;QAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,IAAI,KAAK,EAAE;YACT,KAAK,CAAC,KAAK,EAAE,CAAC;SACf;aAAM;YACL,MAAM,UAAU,GAAG,IAAA,0BAAkB,EAAC,IAAA,kBAAc,EAAC,KAAK,CAAC,CAAC,CAAC;YAC7D,IAAI,UAAU,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,KAAK,6BAAqB,CAAC,SAAS,EAAE;gBAC7E,UAAU,CAAC,OAAO,EAAE,CAAC;aACtB;SACF;IACH,CAAC;CACF;AAnDD,kDAmDC;AAED,kBAAe,mBAAmB,CAAC","sourcesContent":["import { DisTubeVoice } from \".\";\nimport { resolveGuildID } from \"../..\";\nimport { BaseManager } from \"../manager\";\nimport { VoiceConnectionStatus, getVoiceConnection } from \"@discordjs/voice\";\nimport type { GuildIDResolvable } from \"../..\";\nimport type { StageChannel, VoiceChannel } from \"discord.js\";\n\n/**\n * Manages voice connections for {@link DisTube}\n */\nexport class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {\n /**\n * Get a {@link DisTubeVoice}.\n * @method get\n * @memberof DisTubeVoiceManager#\n * @param {GuildIDResolvable} queue The queue resolvable to resolve\n * @returns {DisTubeVoice?}\n */\n /**\n * Collection of {@link DisTubeVoice}.\n * @name DisTubeVoiceManager#collection\n * @type {Discord.Collection<string, DisTubeVoice>}\n */\n /**\n * Create a {@link DisTubeVoice}\n * @param {Discord.VoiceChannel|Discord.StageChannel} channel A voice channel to join\n * @returns {DisTubeVoice}\n * @private\n */\n create(channel: VoiceChannel | StageChannel): DisTubeVoice {\n const existing = this.get(channel.guild.id);\n if (existing) {\n return existing;\n }\n return new DisTubeVoice(this, channel);\n }\n /**\n * Join a voice channel\n * @param {Discord.VoiceChannel|Discord.StageChannel} channel A voice channel to join\n * @returns {Promise<DisTubeVoice>}\n */\n join(channel: VoiceChannel | StageChannel): Promise<DisTubeVoice> {\n const existing = this.get(channel.guild.id);\n if (existing) return existing.join(channel);\n return this.create(channel).join();\n }\n /**\n * Leave the connected voice channel in a guild\n * @param {GuildIDResolvable} guild Queue Resolvable\n */\n leave(guild: GuildIDResolvable) {\n const voice = this.get(guild);\n if (voice) {\n voice.leave();\n } else {\n const connection = getVoiceConnection(resolveGuildID(guild));\n if (connection && connection.state.status !== VoiceConnectionStatus.Destroyed) {\n connection.destroy();\n }\n }\n }\n}\n\nexport default DisTubeVoiceManager;\n"]}
|
package/dist/plugin/http.js
CHANGED
|
@@ -9,10 +9,10 @@ const ExtractorPlugin_1 = __importDefault(require("../struct/ExtractorPlugin"));
|
|
|
9
9
|
const __1 = require("..");
|
|
10
10
|
class HTTPPlugin extends ExtractorPlugin_1.default {
|
|
11
11
|
async validate(url) {
|
|
12
|
-
return __1.validateAudioURL(http_1.default, "http:", url);
|
|
12
|
+
return (0, __1.validateAudioURL)(http_1.default, "http:", url);
|
|
13
13
|
}
|
|
14
14
|
async resolve(url, member) {
|
|
15
|
-
return __1.resolveHttpSong("http", url, member);
|
|
15
|
+
return (0, __1.resolveHttpSong)("http", url, member);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
exports.HTTPPlugin = HTTPPlugin;
|
package/dist/plugin/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/plugin/http.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,gFAAwD;AACxD,0BAAuD;AAGvD,MAAa,UAAW,SAAQ,yBAAe;IAC7C,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,OAAO,oBAAgB,
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/plugin/http.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,gFAAwD;AACxD,0BAAuD;AAGvD,MAAa,UAAW,SAAQ,yBAAe;IAC7C,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,OAAO,IAAA,oBAAgB,EAAC,cAAI,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,MAAmB;QAC5C,OAAO,IAAA,mBAAe,EAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC9C,CAAC;CACF;AARD,gCAQC;AAED,kBAAe,UAAU,CAAC","sourcesContent":["import http from \"http\";\nimport ExtractorPlugin from \"../struct/ExtractorPlugin\";\nimport { resolveHttpSong, validateAudioURL } from \"..\";\nimport type { GuildMember } from \"discord.js\";\n\nexport class HTTPPlugin extends ExtractorPlugin {\n async validate(url: string) {\n return validateAudioURL(http, \"http:\", url);\n }\n\n async resolve(url: string, member: GuildMember) {\n return resolveHttpSong(\"http\", url, member);\n }\n}\n\nexport default HTTPPlugin;\n"]}
|
package/dist/plugin/https.js
CHANGED
|
@@ -21,7 +21,7 @@ const validateAudioURL = async (httpModule, protocol, url) => {
|
|
|
21
21
|
if (new url_1.URL(url).protocol.toLowerCase() !== protocol) {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
|
-
const headers = await exports.getResponseHeaders(httpModule, url), type = headers["content-type"];
|
|
24
|
+
const headers = await (0, exports.getResponseHeaders)(httpModule, url), type = headers["content-type"];
|
|
25
25
|
if (type === null || type === void 0 ? void 0 : type.startsWith("audio")) {
|
|
26
26
|
return true;
|
|
27
27
|
}
|
|
@@ -39,10 +39,10 @@ const resolveHttpSong = async (source, url, member) => {
|
|
|
39
39
|
exports.resolveHttpSong = resolveHttpSong;
|
|
40
40
|
class HTTPSPlugin extends ExtractorPlugin_1.default {
|
|
41
41
|
async validate(url) {
|
|
42
|
-
return exports.validateAudioURL(https_1.default, "https:", url);
|
|
42
|
+
return (0, exports.validateAudioURL)(https_1.default, "https:", url);
|
|
43
43
|
}
|
|
44
44
|
async resolve(url, member) {
|
|
45
|
-
return exports.resolveHttpSong("https", url, member);
|
|
45
|
+
return (0, exports.resolveHttpSong)("https", url, member);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
exports.HTTPSPlugin = HTTPSPlugin;
|
package/dist/plugin/https.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"https.js","sourceRoot":"","sources":["../../src/plugin/https.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,gFAAwD;AACxD,6BAA0B;AAC1B,0BAA0B;AAInB,MAAM,kBAAkB,GAAG,KAAK,EACrC,UAAsC,EACtC,GAAW,EACwB,EAAE,CACrC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;IAC9B,UAAU;SACP,GAAG,CAAC,GAAG,CAAC;SACR,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE;QACpB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC;SACD,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC,CAAC,CAAC;AAXQ,QAAA,kBAAkB,sBAW1B;AAEE,MAAM,gBAAgB,GAAG,KAAK,EAAE,UAAsC,EAAE,QAAgB,EAAE,GAAW,EAAE,EAAE;IAC9G,IAAI,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,QAAQ,EAAE;QACpD,OAAO,KAAK,CAAC;KACd;IACD,MAAM,OAAO,GAAG,MAAM,0BAAkB,
|
|
1
|
+
{"version":3,"file":"https.js","sourceRoot":"","sources":["../../src/plugin/https.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,gFAAwD;AACxD,6BAA0B;AAC1B,0BAA0B;AAInB,MAAM,kBAAkB,GAAG,KAAK,EACrC,UAAsC,EACtC,GAAW,EACwB,EAAE,CACrC,IAAI,OAAO,CAAC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,mBAU1B;AAEF,MAAa,WAAY,SAAQ,yBAAe;IAC9C,KAAK,CAAC,QAAQ,CAAC,GAAW;QACxB,OAAO,IAAA,wBAAgB,EAAC,eAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,GAAW,EAAE,MAAmB;QAC5C,OAAO,IAAA,uBAAe,EAAC,OAAO,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF;AARD,kCAQC;AAED,kBAAe,WAAW,CAAC","sourcesContent":["import https from \"https\";\nimport ExtractorPlugin from \"../struct/ExtractorPlugin\";\nimport { URL } from \"url\";\nimport { Song } from \"..\";\nimport type http from \"http\";\nimport type { GuildMember } from \"discord.js\";\n\nexport const getResponseHeaders = async (\n httpModule: typeof http | typeof https,\n url: string,\n): Promise<http.IncomingHttpHeaders> =>\n new Promise((resolve, reject) => {\n httpModule\n .get(url)\n .on(\"response\", res => {\n resolve(res.headers);\n })\n .on(\"error\", reject);\n });\n\nexport const validateAudioURL = async (httpModule: typeof http | typeof https, protocol: string, url: string) => {\n if (new URL(url).protocol.toLowerCase() !== protocol) {\n return false;\n }\n const headers = await getResponseHeaders(httpModule, url),\n type = headers[\"content-type\"];\n if (type?.startsWith(\"audio\")) {\n return true;\n }\n return false;\n};\n\n// eslint-disable-next-line @typescript-eslint/require-await\nexport const resolveHttpSong = async (source: string, url: string, member: GuildMember) => {\n url = url.replace(/\\/+$/, \"\");\n return new Song(\n {\n name: url.substring(url.lastIndexOf(\"/\") + 1).replace(/((\\?|#).*)?$/, \"\") || url,\n url,\n },\n member,\n source,\n );\n};\n\nexport class HTTPSPlugin extends ExtractorPlugin {\n async validate(url: string) {\n return validateAudioURL(https, \"https:\", url);\n }\n\n async resolve(url: string, member: GuildMember) {\n return resolveHttpSong(\"https\", url, member);\n }\n}\n\nexport default HTTPSPlugin;\n"]}
|
|
@@ -31,7 +31,7 @@ class YouTubeDLPlugin extends ExtractorPlugin_1.default {
|
|
|
31
31
|
super();
|
|
32
32
|
if (updateYouTubeDL) {
|
|
33
33
|
/* eslint-disable no-console */
|
|
34
|
-
youtube_dl_1.download()
|
|
34
|
+
(0, youtube_dl_1.download)()
|
|
35
35
|
.then((version) => console.log(`[DisTube] Updated youtube-dl to ${version}!`))
|
|
36
36
|
.catch(console.error)
|
|
37
37
|
.catch(() => console.warn("[DisTube] Unable to update youtube-dl, using default version."));
|
|
@@ -43,7 +43,7 @@ class YouTubeDLPlugin extends ExtractorPlugin_1.default {
|
|
|
43
43
|
return true;
|
|
44
44
|
}
|
|
45
45
|
async resolve(url, member) {
|
|
46
|
-
const info = await youtube_dl_1.default(url, {
|
|
46
|
+
const info = await (0, youtube_dl_1.default)(url, {
|
|
47
47
|
dumpSingleJson: true,
|
|
48
48
|
noWarnings: true,
|
|
49
49
|
noCallHome: true,
|
|
@@ -59,7 +59,7 @@ class YouTubeDLPlugin extends ExtractorPlugin_1.default {
|
|
|
59
59
|
return new struct_1.Song(info, member, info.extractor);
|
|
60
60
|
}
|
|
61
61
|
async getStreamURL(url) {
|
|
62
|
-
const info = await youtube_dl_1.default(url, {
|
|
62
|
+
const info = await (0, youtube_dl_1.default)(url, {
|
|
63
63
|
dumpSingleJson: true,
|
|
64
64
|
noWarnings: true,
|
|
65
65
|
noCallHome: true,
|