poru 1.0.2 → 1.0.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/package.json +1 -1
- package/src/Player.js +64 -65
package/package.json
CHANGED
package/src/Player.js
CHANGED
|
@@ -8,9 +8,9 @@ class Player extends EventEmitter {
|
|
|
8
8
|
this.manager = manager;
|
|
9
9
|
this.queue = new Queue()
|
|
10
10
|
this.node = node;
|
|
11
|
-
this.filters = new Filters(this,this.node)
|
|
11
|
+
this.filters = new Filters(this, this.node)
|
|
12
|
+
|
|
12
13
|
|
|
13
|
-
|
|
14
14
|
this.guild = options.guild.id || options.guild;
|
|
15
15
|
|
|
16
16
|
this.voiceChannel = options.voiceChannel.id || options.voiceChannel;
|
|
@@ -32,29 +32,28 @@ class Player extends EventEmitter {
|
|
|
32
32
|
|
|
33
33
|
this.timestamp = Date.now();
|
|
34
34
|
|
|
35
|
+
this.pause = false;
|
|
35
36
|
this.position = 0;
|
|
36
37
|
|
|
37
|
-
this.isPaused = false
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
|
|
41
40
|
this.currentTrack = {};
|
|
42
41
|
|
|
43
42
|
this.previousTrack = {};
|
|
44
43
|
|
|
45
|
-
|
|
44
|
+
|
|
46
45
|
this.voiceUpdateState = null;
|
|
47
46
|
|
|
48
|
-
|
|
49
47
|
|
|
50
|
-
|
|
48
|
+
|
|
49
|
+
|
|
51
50
|
|
|
52
51
|
|
|
53
52
|
this.on("event", (data) => (this.lavalinkEvent(data).bind(this))());
|
|
54
|
-
this.on("event",(data)=> this.manager.emit("debug",data))
|
|
53
|
+
this.on("event", (data) => this.manager.emit("debug", data))
|
|
55
54
|
this.on("playerUpdate", (packet) => {
|
|
56
55
|
this.isConnectd = packet.state.connected,
|
|
57
|
-
|
|
56
|
+
this.position = packet.state.position
|
|
58
57
|
this.state = {
|
|
59
58
|
volume: this.state.volume,
|
|
60
59
|
equalizer: this.state.equalizer,
|
|
@@ -63,9 +62,9 @@ class Player extends EventEmitter {
|
|
|
63
62
|
});
|
|
64
63
|
}
|
|
65
64
|
async play() {
|
|
66
|
-
|
|
67
|
-
if(!this.queue.length){
|
|
68
|
-
|
|
65
|
+
|
|
66
|
+
if (!this.queue.length) {
|
|
67
|
+
return nulll;
|
|
69
68
|
}
|
|
70
69
|
this.currentTrack = this.queue.shift();
|
|
71
70
|
this.playing = true;
|
|
@@ -76,7 +75,7 @@ class Player extends EventEmitter {
|
|
|
76
75
|
track: this.currentTrack.track,
|
|
77
76
|
volume: this.volume || 100,
|
|
78
77
|
});
|
|
79
|
-
this.position =0;
|
|
78
|
+
this.position = 0;
|
|
80
79
|
return this;
|
|
81
80
|
}
|
|
82
81
|
|
|
@@ -85,7 +84,7 @@ class Player extends EventEmitter {
|
|
|
85
84
|
|
|
86
85
|
this.position = 0;
|
|
87
86
|
this.isConnectd = false
|
|
88
|
-
this.playing =false;
|
|
87
|
+
this.playing = false;
|
|
89
88
|
this.node.send({
|
|
90
89
|
op: "stop",
|
|
91
90
|
guildId: this.guild
|
|
@@ -95,7 +94,7 @@ class Player extends EventEmitter {
|
|
|
95
94
|
|
|
96
95
|
pause(pause = true) {
|
|
97
96
|
if (typeof pause !== "boolean") throw new RangeError("Pause function must be pass with boolean value.");
|
|
98
|
-
|
|
97
|
+
|
|
99
98
|
this.node.send({
|
|
100
99
|
op: "pause",
|
|
101
100
|
guildId: this.guild,
|
|
@@ -103,7 +102,7 @@ class Player extends EventEmitter {
|
|
|
103
102
|
});
|
|
104
103
|
this.playing = !pause;
|
|
105
104
|
this.paused = pause;
|
|
106
|
-
|
|
105
|
+
|
|
107
106
|
return this;
|
|
108
107
|
}
|
|
109
108
|
|
|
@@ -140,32 +139,32 @@ class Player extends EventEmitter {
|
|
|
140
139
|
async QueueRepeat() {
|
|
141
140
|
this.loop = 2;
|
|
142
141
|
this.queueRepeat = true;
|
|
143
|
-
this.trackRepeat= false;
|
|
142
|
+
this.trackRepeat = false;
|
|
144
143
|
return this;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
async DisableRepeat() {
|
|
148
147
|
this.loop = 0;
|
|
149
|
-
this.trackRepeat =false;
|
|
148
|
+
this.trackRepeat = false;
|
|
150
149
|
this.queueRepeat = false;
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
|
|
151
|
+
|
|
153
152
|
return this;
|
|
154
153
|
}
|
|
155
154
|
|
|
156
|
-
|
|
155
|
+
async setTextChannel(channel) {
|
|
157
156
|
if (typeof channel !== "string") throw new RangeError("Channel must be a string.");
|
|
158
157
|
this.textChannel = channel;
|
|
159
158
|
return this;
|
|
160
159
|
}
|
|
161
160
|
|
|
162
|
-
|
|
161
|
+
async setVoiceChannel(channel) {
|
|
163
162
|
if (typeof channel !== "string") throw new RangeError("Channel must be a string.");
|
|
164
163
|
this.voiceChannel = channel;
|
|
165
164
|
return this;
|
|
166
165
|
}
|
|
167
166
|
|
|
168
|
-
|
|
167
|
+
async connect(data) {
|
|
169
168
|
this.voiceUpdateState = data;
|
|
170
169
|
this.node.send({
|
|
171
170
|
op: "voiceUpdate",
|
|
@@ -189,10 +188,10 @@ class Player extends EventEmitter {
|
|
|
189
188
|
return this;
|
|
190
189
|
}
|
|
191
190
|
|
|
192
|
-
|
|
193
191
|
|
|
194
192
|
|
|
195
|
-
|
|
193
|
+
|
|
194
|
+
async disconnect() {
|
|
196
195
|
if (this.voiceChannel === null) return null;
|
|
197
196
|
this.pause(true);
|
|
198
197
|
this.isConnectd = false;
|
|
@@ -219,26 +218,26 @@ class Player extends EventEmitter {
|
|
|
219
218
|
this.manager.players.delete(this.guild);
|
|
220
219
|
}
|
|
221
220
|
|
|
222
|
-
|
|
221
|
+
async autoplay(toggle = false) {
|
|
223
222
|
|
|
224
|
-
|
|
225
|
-
try{
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
if (!toggle) return null;
|
|
224
|
+
try {
|
|
225
|
+
if (!this.previousTrack) return this.stop();
|
|
226
|
+
let data = `https://www.youtube.com/watch?v=${this.previousTrack.identifier}&list=RD${this.previousTrack.identifier}`;
|
|
228
227
|
|
|
229
|
-
|
|
228
|
+
let response = await this.manager.search(data);
|
|
230
229
|
|
|
231
|
-
|
|
230
|
+
if (!response || !response.tracks || ["LOAD_FAILED", "NO_MATCHES"].includes(response.type)) return this.stop();
|
|
232
231
|
|
|
233
|
-
|
|
232
|
+
let track = response.tracks[Math.floor(Math.random() * Math.floor(response.tracks.length))];
|
|
234
233
|
|
|
235
|
-
|
|
234
|
+
this.queue.push(track);
|
|
236
235
|
|
|
237
|
-
|
|
236
|
+
this.play();
|
|
238
237
|
|
|
239
|
-
|
|
238
|
+
return this;
|
|
240
239
|
|
|
241
|
-
}catch(e){
|
|
240
|
+
} catch (e) {
|
|
242
241
|
console.log(`[Poru Autoplay] error : ${e}`)
|
|
243
242
|
return this.stop();
|
|
244
243
|
}
|
|
@@ -249,46 +248,46 @@ class Player extends EventEmitter {
|
|
|
249
248
|
lavalinkEvent(data) {
|
|
250
249
|
const events = {
|
|
251
250
|
TrackStartEvent() {
|
|
252
|
-
this.playing =true;
|
|
253
|
-
this.paused =false;
|
|
251
|
+
this.playing = true;
|
|
252
|
+
this.paused = false;
|
|
254
253
|
this.manager.emit("trackStart", this, this.currentTrack);
|
|
255
254
|
},
|
|
256
255
|
// eslint-disable-next-line consistent-return
|
|
257
256
|
TrackEndEvent() {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
|
|
258
|
+
this.previousTrack = this.currentTrack;
|
|
259
|
+
|
|
261
260
|
if (this.currentTrack && this.loop === 1) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
261
|
+
|
|
262
|
+
this.queue.unshift(this.previousTrack)
|
|
263
|
+
return this.play();
|
|
265
264
|
} else if (this.currentTrack && this.loop === 2) {
|
|
266
|
-
|
|
265
|
+
|
|
267
266
|
this.queue.push(this.previousTrack)
|
|
268
267
|
return this.play();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if(this.queue.length ===0){
|
|
272
|
-
return this.manager.emit("queueEnd", this, this.track,data);
|
|
273
|
-
// this.destroy();
|
|
274
|
-
} else if (this.queue.length>0) {
|
|
275
|
-
|
|
276
|
-
return this.play();
|
|
277
268
|
}
|
|
278
|
-
|
|
279
|
-
|
|
269
|
+
|
|
270
|
+
if (this.queue.length === 0) {
|
|
271
|
+
return this.manager.emit("queueEnd", this, this.track, data);
|
|
272
|
+
// this.destroy();
|
|
273
|
+
} else if (this.queue.length > 0) {
|
|
274
|
+
|
|
275
|
+
return this.play();
|
|
276
|
+
}
|
|
277
|
+
this.manager.emit("queueEnd", this, this.track, data);
|
|
278
|
+
|
|
280
279
|
},
|
|
281
280
|
TrackStuckEvent() {
|
|
282
|
-
|
|
283
|
-
|
|
281
|
+
this.queue.shift();
|
|
282
|
+
this.manager.emit("trackError", this, this.track, data);
|
|
284
283
|
},
|
|
285
284
|
TrackExceptionEvent() {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
285
|
+
this.queue.shift();
|
|
286
|
+
/**
|
|
287
|
+
* Fire up when there's an error while playing the track
|
|
288
|
+
* @event trackError
|
|
289
|
+
*/
|
|
290
|
+
this.manager.emit("trackError", this, this.track, data);
|
|
292
291
|
},
|
|
293
292
|
WebSocketClosedEvent() {
|
|
294
293
|
if ([4015, 4009].includes(data.code)) {
|