distube 4.0.0-dev.0 → 4.0.0-dev.3
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 +1 -1
- package/dist/index.d.ts +593 -8
- package/dist/index.js +2360 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2300 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +79 -43
- package/dist/DisTube.d.ts +0 -521
- package/dist/DisTube.d.ts.map +0 -1
- package/dist/DisTube.js +0 -793
- package/dist/DisTube.js.map +0 -1
- package/dist/constant.d.ts +0 -124
- package/dist/constant.d.ts.map +0 -1
- package/dist/constant.js +0 -144
- package/dist/constant.js.map +0 -1
- package/dist/core/DisTubeBase.d.ts +0 -54
- package/dist/core/DisTubeBase.d.ts.map +0 -1
- package/dist/core/DisTubeBase.js +0 -75
- package/dist/core/DisTubeBase.js.map +0 -1
- package/dist/core/DisTubeHandler.d.ts +0 -93
- package/dist/core/DisTubeHandler.d.ts.map +0 -1
- package/dist/core/DisTubeHandler.js +0 -292
- package/dist/core/DisTubeHandler.js.map +0 -1
- package/dist/core/DisTubeOptions.d.ts +0 -23
- package/dist/core/DisTubeOptions.d.ts.map +0 -1
- package/dist/core/DisTubeOptions.js +0 -90
- package/dist/core/DisTubeOptions.js.map +0 -1
- package/dist/core/DisTubeStream.d.ts +0 -52
- package/dist/core/DisTubeStream.d.ts.map +0 -1
- package/dist/core/DisTubeStream.js +0 -108
- package/dist/core/DisTubeStream.js.map +0 -1
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -19
- package/dist/core/index.js.map +0 -1
- package/dist/core/manager/BaseManager.d.ts +0 -22
- package/dist/core/manager/BaseManager.d.ts.map +0 -1
- package/dist/core/manager/BaseManager.js +0 -42
- package/dist/core/manager/BaseManager.js.map +0 -1
- package/dist/core/manager/QueueManager.d.ts +0 -33
- package/dist/core/manager/QueueManager.d.ts.map +0 -1
- package/dist/core/manager/QueueManager.js +0 -193
- package/dist/core/manager/QueueManager.js.map +0 -1
- package/dist/core/manager/index.d.ts +0 -3
- package/dist/core/manager/index.d.ts.map +0 -1
- package/dist/core/manager/index.js +0 -15
- package/dist/core/manager/index.js.map +0 -1
- package/dist/core/voice/DisTubeVoice.d.ts +0 -82
- package/dist/core/voice/DisTubeVoice.d.ts.map +0 -1
- package/dist/core/voice/DisTubeVoice.js +0 -250
- package/dist/core/voice/DisTubeVoice.js.map +0 -1
- package/dist/core/voice/DisTubeVoiceManager.d.ts +0 -41
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +0 -1
- package/dist/core/voice/DisTubeVoiceManager.js +0 -67
- package/dist/core/voice/DisTubeVoiceManager.js.map +0 -1
- package/dist/core/voice/index.d.ts +0 -3
- package/dist/core/voice/index.d.ts.map +0 -1
- package/dist/core/voice/index.js +0 -15
- package/dist/core/voice/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/plugin/http.d.ts +0 -10
- package/dist/plugin/http.d.ts.map +0 -1
- package/dist/plugin/http.js +0 -18
- package/dist/plugin/http.js.map +0 -1
- package/dist/plugin/https.d.ts +0 -19
- package/dist/plugin/https.d.ts.map +0 -1
- package/dist/plugin/https.js +0 -47
- package/dist/plugin/https.js.map +0 -1
- package/dist/plugin/index.d.ts +0 -3
- package/dist/plugin/index.d.ts.map +0 -1
- package/dist/plugin/index.js +0 -15
- package/dist/plugin/index.js.map +0 -1
- package/dist/struct/CustomPlugin.d.ts +0 -51
- package/dist/struct/CustomPlugin.d.ts.map +0 -1
- package/dist/struct/CustomPlugin.js +0 -50
- package/dist/struct/CustomPlugin.js.map +0 -1
- package/dist/struct/DisTubeError.d.ts +0 -55
- package/dist/struct/DisTubeError.d.ts.map +0 -1
- package/dist/struct/DisTubeError.js +0 -64
- package/dist/struct/DisTubeError.js.map +0 -1
- package/dist/struct/ExtractorPlugin.d.ts +0 -45
- package/dist/struct/ExtractorPlugin.d.ts.map +0 -1
- package/dist/struct/ExtractorPlugin.js +0 -39
- package/dist/struct/ExtractorPlugin.js.map +0 -1
- package/dist/struct/Playlist.d.ts +0 -54
- package/dist/struct/Playlist.d.ts.map +0 -1
- package/dist/struct/Playlist.js +0 -131
- package/dist/struct/Playlist.js.map +0 -1
- package/dist/struct/Plugin.d.ts +0 -75
- package/dist/struct/Plugin.d.ts.map +0 -1
- package/dist/struct/Plugin.js +0 -99
- package/dist/struct/Plugin.js.map +0 -1
- package/dist/struct/Queue.d.ts +0 -216
- package/dist/struct/Queue.d.ts.map +0 -1
- package/dist/struct/Queue.js +0 -479
- package/dist/struct/Queue.js.map +0 -1
- package/dist/struct/SearchResult.d.ts +0 -27
- package/dist/struct/SearchResult.d.ts.map +0 -1
- package/dist/struct/SearchResult.js +0 -77
- package/dist/struct/SearchResult.js.map +0 -1
- package/dist/struct/Song.d.ts +0 -78
- package/dist/struct/Song.d.ts.map +0 -1
- package/dist/struct/Song.js +0 -259
- package/dist/struct/Song.js.map +0 -1
- package/dist/struct/TaskQueue.d.ts +0 -28
- package/dist/struct/TaskQueue.d.ts.map +0 -1
- package/dist/struct/TaskQueue.js +0 -64
- package/dist/struct/TaskQueue.js.map +0 -1
- package/dist/struct/index.d.ts +0 -10
- package/dist/struct/index.d.ts.map +0 -1
- package/dist/struct/index.js +0 -22
- package/dist/struct/index.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/type.d.ts +0 -169
- package/dist/type.d.ts.map +0 -1
- package/dist/type.js +0 -3
- package/dist/type.js.map +0 -1
- package/dist/util.d.ts +0 -51
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -225
- package/dist/util.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeStream.js","sourceRoot":"","sources":["../../src/core/DisTubeStream.ts"],"names":[],"mappings":";;;AAAA,0BAA2B;AAC3B,6CAAqC;AACrC,sCAAyC;AACzC,4CAA8C;AAkBvC,MAAM,qBAAqB,GA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AAI,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACrE,MAAM,IAAI,qBAAY,CAAC,cAAc,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;SACtE;QACD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,IAAA,SAAK,EAAC,GAAG,CAAC,EAAE;YAC1C,MAAM,IAAI,qBAAY,CAAC,cAAc,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;SACvD;QACD,OAAO,IAAI,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;CAqDF;AArFD,sCAqFC","sourcesContent":["import { isURL } from \"..\";\nimport { FFmpeg } from \"prism-media\";\nimport { DisTubeError } from \"../struct\";\nimport { StreamType } from \"@discordjs/voice\";\nimport type ytdl from \"@distube/ytdl-core\";\n\ninterface StreamOptions {\n /**\n * Time to seek in seconds\n */\n seek?: number;\n /**\n * Additional FFmpeg arguments\n */\n ffmpegArgs?: string[];\n /**\n * If the stream url is live\n */\n isLive?: boolean;\n}\n\nexport const chooseBestVideoFormat = (formats: ytdl.videoFormat[], isLive = false) => {\n let filter = (format: ytdl.videoFormat) => format.hasAudio;\n if (isLive) filter = (format: ytdl.videoFormat) => format.hasAudio && format.isHLS;\n formats = formats\n .filter(filter)\n .sort((a, b) => Number(b.audioBitrate) - Number(a.audioBitrate) || Number(a.bitrate) - Number(b.bitrate));\n return formats.find(format => !format.hasVideo) || formats.sort((a, b) => Number(a.bitrate) - Number(b.bitrate))[0];\n};\n\n/**\n * Create a stream to play with {@link DisTubeVoice}\n * @private\n */\nexport class DisTubeStream {\n /**\n * Create a stream from ytdl video formats\n * @param {ytdl.videoFormat[]} formats ytdl video formats\n * @param {StreamOptions} options options\n * @returns {DisTubeStream}\n * @private\n */\n static YouTube(formats: ytdl.videoFormat[] | undefined, options: StreamOptions = {}): DisTubeStream {\n if (!formats || !formats.length) throw new DisTubeError(\"UNAVAILABLE_VIDEO\");\n if (!options || typeof options !== \"object\" || Array.isArray(options)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"object\", options, \"options\");\n }\n const bestFormat = chooseBestVideoFormat(formats, options.isLive);\n if (!bestFormat) throw new DisTubeError(\"UNPLAYABLE_FORMATS\");\n return new DisTubeStream(bestFormat.url, options);\n }\n /**\n * Create a stream from a stream url\n * @param {string} url stream url\n * @param {StreamOptions} options options\n * @returns {DisTubeStream}\n * @private\n */\n static DirectLink(url: string, options: StreamOptions = {}): DisTubeStream {\n if (!options || typeof options !== \"object\" || Array.isArray(options)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"object\", options, \"options\");\n }\n if (typeof url !== \"string\" || !isURL(url)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"an URL\", url);\n }\n return new DisTubeStream(url, options);\n }\n type: StreamType.Raw;\n stream: FFmpeg;\n url: string;\n /**\n * Create a DisTubeStream to play with {@link DisTubeVoice}\n * @param {string} url Stream URL\n * @param {StreamOptions} options Stream options\n * @private\n */\n constructor(url: string, options: StreamOptions) {\n /**\n * Stream URL\n * @type {string}\n */\n this.url = url;\n /**\n * Stream type\n * @type {DiscordVoice.StreamType.Raw}\n */\n this.type = StreamType.Raw;\n const args = [\n \"-reconnect\",\n \"1\",\n \"-reconnect_streamed\",\n \"1\",\n \"-reconnect_delay_max\",\n \"5\",\n \"-i\",\n url,\n \"-analyzeduration\",\n \"0\",\n \"-loglevel\",\n \"0\",\n \"-ar\",\n \"48000\",\n \"-ac\",\n \"2\",\n \"-f\",\n \"s16le\",\n ];\n if (typeof options.seek === \"number\" && options.seek > 0) {\n args.unshift(\"-ss\", options.seek.toString());\n }\n if (Array.isArray(options.ffmpegArgs)) {\n args.push(...options.ffmpegArgs);\n }\n /**\n * FFmpeg stream (Duplex)\n * @type {FFmpeg}\n */\n this.stream = new FFmpeg({ args, shell: false });\n }\n}\n"]}
|
package/dist/core/index.d.ts
DELETED
package/dist/core/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,kBAAkB,CAAC"}
|
package/dist/core/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./DisTubeOptions"), exports);
|
|
14
|
-
__exportStar(require("./DisTubeBase"), exports);
|
|
15
|
-
__exportStar(require("./DisTubeStream"), exports);
|
|
16
|
-
__exportStar(require("./manager"), exports);
|
|
17
|
-
__exportStar(require("./voice"), exports);
|
|
18
|
-
__exportStar(require("./DisTubeHandler"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAiC;AACjC,gDAA8B;AAC9B,kDAAgC;AAChC,4CAA0B;AAC1B,0CAAwB;AACxB,mDAAiC","sourcesContent":["export * from \"./DisTubeOptions\";\nexport * from \"./DisTubeBase\";\nexport * from \"./DisTubeStream\";\nexport * from \"./manager\";\nexport * from \"./voice\";\nexport * from \"./DisTubeHandler\";\n"]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DisTubeBase } from "..";
|
|
2
|
-
import { Collection } from "discord.js";
|
|
3
|
-
import type { GuildIdResolvable } from "../..";
|
|
4
|
-
/**
|
|
5
|
-
* Manages the collection of a data model.
|
|
6
|
-
* @abstract
|
|
7
|
-
* @private
|
|
8
|
-
* @extends DisTubeBase
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class BaseManager<V> extends DisTubeBase {
|
|
11
|
-
/**
|
|
12
|
-
* The collection of items for this manager.
|
|
13
|
-
* @type {Discord.Collection}
|
|
14
|
-
* @abstract
|
|
15
|
-
*/
|
|
16
|
-
collection: Collection<string, V>;
|
|
17
|
-
add(id: string, data: V): V;
|
|
18
|
-
get(idOrInstance: GuildIdResolvable): V | undefined;
|
|
19
|
-
delete(idOrInstance: GuildIdResolvable): void;
|
|
20
|
-
has(idOrInstance: GuildIdResolvable): boolean;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=BaseManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseManager.d.ts","sourceRoot":"","sources":["../../../src/core/manager/BaseManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE/C;;;;;GAKG;AACH,8BAAsB,WAAW,CAAC,CAAC,CAAE,SAAQ,WAAW;IACtD;;;;OAIG;IACH,UAAU,wBAA+B;IACzC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;IAQvB,GAAG,CAAC,YAAY,EAAE,iBAAiB,GAAG,CAAC,GAAG,SAAS;IAGnD,MAAM,CAAC,YAAY,EAAE,iBAAiB,GAAG,IAAI;IAG7C,GAAG,CAAC,YAAY,EAAE,iBAAiB,GAAG,OAAO;CAG9C"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseManager = void 0;
|
|
4
|
-
const __1 = require("..");
|
|
5
|
-
const __2 = require("../..");
|
|
6
|
-
const discord_js_1 = require("discord.js");
|
|
7
|
-
/**
|
|
8
|
-
* Manages the collection of a data model.
|
|
9
|
-
* @abstract
|
|
10
|
-
* @private
|
|
11
|
-
* @extends DisTubeBase
|
|
12
|
-
*/
|
|
13
|
-
class BaseManager extends __1.DisTubeBase {
|
|
14
|
-
constructor() {
|
|
15
|
-
super(...arguments);
|
|
16
|
-
/**
|
|
17
|
-
* The collection of items for this manager.
|
|
18
|
-
* @type {Discord.Collection}
|
|
19
|
-
* @abstract
|
|
20
|
-
*/
|
|
21
|
-
this.collection = new discord_js_1.Collection();
|
|
22
|
-
}
|
|
23
|
-
add(id, data) {
|
|
24
|
-
const existing = this.get(id);
|
|
25
|
-
if (existing) {
|
|
26
|
-
return existing;
|
|
27
|
-
}
|
|
28
|
-
this.collection.set(id, data);
|
|
29
|
-
return data;
|
|
30
|
-
}
|
|
31
|
-
get(idOrInstance) {
|
|
32
|
-
return this.collection.get((0, __2.resolveGuildId)(idOrInstance));
|
|
33
|
-
}
|
|
34
|
-
delete(idOrInstance) {
|
|
35
|
-
this.collection.delete((0, __2.resolveGuildId)(idOrInstance));
|
|
36
|
-
}
|
|
37
|
-
has(idOrInstance) {
|
|
38
|
-
return this.collection.has((0, __2.resolveGuildId)(idOrInstance));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.BaseManager = BaseManager;
|
|
42
|
-
//# sourceMappingURL=BaseManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"BaseManager.js","sourceRoot":"","sources":["../../../src/core/manager/BaseManager.ts"],"names":[],"mappings":";;;AAAA,0BAAiC;AACjC,6BAAuC;AACvC,2CAAwC;AAGxC;;;;;GAKG;AACH,MAAsB,WAAe,SAAQ,eAAW;IAAxD;;QACE;;;;WAIG;QACH,eAAU,GAAG,IAAI,uBAAU,EAAa,CAAC;IAkB3C,CAAC;IAjBC,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;AAxBD,kCAwBC","sourcesContent":["import { DisTubeBase } from \"..\";\nimport { resolveGuildId } from \"../..\";\nimport { Collection } from \"discord.js\";\nimport type { GuildIdResolvable } from \"../..\";\n\n/**\n * Manages the collection of a data model.\n * @abstract\n * @private\n * @extends DisTubeBase\n */\nexport abstract class BaseManager<V> extends DisTubeBase {\n /**\n * The collection of items for this manager.\n * @type {Discord.Collection}\n * @abstract\n */\n collection = new Collection<string, V>();\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"]}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { BaseManager } from ".";
|
|
2
|
-
import { Queue } from "../..";
|
|
3
|
-
import type { Song } from "../..";
|
|
4
|
-
import type { GuildTextBasedChannel, VoiceBasedChannel } from "discord.js";
|
|
5
|
-
/**
|
|
6
|
-
* Queue manager
|
|
7
|
-
* @extends BaseManager
|
|
8
|
-
*/
|
|
9
|
-
export declare class QueueManager extends BaseManager<Queue> {
|
|
10
|
-
#private;
|
|
11
|
-
/**
|
|
12
|
-
* Collection of {@link Queue}.
|
|
13
|
-
* @name QueueManager#collection
|
|
14
|
-
* @type {Discord.Collection<string, Queue>}
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* Create a {@link Queue}
|
|
18
|
-
* @private
|
|
19
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel
|
|
20
|
-
* @param {Song|Song[]} song First song
|
|
21
|
-
* @param {Discord.BaseGuildTextChannel} textChannel Default text channel
|
|
22
|
-
* @returns {Promise<Queue|true>} Returns `true` if encounter an error
|
|
23
|
-
*/
|
|
24
|
-
create(channel: VoiceBasedChannel, song: Song[] | Song, textChannel?: GuildTextBasedChannel): Promise<Queue | true>;
|
|
25
|
-
/**
|
|
26
|
-
* Play a song on voice connection
|
|
27
|
-
* @private
|
|
28
|
-
* @param {Queue} queue The guild queue
|
|
29
|
-
* @returns {Promise<boolean>} error?
|
|
30
|
-
*/
|
|
31
|
-
playSong(queue: Queue): Promise<boolean>;
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=QueueManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE3E;;;GAGG;AACH,qBAAa,YAAa,SAAQ,WAAW,CAAC,KAAK,CAAC;;IAClD;;;;OAIG;IACH;;;;;;;OAOG;IACG,MAAM,CACV,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EACnB,WAAW,CAAC,EAAE,qBAAqB,GAClC,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IA+GxB;;;;;OAKG;IACG,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;CA8C/C"}
|
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _QueueManager_instances, _QueueManager_voiceEventHandler, _QueueManager_handleSongFinish, _QueueManager_handlePlayingError, _QueueManager_emitPlaySong;
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.QueueManager = void 0;
|
|
10
|
-
const _1 = require(".");
|
|
11
|
-
const __1 = require("../..");
|
|
12
|
-
/**
|
|
13
|
-
* Queue manager
|
|
14
|
-
* @extends BaseManager
|
|
15
|
-
*/
|
|
16
|
-
class QueueManager extends _1.BaseManager {
|
|
17
|
-
constructor() {
|
|
18
|
-
super(...arguments);
|
|
19
|
-
_QueueManager_instances.add(this);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Collection of {@link Queue}.
|
|
23
|
-
* @name QueueManager#collection
|
|
24
|
-
* @type {Discord.Collection<string, Queue>}
|
|
25
|
-
*/
|
|
26
|
-
/**
|
|
27
|
-
* Create a {@link Queue}
|
|
28
|
-
* @private
|
|
29
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel
|
|
30
|
-
* @param {Song|Song[]} song First song
|
|
31
|
-
* @param {Discord.BaseGuildTextChannel} textChannel Default text channel
|
|
32
|
-
* @returns {Promise<Queue|true>} Returns `true` if encounter an error
|
|
33
|
-
*/
|
|
34
|
-
async create(channel, song, textChannel) {
|
|
35
|
-
if (this.has(channel.guild.id))
|
|
36
|
-
throw new __1.DisTubeError("QUEUE_EXIST");
|
|
37
|
-
const voice = this.voices.create(channel);
|
|
38
|
-
const queue = new __1.Queue(this.distube, voice, song, textChannel);
|
|
39
|
-
await queue.taskQueue.queuing();
|
|
40
|
-
try {
|
|
41
|
-
await voice.join();
|
|
42
|
-
__classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_voiceEventHandler).call(this, queue);
|
|
43
|
-
this.add(queue.id, queue);
|
|
44
|
-
this.emit("initQueue", queue);
|
|
45
|
-
const err = await this.playSong(queue);
|
|
46
|
-
return err || queue;
|
|
47
|
-
}
|
|
48
|
-
finally {
|
|
49
|
-
queue.taskQueue.resolve();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Play a song on voice connection
|
|
54
|
-
* @private
|
|
55
|
-
* @param {Queue} queue The guild queue
|
|
56
|
-
* @returns {Promise<boolean>} error?
|
|
57
|
-
*/
|
|
58
|
-
async playSong(queue) {
|
|
59
|
-
if (!queue)
|
|
60
|
-
return true;
|
|
61
|
-
if (!queue.songs.length) {
|
|
62
|
-
queue.stop();
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
if (queue.stopped)
|
|
66
|
-
return false;
|
|
67
|
-
const song = queue.songs[0];
|
|
68
|
-
try {
|
|
69
|
-
const { url, source, formats, streamURL } = song;
|
|
70
|
-
if (source === "youtube" && !formats)
|
|
71
|
-
song._patchYouTube(await this.handler.getYouTubeInfo(url));
|
|
72
|
-
if (source !== "youtube" && !streamURL) {
|
|
73
|
-
for (const plugin of [...this.distube.extractorPlugins, ...this.distube.customPlugins]) {
|
|
74
|
-
if (await plugin.validate(url)) {
|
|
75
|
-
const info = [plugin.getStreamURL(url), plugin.getRelatedSongs(url)];
|
|
76
|
-
const result = await Promise.all(info);
|
|
77
|
-
song.streamURL = result[0];
|
|
78
|
-
song.related = result[1];
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const stream = this.handler.createStream(queue);
|
|
84
|
-
queue.voice.play(stream);
|
|
85
|
-
song.streamURL = stream.url;
|
|
86
|
-
if (queue.stopped)
|
|
87
|
-
queue.stop();
|
|
88
|
-
else if (queue.paused)
|
|
89
|
-
queue.voice.pause();
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
__classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_handlePlayingError).call(this, queue, e);
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
exports.QueueManager = QueueManager;
|
|
99
|
-
_QueueManager_instances = new WeakSet(), _QueueManager_voiceEventHandler = function _QueueManager_voiceEventHandler(queue) {
|
|
100
|
-
queue.listeners = {
|
|
101
|
-
disconnect: error => {
|
|
102
|
-
queue.delete();
|
|
103
|
-
this.emit("disconnect", queue);
|
|
104
|
-
if (error)
|
|
105
|
-
this.emitError(error, queue.textChannel);
|
|
106
|
-
},
|
|
107
|
-
error: error => __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_handlePlayingError).call(this, queue, error),
|
|
108
|
-
finish: () => __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_handleSongFinish).call(this, queue),
|
|
109
|
-
};
|
|
110
|
-
for (const event of Object.keys(queue.listeners)) {
|
|
111
|
-
queue.voice.on(event, queue.listeners[event]);
|
|
112
|
-
}
|
|
113
|
-
}, _QueueManager_handleSongFinish =
|
|
114
|
-
/**
|
|
115
|
-
* Handle the queue when a Song finish
|
|
116
|
-
* @private
|
|
117
|
-
* @param {Queue} queue queue
|
|
118
|
-
* @returns {Promise<void>}
|
|
119
|
-
*/
|
|
120
|
-
async function _QueueManager_handleSongFinish(queue) {
|
|
121
|
-
this.emit("finishSong", queue, queue.songs[0]);
|
|
122
|
-
await queue.taskQueue.queuing();
|
|
123
|
-
try {
|
|
124
|
-
if (queue.stopped)
|
|
125
|
-
return;
|
|
126
|
-
if (queue.repeatMode === __1.RepeatMode.QUEUE && !queue.prev)
|
|
127
|
-
queue.songs.push(queue.songs[0]);
|
|
128
|
-
if (queue.prev) {
|
|
129
|
-
if (queue.repeatMode === __1.RepeatMode.QUEUE)
|
|
130
|
-
queue.songs.unshift(queue.songs.pop());
|
|
131
|
-
else
|
|
132
|
-
queue.songs.unshift(queue.previousSongs.pop());
|
|
133
|
-
}
|
|
134
|
-
if (queue.songs.length <= 1 && (queue.next || queue.repeatMode === __1.RepeatMode.DISABLED)) {
|
|
135
|
-
if (queue.autoplay) {
|
|
136
|
-
try {
|
|
137
|
-
await queue.addRelatedSong();
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
this.emit("noRelated", queue);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (queue.songs.length <= 1) {
|
|
144
|
-
if (this.options.leaveOnFinish)
|
|
145
|
-
queue.voice.leave();
|
|
146
|
-
if (!queue.autoplay)
|
|
147
|
-
this.emit("finish", queue);
|
|
148
|
-
queue.delete();
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
const emitPlaySong = __classPrivateFieldGet(this, _QueueManager_instances, "m", _QueueManager_emitPlaySong).call(this, queue);
|
|
153
|
-
if (!queue.prev && (queue.repeatMode !== __1.RepeatMode.SONG || queue.next)) {
|
|
154
|
-
const prev = queue.songs.shift();
|
|
155
|
-
delete prev.formats;
|
|
156
|
-
delete prev.streamURL;
|
|
157
|
-
if (this.options.savePreviousSongs)
|
|
158
|
-
queue.previousSongs.push(prev);
|
|
159
|
-
else
|
|
160
|
-
queue.previousSongs.push({ id: prev.id });
|
|
161
|
-
}
|
|
162
|
-
queue.next = queue.prev = false;
|
|
163
|
-
queue.beginTime = 0;
|
|
164
|
-
const err = await this.playSong(queue);
|
|
165
|
-
if (!err && emitPlaySong)
|
|
166
|
-
this.emit("playSong", queue, queue.songs[0]);
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
queue.taskQueue.resolve();
|
|
170
|
-
}
|
|
171
|
-
}, _QueueManager_handlePlayingError = function _QueueManager_handlePlayingError(queue, error) {
|
|
172
|
-
const song = queue.songs.shift();
|
|
173
|
-
try {
|
|
174
|
-
error.name = "PlayingError";
|
|
175
|
-
error.message = `${error.message}\nId: ${song.id}\nName: ${song.name}`;
|
|
176
|
-
}
|
|
177
|
-
catch { }
|
|
178
|
-
this.emitError(error, queue.textChannel);
|
|
179
|
-
if (queue.songs.length > 0) {
|
|
180
|
-
this.playSong(queue).then(e => {
|
|
181
|
-
if (!e)
|
|
182
|
-
this.emit("playSong", queue, queue.songs[0]);
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
queue.stop();
|
|
187
|
-
}
|
|
188
|
-
}, _QueueManager_emitPlaySong = function _QueueManager_emitPlaySong(queue) {
|
|
189
|
-
return (!this.options.emitNewSongOnly ||
|
|
190
|
-
(queue.repeatMode === __1.RepeatMode.SONG && queue.next) ||
|
|
191
|
-
(queue.repeatMode !== __1.RepeatMode.SONG && queue.songs[0]?.id !== queue.songs[1]?.id));
|
|
192
|
-
};
|
|
193
|
-
//# sourceMappingURL=QueueManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueueManager.js","sourceRoot":"","sources":["../../../src/core/manager/QueueManager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,wBAAgC;AAChC,6BAAwD;AAIxD;;;GAGG;AACH,MAAa,YAAa,SAAQ,cAAkB;IAApD;;;IAqLA,CAAC;IApLC;;;;OAIG;IACH;;;;;;;OAOG;IACH,KAAK,CAAC,MAAM,CACV,OAA0B,EAC1B,IAAmB,EACnB,WAAmC;QAEnC,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,uBAAA,IAAI,gEAAmB,MAAvB,IAAI,EAAoB,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;SAC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OAAO,SAAS,IAAI,CAAC,EAAE,WAAW,IAAI,CAAC,IAAI,EAAE,CAAC;KACxE;IAAC,MAAM,GAAE;IACV,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IACzC,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC1B,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;YAC5B,IAAI,CAAC,CAAC;gBAAE,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;KACJ;SAAM;QACL,KAAK,CAAC,IAAI,EAAE,CAAC;KACd;AACH,CAAC,mEA+Ca,KAAY;IACxB,OAAO,CACL,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe;QAC7B,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC;QACpD,CAAC,KAAK,CAAC,UAAU,KAAK,cAAU,CAAC,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CACpF,CAAC;AACJ,CAAC","sourcesContent":["import { BaseManager } from \".\";\nimport { DisTubeError, Queue, RepeatMode } from \"../..\";\nimport type { DisTubeVoiceEvents, Song } from \"../..\";\nimport type { GuildTextBasedChannel, VoiceBasedChannel } from \"discord.js\";\n\n/**\n * Queue manager\n * @extends BaseManager\n */\nexport class QueueManager extends BaseManager<Queue> {\n /**\n * Collection of {@link Queue}.\n * @name QueueManager#collection\n * @type {Discord.Collection<string, Queue>}\n */\n /**\n * Create a {@link Queue}\n * @private\n * @param {Discord.BaseGuildVoiceChannel} channel A voice channel\n * @param {Song|Song[]} song First song\n * @param {Discord.BaseGuildTextChannel} textChannel Default text channel\n * @returns {Promise<Queue|true>} Returns `true` if encounter an error\n */\n async create(\n channel: VoiceBasedChannel,\n song: Song[] | Song,\n textChannel?: GuildTextBasedChannel,\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 #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 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 #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 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 = 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 if (queue.stopped) queue.stop();\n else if (queue.paused) queue.voice.pause();\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 #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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./BaseManager"), exports);
|
|
14
|
-
__exportStar(require("./QueueManager"), exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/manager/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,gDAA8B;AAC9B,iDAA+B","sourcesContent":["export * from \"./BaseManager\";\nexport * from \"./QueueManager\";\n"]}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { TypedEmitter } from "tiny-typed-emitter";
|
|
2
|
-
import type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from "../..";
|
|
3
|
-
import type { AudioPlayer, AudioResource, VoiceConnection } from "@discordjs/voice";
|
|
4
|
-
import type { Snowflake, VoiceBasedChannel, VoiceState } from "discord.js";
|
|
5
|
-
/**
|
|
6
|
-
* Create a voice connection to the voice channel
|
|
7
|
-
*/
|
|
8
|
-
export declare class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
|
|
9
|
-
#private;
|
|
10
|
-
readonly id: Snowflake;
|
|
11
|
-
readonly voices: DisTubeVoiceManager;
|
|
12
|
-
readonly audioPlayer: AudioPlayer;
|
|
13
|
-
connection: VoiceConnection;
|
|
14
|
-
audioResource?: AudioResource;
|
|
15
|
-
emittedError: boolean;
|
|
16
|
-
isDisconnected: boolean;
|
|
17
|
-
constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel);
|
|
18
|
-
get channel(): VoiceBasedChannel;
|
|
19
|
-
set channel(channel: VoiceBasedChannel);
|
|
20
|
-
/**
|
|
21
|
-
* Join a voice channel with this connection
|
|
22
|
-
* @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel
|
|
23
|
-
* @private
|
|
24
|
-
* @returns {Promise<DisTubeVoice>}
|
|
25
|
-
*/
|
|
26
|
-
join(channel?: VoiceBasedChannel): Promise<DisTubeVoice>;
|
|
27
|
-
/**
|
|
28
|
-
* Leave the voice channel of this connection
|
|
29
|
-
* @param {Error} [error] Optional, an error to emit with 'error' event.
|
|
30
|
-
*/
|
|
31
|
-
leave(error?: Error): void;
|
|
32
|
-
/**
|
|
33
|
-
* Stop the playing stream
|
|
34
|
-
* @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
|
|
35
|
-
* even if the {@link DisTubeVoice#audioResource} has silence padding frames.
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
stop(force?: boolean): void;
|
|
39
|
-
/**
|
|
40
|
-
* Play a readable stream
|
|
41
|
-
* @private
|
|
42
|
-
* @param {DisTubeStream} stream Readable stream
|
|
43
|
-
*/
|
|
44
|
-
play(stream: DisTubeStream): void;
|
|
45
|
-
set volume(volume: number);
|
|
46
|
-
get volume(): number;
|
|
47
|
-
/**
|
|
48
|
-
* Playback duration of the audio resource in seconds
|
|
49
|
-
* @type {number}
|
|
50
|
-
*/
|
|
51
|
-
get playbackDuration(): number;
|
|
52
|
-
pause(): void;
|
|
53
|
-
unpause(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Whether the bot is self-deafened
|
|
56
|
-
* @type {boolean}
|
|
57
|
-
*/
|
|
58
|
-
get selfDeaf(): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Whether the bot is self-muted
|
|
61
|
-
* @type {boolean}
|
|
62
|
-
*/
|
|
63
|
-
get selfMute(): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Self-deafens/undeafens the bot.
|
|
66
|
-
* @param {boolean} selfDeaf Whether or not the bot should be self-deafened
|
|
67
|
-
* @returns {boolean} true if the voice state was successfully updated, otherwise false
|
|
68
|
-
*/
|
|
69
|
-
setSelfDeaf(selfDeaf: boolean): boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Self-mutes/unmutes the bot.
|
|
72
|
-
* @param {boolean} selfMute Whether or not the bot should be self-muted
|
|
73
|
-
* @returns {boolean} true if the voice state was successfully updated, otherwise false
|
|
74
|
-
*/
|
|
75
|
-
setSelfMute(selfMute: boolean): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* The voice state of this connection
|
|
78
|
-
* @type {Discord.VoiceState?}
|
|
79
|
-
*/
|
|
80
|
-
get voiceState(): VoiceState | undefined;
|
|
81
|
-
}
|
|
82
|
-
//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