Skip to content

Commit 944d9f1

Browse files
Add autoplay flag to track metadata (#38)
* Add isAutoplay boolean to autoplay function * Fix unnecessary spaces * Changed autoplay flag * add: types, and use object.defineProperty --------- Co-authored-by: unschooledgamer <unschooledgamer@gmail.com>
1 parent 897e7cf commit 944d9f1

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

build/index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ export declare class Track {
134134
public pluginInfo: object;
135135
public rawData: RestTrack;
136136
public userData: object;
137+
/**
138+
* (Client-Specific Property - not from the Node), If the track was auto-played by the Client/Riffy.
139+
*/
140+
public isAutoplay: boolean;
137141

138142
public resolve(riffy: Riffy): Promise<Track>;
139143
}
@@ -1426,4 +1430,4 @@ export declare class Connection {
14261430
}): void;
14271431

14281432
private updatePlayerVoiceData(voiceData: any): Promise<RestResponse | null>;
1429-
}
1433+
}

build/structures/Player.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Player extends EventEmitter {
148148
if (player == null) {
149149
this.isAutoplay = false;
150150
return this;
151-
// @ts-ignore
151+
// @ts-ignore
152152
} else if (player == false) {
153153
this.isAutoplay = false;
154154
return this;
@@ -193,6 +193,12 @@ class Player extends EventEmitter {
193193
availableTracks = response.tracks;
194194
}
195195
let track = availableTracks[Math.floor(Math.random() * availableTracks.length)];
196+
Object.defineProperty(track, "isAutoplay", {
197+
writable: false,
198+
enumerable: true,
199+
value: true
200+
})
201+
196202
this.queue.push(track);
197203
this.play();
198204
return this;
@@ -223,6 +229,11 @@ class Player extends EventEmitter {
223229
}
224230

225231
let track = availableTracks[Math.floor(Math.random() * availableTracks.length)];
232+
Object.defineProperty(track, "isAutoplay", {
233+
writable: false,
234+
enumerable: true,
235+
value: true
236+
})
226237

227238
this.queue.push(track);
228239
this.play();
@@ -255,6 +266,11 @@ class Player extends EventEmitter {
255266
}
256267

257268
let track = availableTracks[Math.floor(Math.random() * availableTracks.length)];
269+
Object.defineProperty(track, "isAutoplay", {
270+
writable: false,
271+
enumerable: true,
272+
value: true
273+
})
258274

259275
this.queue.push(track);
260276
this.play();
@@ -287,6 +303,11 @@ class Player extends EventEmitter {
287303
}
288304

289305
let track = availableTracks[Math.floor(Math.random() * availableTracks.length)];
306+
Object.defineProperty(track, "isAutoplay", {
307+
writable: false,
308+
enumerable: true,
309+
value: true
310+
})
290311

291312
this.queue.push(track);
292313
this.play();
@@ -300,7 +321,7 @@ class Player extends EventEmitter {
300321
} else return this;
301322
}
302323

303-
connect(options = {
324+
connect(options = {
304325
guildId: this.guildId,
305326
voiceChannel: this.voiceChannel,
306327
deaf: this.deaf,
@@ -654,4 +675,4 @@ class Player extends EventEmitter {
654675
}
655676
}
656677

657-
module.exports = { Player };
678+
module.exports = { Player };

build/structures/Track.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Track {
4040

4141
this.pluginInfo = data.pluginInfo
4242
this.userData = data.userData
43+
this.isAutoplay = false;
4344
}
4445

4546
async resolve(riffy) {
@@ -87,4 +88,4 @@ class Track {
8788
}
8889
}
8990

90-
module.exports = { Track };
91+
module.exports = { Track };

0 commit comments

Comments
 (0)