distube 4.0.0-dev.1 → 4.0.0-dev.2
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/dist/DisTube.d.ts +13 -480
- package/dist/DisTube.d.ts.map +1 -1
- package/dist/DisTube.js +30 -544
- package/dist/DisTube.js.map +1 -1
- package/dist/constant.d.ts +0 -97
- package/dist/constant.d.ts.map +1 -1
- package/dist/constant.js +0 -97
- package/dist/constant.js.map +1 -1
- package/dist/core/DisTubeBase.d.ts +0 -40
- package/dist/core/DisTubeBase.d.ts.map +1 -1
- package/dist/core/DisTubeBase.js +0 -44
- package/dist/core/DisTubeBase.js.map +1 -1
- package/dist/core/DisTubeHandler.d.ts +2 -68
- package/dist/core/DisTubeHandler.d.ts.map +1 -1
- package/dist/core/DisTubeHandler.js +6 -68
- package/dist/core/DisTubeHandler.js.map +1 -1
- package/dist/core/DisTubeStream.d.ts +0 -33
- package/dist/core/DisTubeStream.d.ts.map +1 -1
- package/dist/core/DisTubeStream.js +0 -36
- package/dist/core/DisTubeStream.js.map +1 -1
- package/dist/core/manager/BaseManager.d.ts +1 -16
- package/dist/core/manager/BaseManager.d.ts.map +1 -1
- package/dist/core/manager/BaseManager.js +2 -28
- package/dist/core/manager/BaseManager.js.map +1 -1
- package/dist/core/manager/FilterManager.d.ts +16 -0
- package/dist/core/manager/FilterManager.d.ts.map +1 -0
- package/dist/core/manager/FilterManager.js +88 -0
- package/dist/core/manager/FilterManager.js.map +1 -0
- package/dist/core/manager/GuildIdManager.d.ts +9 -0
- package/dist/core/manager/GuildIdManager.d.ts.map +1 -0
- package/dist/core/manager/GuildIdManager.js +25 -0
- package/dist/core/manager/GuildIdManager.js.map +1 -0
- package/dist/core/manager/QueueManager.d.ts +4 -26
- package/dist/core/manager/QueueManager.d.ts.map +1 -1
- package/dist/core/manager/QueueManager.js +27 -48
- package/dist/core/manager/QueueManager.js.map +1 -1
- package/dist/core/manager/index.d.ts +2 -0
- package/dist/core/manager/index.d.ts.map +1 -1
- package/dist/core/manager/index.js +2 -0
- package/dist/core/manager/index.js.map +1 -1
- package/dist/core/voice/DisTubeVoice.d.ts +0 -50
- package/dist/core/voice/DisTubeVoice.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoice.js +8 -68
- package/dist/core/voice/DisTubeVoice.js.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.d.ts +2 -33
- package/dist/core/voice/DisTubeVoiceManager.d.ts.map +1 -1
- package/dist/core/voice/DisTubeVoiceManager.js +1 -32
- package/dist/core/voice/DisTubeVoiceManager.js.map +1 -1
- package/dist/struct/CustomPlugin.d.ts +0 -41
- package/dist/struct/CustomPlugin.d.ts.map +1 -1
- package/dist/struct/CustomPlugin.js +0 -34
- package/dist/struct/CustomPlugin.js.map +1 -1
- package/dist/struct/ExtractorPlugin.d.ts +0 -32
- package/dist/struct/ExtractorPlugin.d.ts.map +1 -1
- package/dist/struct/ExtractorPlugin.js +0 -23
- package/dist/struct/ExtractorPlugin.js.map +1 -1
- package/dist/struct/Playlist.d.ts +0 -29
- package/dist/struct/Playlist.d.ts.map +1 -1
- package/dist/struct/Playlist.js +0 -54
- package/dist/struct/Playlist.js.map +1 -1
- package/dist/struct/Plugin.d.ts +0 -58
- package/dist/struct/Plugin.d.ts.map +1 -1
- package/dist/struct/Plugin.js +0 -62
- package/dist/struct/Plugin.js.map +1 -1
- package/dist/struct/Queue.d.ts +10 -177
- package/dist/struct/Queue.d.ts.map +1 -1
- package/dist/struct/Queue.js +49 -256
- package/dist/struct/Queue.js.map +1 -1
- package/dist/struct/SearchResult.d.ts +0 -8
- package/dist/struct/SearchResult.d.ts.map +1 -1
- package/dist/struct/SearchResult.js +0 -47
- package/dist/struct/SearchResult.js.map +1 -1
- package/dist/struct/Song.d.ts +0 -35
- package/dist/struct/Song.d.ts.map +1 -1
- package/dist/struct/Song.js +0 -121
- package/dist/struct/Song.js.map +1 -1
- package/dist/struct/TaskQueue.d.ts +0 -20
- package/dist/struct/TaskQueue.d.ts.map +1 -1
- package/dist/struct/TaskQueue.js +0 -25
- package/dist/struct/TaskQueue.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/type.d.ts +6 -71
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js.map +1 -1
- package/dist/util.d.ts +0 -29
- package/dist/util.d.ts.map +1 -1
- package/dist/util.js +2 -38
- package/dist/util.js.map +1 -1
- package/package.json +13 -4
|
@@ -16,9 +16,6 @@ exports.DisTubeVoice = void 0;
|
|
|
16
16
|
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
|
|
17
17
|
const __1 = require("../..");
|
|
18
18
|
const voice_1 = require("@discordjs/voice");
|
|
19
|
-
/**
|
|
20
|
-
* Create a voice connection to the voice channel
|
|
21
|
-
*/
|
|
22
19
|
class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
23
20
|
constructor(voiceManager, channel) {
|
|
24
21
|
super();
|
|
@@ -37,10 +34,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
37
34
|
}
|
|
38
35
|
this.id = channel.guild.id;
|
|
39
36
|
this.channel = channel;
|
|
40
|
-
/**
|
|
41
|
-
* The voice manager that instantiated this connection
|
|
42
|
-
* @type {DisTubeVoiceManager}
|
|
43
|
-
*/
|
|
44
37
|
this.voices = voiceManager;
|
|
45
38
|
this.voices.add(this.id, this);
|
|
46
39
|
this.audioPlayer = (0, voice_1.createAudioPlayer)()
|
|
@@ -73,16 +66,9 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
73
66
|
}
|
|
74
67
|
})
|
|
75
68
|
.on(voice_1.VoiceConnectionStatus.Destroyed, () => {
|
|
76
|
-
this.leave();
|
|
77
|
-
})
|
|
78
|
-
// eslint-disable-next-line no-console
|
|
79
|
-
.on("error", console.warn);
|
|
69
|
+
this.leave(new __1.DisTubeError("VOICE_RECONNECT_FAILED"));
|
|
70
|
+
});
|
|
80
71
|
this.connection.subscribe(this.audioPlayer);
|
|
81
|
-
/**
|
|
82
|
-
* Get or set the volume percentage
|
|
83
|
-
* @name DisTubeVoice#volume
|
|
84
|
-
* @type {number}
|
|
85
|
-
*/
|
|
86
72
|
}
|
|
87
73
|
get channel() {
|
|
88
74
|
return __classPrivateFieldGet(this, _DisTubeVoice_channel, "f");
|
|
@@ -94,14 +80,9 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
94
80
|
if (channel.guild.id !== this.id)
|
|
95
81
|
throw new __1.DisTubeError("VOICE_CHANGE_GUILD");
|
|
96
82
|
this.connection = __classPrivateFieldGet(this, _DisTubeVoice_instances, "m", _DisTubeVoice_join).call(this, channel);
|
|
83
|
+
this.audioResource?.encoder?.setBitrate(channel.bitrate);
|
|
97
84
|
__classPrivateFieldSet(this, _DisTubeVoice_channel, channel, "f");
|
|
98
85
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Join a voice channel with this connection
|
|
101
|
-
* @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel
|
|
102
|
-
* @private
|
|
103
|
-
* @returns {Promise<DisTubeVoice>}
|
|
104
|
-
*/
|
|
105
86
|
async join(channel) {
|
|
106
87
|
const TIMEOUT = 30e3;
|
|
107
88
|
if (channel) {
|
|
@@ -114,15 +95,11 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
114
95
|
if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed) {
|
|
115
96
|
this.connection.destroy();
|
|
116
97
|
}
|
|
117
|
-
this.voices.
|
|
98
|
+
this.voices.remove(this.id);
|
|
118
99
|
throw new __1.DisTubeError("VOICE_CONNECT_FAILED", TIMEOUT / 1e3);
|
|
119
100
|
}
|
|
120
101
|
return this;
|
|
121
102
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Leave the voice channel of this connection
|
|
124
|
-
* @param {Error} [error] Optional, an error to emit with 'error' event.
|
|
125
|
-
*/
|
|
126
103
|
leave(error) {
|
|
127
104
|
this.stop(true);
|
|
128
105
|
if (!this.isDisconnected) {
|
|
@@ -131,22 +108,11 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
131
108
|
}
|
|
132
109
|
if (this.connection.state.status !== voice_1.VoiceConnectionStatus.Destroyed)
|
|
133
110
|
this.connection.destroy();
|
|
134
|
-
this.voices.
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Stop the playing stream
|
|
138
|
-
* @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state
|
|
139
|
-
* even if the {@link DisTubeVoice#audioResource} has silence padding frames.
|
|
140
|
-
* @private
|
|
141
|
-
*/
|
|
111
|
+
this.voices.remove(this.id);
|
|
112
|
+
}
|
|
142
113
|
stop(force = false) {
|
|
143
114
|
this.audioPlayer.stop(force);
|
|
144
115
|
}
|
|
145
|
-
/**
|
|
146
|
-
* Play a readable stream
|
|
147
|
-
* @private
|
|
148
|
-
* @param {DisTubeStream} stream Readable stream
|
|
149
|
-
*/
|
|
150
116
|
play(stream) {
|
|
151
117
|
this.emittedError = false;
|
|
152
118
|
stream.stream.on("error", (error) => {
|
|
@@ -159,8 +125,8 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
159
125
|
inputType: stream.type,
|
|
160
126
|
inlineVolume: true,
|
|
161
127
|
});
|
|
162
|
-
|
|
163
|
-
this.
|
|
128
|
+
this.volume = __classPrivateFieldGet(this, _DisTubeVoice_volume, "f");
|
|
129
|
+
this.audioResource.encoder?.setBitrate(this.channel.bitrate);
|
|
164
130
|
this.audioPlayer.play(this.audioResource);
|
|
165
131
|
}
|
|
166
132
|
set volume(volume) {
|
|
@@ -176,10 +142,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
176
142
|
get volume() {
|
|
177
143
|
return __classPrivateFieldGet(this, _DisTubeVoice_volume, "f");
|
|
178
144
|
}
|
|
179
|
-
/**
|
|
180
|
-
* Playback duration of the audio resource in seconds
|
|
181
|
-
* @type {number}
|
|
182
|
-
*/
|
|
183
145
|
get playbackDuration() {
|
|
184
146
|
return (this.audioResource?.playbackDuration ?? 0) / 1000;
|
|
185
147
|
}
|
|
@@ -189,25 +151,12 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
189
151
|
unpause() {
|
|
190
152
|
this.audioPlayer.unpause();
|
|
191
153
|
}
|
|
192
|
-
/**
|
|
193
|
-
* Whether the bot is self-deafened
|
|
194
|
-
* @type {boolean}
|
|
195
|
-
*/
|
|
196
154
|
get selfDeaf() {
|
|
197
155
|
return this.connection.joinConfig.selfDeaf;
|
|
198
156
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Whether the bot is self-muted
|
|
201
|
-
* @type {boolean}
|
|
202
|
-
*/
|
|
203
157
|
get selfMute() {
|
|
204
158
|
return this.connection.joinConfig.selfMute;
|
|
205
159
|
}
|
|
206
|
-
/**
|
|
207
|
-
* Self-deafens/undeafens the bot.
|
|
208
|
-
* @param {boolean} selfDeaf Whether or not the bot should be self-deafened
|
|
209
|
-
* @returns {boolean} true if the voice state was successfully updated, otherwise false
|
|
210
|
-
*/
|
|
211
160
|
setSelfDeaf(selfDeaf) {
|
|
212
161
|
if (typeof selfDeaf !== "boolean") {
|
|
213
162
|
throw new __1.DisTubeError("INVALID_TYPE", "boolean", selfDeaf, "selfDeaf");
|
|
@@ -217,11 +166,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
217
166
|
selfDeaf,
|
|
218
167
|
});
|
|
219
168
|
}
|
|
220
|
-
/**
|
|
221
|
-
* Self-mutes/unmutes the bot.
|
|
222
|
-
* @param {boolean} selfMute Whether or not the bot should be self-muted
|
|
223
|
-
* @returns {boolean} true if the voice state was successfully updated, otherwise false
|
|
224
|
-
*/
|
|
225
169
|
setSelfMute(selfMute) {
|
|
226
170
|
if (typeof selfMute !== "boolean") {
|
|
227
171
|
throw new __1.DisTubeError("INVALID_TYPE", "boolean", selfMute, "selfMute");
|
|
@@ -231,10 +175,6 @@ class DisTubeVoice extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
231
175
|
selfMute,
|
|
232
176
|
});
|
|
233
177
|
}
|
|
234
|
-
/**
|
|
235
|
-
* The voice state of this connection
|
|
236
|
-
* @type {Discord.VoiceState?}
|
|
237
|
-
*/
|
|
238
178
|
get voiceState() {
|
|
239
179
|
return this.channel?.guild?.me?.voice;
|
|
240
180
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAkD;AAClD,6BAA2E;AAC3E,4CAO0B;AAK1B;;GAEG;AACH,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAA0B;QACvE,KAAK,EAAE,CAAC;;QAJV,mBAAc,GAAG,KAAK,CAAC;QACvB,wCAA6B;QAC7B,+BAAU,GAAG,EAAC;QAGZ,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC,EAAE;YACrC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,uBAAuB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;SACrF;QACD,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;QACvB;;;WAGG;QACH,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC;QAC3B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,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isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, VoiceBasedChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n readonly id: Snowflake;\n readonly voices: DisTubeVoiceManager;\n readonly audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected = false;\n #channel!: VoiceBasedChannel;\n #volume = 100;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"channel\");\n }\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.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: VoiceBasedChannel) {\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"DisTubeVoice#channel\");\n }\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 #join(channel: VoiceBasedChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: channel.guild.voiceAdapterCreator as any,\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel\n * @private\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceBasedChannel): 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(true);\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 * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state\n * even if the {@link DisTubeVoice#audioResource} has silence padding frames.\n * @private\n */\n stop(force = false) {\n this.audioPlayer.stop(force);\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;\n this.audioResource?.volume?.setVolume(Math.pow(this.#volume / 100, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this.#volume;\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"]}
|
|
1
|
+
{"version":3,"file":"DisTubeVoice.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoice.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2DAAkD;AAClD,6BAA2E;AAC3E,4CAO0B;AAQ1B,MAAa,YAAa,SAAQ,iCAAgC;IAUhE,YAAY,YAAiC,EAAE,OAA0B;QACvE,KAAK,EAAE,CAAC;;QAJV,mBAAc,GAAG,KAAK,CAAC;QACvB,wCAA6B;QAC7B,+BAAU,GAAG,EAAC;QAGZ,IAAI,CAAC,IAAA,2BAAuB,EAAC,OAAO,CAAC,EAAE;YACrC,MAAM,IAAI,gBAAY,CAAC,cAAc,EAAE,uBAAuB,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;SACrF;QACD,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,E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ACrB,OAAO,EAAE,IAAI,CAAC,EAAE;QAChB,cAAc,EAAE,OAAO,CAAC,KAAK,CAAC,mBAA0B;KACzD,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { TypedEmitter } from \"tiny-typed-emitter\";\nimport { DisTubeError, entersState, isSupportedVoiceChannel } from \"../..\";\nimport {\n AudioPlayerStatus,\n VoiceConnectionDisconnectReason,\n VoiceConnectionStatus,\n createAudioPlayer,\n createAudioResource,\n joinVoiceChannel,\n} from \"@discordjs/voice\";\nimport type { DisTubeStream, DisTubeVoiceEvents, DisTubeVoiceManager } from \"../..\";\nimport type { AudioPlayer, AudioResource, VoiceConnection } from \"@discordjs/voice\";\nimport type { Snowflake, VoiceBasedChannel, VoiceState } from \"discord.js\";\n\n/**\n * Create a voice connection to the voice channel\n */\nexport class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {\n readonly id: Snowflake;\n readonly voices: DisTubeVoiceManager;\n readonly audioPlayer: AudioPlayer;\n connection!: VoiceConnection;\n audioResource?: AudioResource;\n emittedError!: boolean;\n isDisconnected = false;\n #channel!: VoiceBasedChannel;\n #volume = 100;\n constructor(voiceManager: DisTubeVoiceManager, channel: VoiceBasedChannel) {\n super();\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"channel\");\n }\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.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(new DisTubeError(\"VOICE_RECONNECT_FAILED\"));\n });\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: VoiceBasedChannel) {\n if (!isSupportedVoiceChannel(channel)) {\n throw new DisTubeError(\"INVALID_TYPE\", \"BaseGuildVoiceChannel\", channel, \"DisTubeVoice#channel\");\n }\n if (channel.guild.id !== this.id) throw new DisTubeError(\"VOICE_CHANGE_GUILD\");\n this.connection = this.#join(channel);\n this.audioResource?.encoder?.setBitrate(channel.bitrate);\n this.#channel = channel;\n }\n #join(channel: VoiceBasedChannel) {\n return joinVoiceChannel({\n channelId: channel.id,\n guildId: this.id,\n adapterCreator: channel.guild.voiceAdapterCreator as any,\n });\n }\n /**\n * Join a voice channel with this connection\n * @param {Discord.BaseGuildVoiceChannel} [channel] A voice channel\n * @returns {Promise<DisTubeVoice>}\n */\n async join(channel?: VoiceBasedChannel): 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.remove(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(true);\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.remove(this.id);\n }\n /**\n * Stop the playing stream\n * @param {boolean} [force=false] If true, will force the {@link DisTubeVoice#audioPlayer} to enter the Idle state\n * even if the {@link DisTubeVoice#audioResource} has silence padding frames.\n * @private\n */\n stop(force = false) {\n this.audioPlayer.stop(force);\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 this.volume = this.#volume;\n this.audioResource.encoder?.setBitrate(this.channel.bitrate);\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;\n this.audioResource?.volume?.setVolume(Math.pow(this.#volume / 100, 0.5 / Math.log10(2)));\n }\n get volume() {\n return this.#volume;\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"]}
|
|
@@ -1,41 +1,10 @@
|
|
|
1
1
|
import { DisTubeVoice } from ".";
|
|
2
|
-
import {
|
|
2
|
+
import { GuildIdManager } from "../manager";
|
|
3
3
|
import type { GuildIdResolvable } from "../..";
|
|
4
4
|
import type { VoiceBasedChannel } from "discord.js";
|
|
5
|
-
|
|
6
|
-
* Manages voice connections for {@link DisTube}
|
|
7
|
-
* @extends BaseManager
|
|
8
|
-
*/
|
|
9
|
-
export declare class DisTubeVoiceManager extends BaseManager<DisTubeVoice> {
|
|
10
|
-
/**
|
|
11
|
-
* Get a {@link DisTubeVoice}.
|
|
12
|
-
* @method get
|
|
13
|
-
* @memberof DisTubeVoiceManager#
|
|
14
|
-
* @param {GuildIdResolvable} queue The queue resolvable to resolve
|
|
15
|
-
* @returns {DisTubeVoice?}
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Collection of {@link DisTubeVoice}.
|
|
19
|
-
* @name DisTubeVoiceManager#collection
|
|
20
|
-
* @type {Discord.Collection<string, DisTubeVoice>}
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Create a {@link DisTubeVoice}
|
|
24
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
|
|
25
|
-
* @returns {DisTubeVoice}
|
|
26
|
-
* @private
|
|
27
|
-
*/
|
|
5
|
+
export declare class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {
|
|
28
6
|
create(channel: VoiceBasedChannel): DisTubeVoice;
|
|
29
|
-
/**
|
|
30
|
-
* Join a voice channel
|
|
31
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
|
|
32
|
-
* @returns {Promise<DisTubeVoice>}
|
|
33
|
-
*/
|
|
34
7
|
join(channel: VoiceBasedChannel): Promise<DisTubeVoice>;
|
|
35
|
-
/**
|
|
36
|
-
* Leave the connected voice channel in a guild
|
|
37
|
-
* @param {GuildIdResolvable} guild Queue Resolvable
|
|
38
|
-
*/
|
|
39
8
|
leave(guild: GuildIdResolvable): void;
|
|
40
9
|
}
|
|
41
10
|
//# sourceMappingURL=DisTubeVoiceManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoiceManager.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAEjC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"DisTubeVoiceManager.d.ts","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAMpD,qBAAa,mBAAoB,SAAQ,cAAc,CAAC,YAAY,CAAC;IAmBnE,MAAM,CAAC,OAAO,EAAE,iBAAiB,GAAG,YAAY;IAYhD,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC;IASvD,KAAK,CAAC,KAAK,EAAE,iBAAiB;CAW/B"}
|
|
@@ -5,29 +5,7 @@ const _1 = require(".");
|
|
|
5
5
|
const __1 = require("../..");
|
|
6
6
|
const manager_1 = require("../manager");
|
|
7
7
|
const voice_1 = require("@discordjs/voice");
|
|
8
|
-
|
|
9
|
-
* Manages voice connections for {@link DisTube}
|
|
10
|
-
* @extends BaseManager
|
|
11
|
-
*/
|
|
12
|
-
class DisTubeVoiceManager extends manager_1.BaseManager {
|
|
13
|
-
/**
|
|
14
|
-
* Get a {@link DisTubeVoice}.
|
|
15
|
-
* @method get
|
|
16
|
-
* @memberof DisTubeVoiceManager#
|
|
17
|
-
* @param {GuildIdResolvable} queue The queue resolvable to resolve
|
|
18
|
-
* @returns {DisTubeVoice?}
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Collection of {@link DisTubeVoice}.
|
|
22
|
-
* @name DisTubeVoiceManager#collection
|
|
23
|
-
* @type {Discord.Collection<string, DisTubeVoice>}
|
|
24
|
-
*/
|
|
25
|
-
/**
|
|
26
|
-
* Create a {@link DisTubeVoice}
|
|
27
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
|
|
28
|
-
* @returns {DisTubeVoice}
|
|
29
|
-
* @private
|
|
30
|
-
*/
|
|
8
|
+
class DisTubeVoiceManager extends manager_1.GuildIdManager {
|
|
31
9
|
create(channel) {
|
|
32
10
|
const existing = this.get(channel.guild.id);
|
|
33
11
|
if (existing) {
|
|
@@ -35,21 +13,12 @@ class DisTubeVoiceManager extends manager_1.BaseManager {
|
|
|
35
13
|
}
|
|
36
14
|
return new _1.DisTubeVoice(this, channel);
|
|
37
15
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Join a voice channel
|
|
40
|
-
* @param {Discord.BaseGuildVoiceChannel} channel A voice channel to join
|
|
41
|
-
* @returns {Promise<DisTubeVoice>}
|
|
42
|
-
*/
|
|
43
16
|
join(channel) {
|
|
44
17
|
const existing = this.get(channel.guild.id);
|
|
45
18
|
if (existing)
|
|
46
19
|
return existing.join(channel);
|
|
47
20
|
return this.create(channel).join();
|
|
48
21
|
}
|
|
49
|
-
/**
|
|
50
|
-
* Leave the connected voice channel in a guild
|
|
51
|
-
* @param {GuildIdResolvable} guild Queue Resolvable
|
|
52
|
-
*/
|
|
53
22
|
leave(guild) {
|
|
54
23
|
const voice = this.get(guild);
|
|
55
24
|
if (voice) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DisTubeVoiceManager.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,6BAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"DisTubeVoiceManager.js","sourceRoot":"","sources":["../../../src/core/voice/DisTubeVoiceManager.ts"],"names":[],"mappings":";;;AAAA,wBAAiC;AACjC,6BAAuC;AACvC,wCAA4C;AAC5C,4CAA6E;AAQ7E,MAAa,mBAAoB,SAAQ,wBAA4B;IAmBnE,MAAM,CAAC,OAA0B;QAC/B,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,CAAC;IAMD,IAAI,CAAC,OAA0B;QAC7B,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC5C,IAAI,QAAQ;YAAE,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAKD,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","sourcesContent":["import { DisTubeVoice } from \".\";\nimport { resolveGuildId } from \"../..\";\nimport { GuildIdManager } from \"../manager\";\nimport { VoiceConnectionStatus, getVoiceConnection } from \"@discordjs/voice\";\nimport type { GuildIdResolvable } from \"../..\";\nimport type { VoiceBasedChannel } from \"discord.js\";\n\n/**\n * Manages voice connections for {@link DisTube}\n * @extends BaseManager\n */\nexport class DisTubeVoiceManager extends GuildIdManager<DisTubeVoice> {\n /**\n * Get a {@link DisTubeVoice}.\n * @method get\n * @memberof DisTubeVoiceManager#\n * @param {GuildIdResolvable} guild 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.BaseGuildVoiceChannel} channel A voice channel to join\n * @returns {DisTubeVoice}\n * @private\n */\n create(channel: VoiceBasedChannel): 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.BaseGuildVoiceChannel} channel A voice channel to join\n * @returns {Promise<DisTubeVoice>}\n */\n join(channel: VoiceBasedChannel): 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"]}
|
|
@@ -2,50 +2,9 @@ import { Plugin } from ".";
|
|
|
2
2
|
import { PluginType } from "..";
|
|
3
3
|
import type { VoiceBasedChannel } from "discord.js";
|
|
4
4
|
import type { Awaitable, CustomPluginPlayOptions } from "..";
|
|
5
|
-
/**
|
|
6
|
-
* Custom Plugin
|
|
7
|
-
* @extends Plugin
|
|
8
|
-
* @abstract
|
|
9
|
-
*/
|
|
10
5
|
export declare abstract class CustomPlugin extends Plugin {
|
|
11
6
|
type: PluginType;
|
|
12
|
-
/**
|
|
13
|
-
* This method will be executed if the `song` string is validated.
|
|
14
|
-
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
15
|
-
* @param {string} song Validated `song`
|
|
16
|
-
* @param {CustomPluginPlayOptions} [options] Optional options
|
|
17
|
-
* @returns {Promise<void>}
|
|
18
|
-
* @abstract
|
|
19
|
-
*/
|
|
20
7
|
abstract play(voiceChannel: VoiceBasedChannel, song: string, options: CustomPluginPlayOptions): Awaitable<void>;
|
|
21
|
-
/**
|
|
22
|
-
* Check if the {@link DisTube#play} `song` parameter is working with this plugin
|
|
23
|
-
* @param {string} song String need to validate
|
|
24
|
-
* @returns {boolean|Promise<boolean>}
|
|
25
|
-
*/
|
|
26
8
|
validate(song: string): Awaitable<boolean>;
|
|
27
9
|
}
|
|
28
|
-
/**
|
|
29
|
-
* @typedef {Object} CustomPluginPlayOptions
|
|
30
|
-
* @param {Discord.GuildMember} [member] Requested user
|
|
31
|
-
* @param {Discord.BaseGuildTextChannel} [textChannel] Default {@link Queue#textChannel}
|
|
32
|
-
* @param {boolean} [skip=false]
|
|
33
|
-
* Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
|
|
34
|
-
* If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
|
|
35
|
-
* @param {number} [position=0] Position of the song/playlist to add to the queue,
|
|
36
|
-
* <= 0 to add to the end of the queue.
|
|
37
|
-
* @param {boolean} [unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
|
|
38
|
-
* (after the playing song if exists)
|
|
39
|
-
* @param {*} [metadata] Optional metadata that can be attached to the song/playlist will be played.
|
|
40
|
-
*/
|
|
41
|
-
/**
|
|
42
|
-
* This method will be executed if the url is validated.
|
|
43
|
-
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
44
|
-
* @param {string} song Validated `song`
|
|
45
|
-
* @param {CustomPluginPlayOptions} [options] Optional options
|
|
46
|
-
* @returns {Promise<void>}
|
|
47
|
-
* @abstract
|
|
48
|
-
* @method play
|
|
49
|
-
* @memberof CustomPlugin#
|
|
50
|
-
*/
|
|
51
10
|
//# sourceMappingURL=CustomPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomPlugin.d.ts","sourceRoot":"","sources":["../../src/struct/CustomPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAgC,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"CustomPlugin.d.ts","sourceRoot":"","sources":["../../src/struct/CustomPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAgC,MAAM,IAAI,CAAC;AAO3F,8BAAsB,YAAa,SAAQ,MAAM;IAC/C,IAAI,aAAqB;IASzB,QAAQ,CAAC,IAAI,CAAC,YAAY,EAAE,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,SAAS,CAAC,IAAI,CAAC;IAM/G,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;CAG3C"}
|
|
@@ -1,50 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CustomPlugin = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
4
|
const _1 = require(".");
|
|
6
5
|
const __1 = require("..");
|
|
7
|
-
/**
|
|
8
|
-
* Custom Plugin
|
|
9
|
-
* @extends Plugin
|
|
10
|
-
* @abstract
|
|
11
|
-
*/
|
|
12
6
|
class CustomPlugin extends _1.Plugin {
|
|
13
7
|
constructor() {
|
|
14
8
|
super(...arguments);
|
|
15
9
|
this.type = __1.PluginType.CUSTOM;
|
|
16
10
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Check if the {@link DisTube#play} `song` parameter is working with this plugin
|
|
19
|
-
* @param {string} song String need to validate
|
|
20
|
-
* @returns {boolean|Promise<boolean>}
|
|
21
|
-
*/
|
|
22
11
|
validate(song) {
|
|
23
12
|
return false;
|
|
24
13
|
}
|
|
25
14
|
}
|
|
26
15
|
exports.CustomPlugin = CustomPlugin;
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {Object} CustomPluginPlayOptions
|
|
29
|
-
* @param {Discord.GuildMember} [member] Requested user
|
|
30
|
-
* @param {Discord.BaseGuildTextChannel} [textChannel] Default {@link Queue#textChannel}
|
|
31
|
-
* @param {boolean} [skip=false]
|
|
32
|
-
* Skip the playing song (if exists) and play the added song/playlist if `position` is 1.
|
|
33
|
-
* If `position` is defined and not equal to 1, it will skip to the next song instead of the added song
|
|
34
|
-
* @param {number} [position=0] Position of the song/playlist to add to the queue,
|
|
35
|
-
* <= 0 to add to the end of the queue.
|
|
36
|
-
* @param {boolean} [unshift=false] (DEPRECATED) Add the song/playlist to the beginning of the queue
|
|
37
|
-
* (after the playing song if exists)
|
|
38
|
-
* @param {*} [metadata] Optional metadata that can be attached to the song/playlist will be played.
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* This method will be executed if the url is validated.
|
|
42
|
-
* @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined
|
|
43
|
-
* @param {string} song Validated `song`
|
|
44
|
-
* @param {CustomPluginPlayOptions} [options] Optional options
|
|
45
|
-
* @returns {Promise<void>}
|
|
46
|
-
* @abstract
|
|
47
|
-
* @method play
|
|
48
|
-
* @memberof CustomPlugin#
|
|
49
|
-
*/
|
|
50
16
|
//# sourceMappingURL=CustomPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomPlugin.js","sourceRoot":"","sources":["../../src/struct/CustomPlugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"CustomPlugin.js","sourceRoot":"","sources":["../../src/struct/CustomPlugin.ts"],"names":[],"mappings":";;;AACA,wBAA2B;AAC3B,0BAAgC;AAShC,MAAsB,YAAa,SAAQ,SAAM;IAAjD;;QACE,SAAI,GAAG,cAAU,CAAC,MAAM,CAAC;IAkB3B,CAAC;IAHC,QAAQ,CAAC,IAAY;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAnBD,oCAmBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { Plugin } from \".\";\nimport { PluginType } from \"..\";\nimport type { VoiceBasedChannel } from \"discord.js\";\nimport type { Awaitable, CustomPluginPlayOptions, Playlist, SearchResult, Song } from \"..\";\n\n/**\n * Custom Plugin\n * @extends Plugin\n * @abstract\n */\nexport abstract class CustomPlugin extends Plugin {\n type = PluginType.CUSTOM;\n /**\n * This method will be executed if the `song` string is validated.\n * @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined\n * @param {string} song Validated `song`\n * @param {CustomPluginPlayOptions} [options] Optional options\n * @returns {Promise<void>}\n * @abstract\n */\n abstract play(voiceChannel: VoiceBasedChannel, song: string, options: CustomPluginPlayOptions): Awaitable<void>;\n /**\n * Check if the {@link DisTube#play} `song` parameter is working with this plugin\n * @param {string} song String need to validate\n * @returns {boolean|Promise<boolean>}\n */\n validate(song: string): Awaitable<boolean> {\n return false;\n }\n}\n\n/**\n * @typedef {Object} CustomPluginPlayOptions\n * @param {Discord.GuildMember} [member] Requested user\n * @param {Discord.BaseGuildTextChannel} [textChannel] Default {@link Queue#textChannel}\n * @param {boolean} [skip=false]\n * Skip the playing song (if exists) and play the added song/playlist if `position` is 1.\n * If `position` is defined and not equal to 1, it will skip to the next song instead of the added song\n * @param {number} [position=0] Position of the song/playlist to add to the queue,\n * <= 0 to add to the end of the queue.\n * @param {*} [metadata] Optional metadata that can be attached to the song/playlist will be played.\n */\n\n/**\n * This method will be executed if the url is validated.\n * @param {Discord.BaseGuildVoiceChannel} voiceChannel The voice channel will be joined\n * @param {string} song Validated `song`\n * @param {CustomPluginPlayOptions} [options] Optional options\n * @returns {Promise<void>}\n * @abstract\n * @method play\n * @memberof CustomPlugin#\n */\n"]}
|
|
@@ -2,44 +2,12 @@ import { Plugin } from ".";
|
|
|
2
2
|
import { PluginType } from "..";
|
|
3
3
|
import type { GuildMember } from "discord.js";
|
|
4
4
|
import type { Awaitable, Playlist, Song } from "..";
|
|
5
|
-
/**
|
|
6
|
-
* Extractor Plugin
|
|
7
|
-
* @extends Plugin
|
|
8
|
-
* @abstract
|
|
9
|
-
*/
|
|
10
5
|
export declare abstract class ExtractorPlugin extends Plugin {
|
|
11
6
|
type: PluginType;
|
|
12
|
-
/**
|
|
13
|
-
* Resolve the validated url to a {@link Song} or a {@link Playlist}.
|
|
14
|
-
*
|
|
15
|
-
* @param {string} url URL
|
|
16
|
-
* @param {Object} [options] Optional options
|
|
17
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
18
|
-
* @param {*} [options.metadata] Metadata
|
|
19
|
-
* @returns {Song|Playlist|Promise<Song|Playlist>}
|
|
20
|
-
* @abstract
|
|
21
|
-
*/
|
|
22
7
|
abstract resolve<T = unknown>(url: string, options: {
|
|
23
8
|
member?: GuildMember;
|
|
24
9
|
metadata?: T;
|
|
25
10
|
}): Awaitable<Song<T> | Playlist<T>>;
|
|
26
|
-
/**
|
|
27
|
-
* Check if the url is working with this plugin
|
|
28
|
-
* @param {string} url Input url
|
|
29
|
-
* @returns {boolean|Promise<boolean>}
|
|
30
|
-
*/
|
|
31
11
|
validate(url: string): Awaitable<boolean>;
|
|
32
12
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Resolve the validated url to a {@link Song} or a {@link Playlist}.
|
|
35
|
-
*
|
|
36
|
-
* @param {string} url URL
|
|
37
|
-
* @param {Object} [options] Optional options
|
|
38
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
39
|
-
* @param {*} [options.metadata] Metadata
|
|
40
|
-
* @returns {Song|Playlist|Promise<Song|Playlist>}
|
|
41
|
-
* @method resolve
|
|
42
|
-
* @memberof ExtractorPlugin#
|
|
43
|
-
* @abstract
|
|
44
|
-
*/
|
|
45
13
|
//# sourceMappingURL=ExtractorPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtractorPlugin.d.ts","sourceRoot":"","sources":["../../src/struct/ExtractorPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"ExtractorPlugin.d.ts","sourceRoot":"","sources":["../../src/struct/ExtractorPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAOpD,8BAAsB,eAAgB,SAAQ,MAAM;IAClD,IAAI,aAAwB;IAW5B,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAC;QAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;KAAE,GAC9C,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAMnC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC;CAG1C"}
|
|
@@ -1,39 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExtractorPlugin = void 0;
|
|
4
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
5
4
|
const _1 = require(".");
|
|
6
5
|
const __1 = require("..");
|
|
7
|
-
/**
|
|
8
|
-
* Extractor Plugin
|
|
9
|
-
* @extends Plugin
|
|
10
|
-
* @abstract
|
|
11
|
-
*/
|
|
12
6
|
class ExtractorPlugin extends _1.Plugin {
|
|
13
7
|
constructor() {
|
|
14
8
|
super(...arguments);
|
|
15
9
|
this.type = __1.PluginType.EXTRACTOR;
|
|
16
10
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Check if the url is working with this plugin
|
|
19
|
-
* @param {string} url Input url
|
|
20
|
-
* @returns {boolean|Promise<boolean>}
|
|
21
|
-
*/
|
|
22
11
|
validate(url) {
|
|
23
12
|
return false;
|
|
24
13
|
}
|
|
25
14
|
}
|
|
26
15
|
exports.ExtractorPlugin = ExtractorPlugin;
|
|
27
|
-
/**
|
|
28
|
-
* Resolve the validated url to a {@link Song} or a {@link Playlist}.
|
|
29
|
-
*
|
|
30
|
-
* @param {string} url URL
|
|
31
|
-
* @param {Object} [options] Optional options
|
|
32
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
33
|
-
* @param {*} [options.metadata] Metadata
|
|
34
|
-
* @returns {Song|Playlist|Promise<Song|Playlist>}
|
|
35
|
-
* @method resolve
|
|
36
|
-
* @memberof ExtractorPlugin#
|
|
37
|
-
* @abstract
|
|
38
|
-
*/
|
|
39
16
|
//# sourceMappingURL=ExtractorPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtractorPlugin.js","sourceRoot":"","sources":["../../src/struct/ExtractorPlugin.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ExtractorPlugin.js","sourceRoot":"","sources":["../../src/struct/ExtractorPlugin.ts"],"names":[],"mappings":";;;AACA,wBAA2B;AAC3B,0BAAgC;AAShC,MAAsB,eAAgB,SAAQ,SAAM;IAApD;;QACE,SAAI,GAAG,cAAU,CAAC,SAAS,CAAC;IAuB9B,CAAC;IAHC,QAAQ,CAAC,GAAW;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAxBD,0CAwBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\nimport { Plugin } from \".\";\nimport { PluginType } from \"..\";\nimport type { GuildMember } from \"discord.js\";\nimport type { Awaitable, Playlist, Song } from \"..\";\n\n/**\n * Extractor Plugin\n * @extends Plugin\n * @abstract\n */\nexport abstract class ExtractorPlugin extends Plugin {\n type = PluginType.EXTRACTOR;\n /**\n * Resolve the validated url to a {@link Song} or a {@link Playlist}.\n *\n * @param {string} url URL\n * @param {Object} [options] Optional options\n * @param {Discord.GuildMember} [options.member] Requested user\n * @param {*} [options.metadata] Metadata\n * @returns {Song|Playlist|Promise<Song|Playlist>}\n * @abstract\n */\n abstract resolve<T = unknown>(\n url: string,\n options: { member?: GuildMember; metadata?: T },\n ): Awaitable<Song<T> | Playlist<T>>;\n /**\n * Check if the url is working with this plugin\n * @param {string} url Input url\n * @returns {boolean|Promise<boolean>}\n */\n validate(url: string): Awaitable<boolean> {\n return false;\n }\n}\n\n/**\n * Resolve the validated url to a {@link Song} or a {@link Playlist}.\n *\n * @param {string} url URL\n * @param {Object} [options] Optional options\n * @param {Discord.GuildMember} [options.member] Requested user\n * @param {*} [options.metadata] Metadata\n * @returns {Song|Playlist|Promise<Song|Playlist>}\n * @method resolve\n * @memberof ExtractorPlugin#\n * @abstract\n */\n"]}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type ytpl from "@distube/ytpl";
|
|
2
2
|
import type { PlaylistInfo, Song } from "..";
|
|
3
3
|
import type { GuildMember } from "discord.js";
|
|
4
|
-
/**
|
|
5
|
-
* Class representing a playlist.
|
|
6
|
-
* @prop {string} source Playlist source
|
|
7
|
-
* @template T - The type for the metadata (if any) of the playlist
|
|
8
|
-
*/
|
|
9
4
|
export declare class Playlist<T = unknown> implements PlaylistInfo {
|
|
10
5
|
#private;
|
|
11
6
|
source: string;
|
|
@@ -14,39 +9,15 @@ export declare class Playlist<T = unknown> implements PlaylistInfo {
|
|
|
14
9
|
url?: string;
|
|
15
10
|
thumbnail?: string;
|
|
16
11
|
[x: string]: any;
|
|
17
|
-
/**
|
|
18
|
-
* Create a playlist
|
|
19
|
-
* @param {Song[]|PlaylistInfo} playlist Playlist
|
|
20
|
-
* @param {Object} [options] Optional options
|
|
21
|
-
* @param {Discord.GuildMember} [options.member] Requested user
|
|
22
|
-
* @param {Object} [options.properties] Custom properties
|
|
23
|
-
* @param {T} [options.metadata] Playlist metadata
|
|
24
|
-
*/
|
|
25
12
|
constructor(playlist: Song[] | ytpl.result | PlaylistInfo, options?: {
|
|
26
13
|
member?: GuildMember;
|
|
27
14
|
properties?: Record<string, any>;
|
|
28
15
|
metadata?: T;
|
|
29
16
|
});
|
|
30
|
-
/**
|
|
31
|
-
* Playlist duration in second.
|
|
32
|
-
* @type {number}
|
|
33
|
-
*/
|
|
34
17
|
get duration(): number;
|
|
35
|
-
/**
|
|
36
|
-
* Formatted duration string `hh:mm:ss`.
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
18
|
get formattedDuration(): string;
|
|
40
|
-
/**
|
|
41
|
-
* User requested.
|
|
42
|
-
* @type {Discord.GuildMember?}
|
|
43
|
-
*/
|
|
44
19
|
get member(): GuildMember | undefined;
|
|
45
20
|
set member(member: GuildMember | undefined);
|
|
46
|
-
/**
|
|
47
|
-
* User requested.
|
|
48
|
-
* @type {Discord.User?}
|
|
49
|
-
*/
|
|
50
21
|
get user(): import("discord.js").User | undefined;
|
|
51
22
|
get metadata(): T;
|
|
52
23
|
set metadata(metadata: T);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Playlist.d.ts","sourceRoot":"","sources":["../../src/struct/Playlist.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"Playlist.d.ts","sourceRoot":"","sources":["../../src/struct/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