chore(auto): task completed - unknown
This commit is contained in:
@@ -19,6 +19,9 @@ export class DiscordPlayer {
|
|||||||
private owner: DiscordPlayerOwner = "none";
|
private owner: DiscordPlayerOwner = "none";
|
||||||
private resource: AudioResource | null = null;
|
private resource: AudioResource | null = null;
|
||||||
private musicVolume = 1;
|
private musicVolume = 1;
|
||||||
|
private idleCallback: (() => void) | null = null;
|
||||||
|
/** Set before manual stop() calls to distinguish from natural track end. */
|
||||||
|
private manualStop = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.player = createAudioPlayer();
|
this.player = createAudioPlayer();
|
||||||
@@ -27,6 +30,19 @@ export class DiscordPlayer {
|
|||||||
logger.info("Audio player is now playing!");
|
logger.info("Audio player is now playing!");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.player.on(AudioPlayerStatus.Idle, () => {
|
||||||
|
// manualStop guards against both sync & async idle emission from stop()
|
||||||
|
if (this.manualStop || this.owner === "none") {
|
||||||
|
this.manualStop = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Natural track end — queue auto-advance
|
||||||
|
logger.info("Audio player finished — advancing queue");
|
||||||
|
this.owner = "none";
|
||||||
|
this.resource = null;
|
||||||
|
this.idleCallback?.();
|
||||||
|
});
|
||||||
|
|
||||||
this.player.on("error", (error) => {
|
this.player.on("error", (error) => {
|
||||||
logger.error({ error: error.message }, "Audio player error");
|
logger.error({ error: error.message }, "Audio player error");
|
||||||
this.owner = "none";
|
this.owner = "none";
|
||||||
@@ -34,6 +50,11 @@ export class DiscordPlayer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Register a callback fired when the player goes idle after a natural track end. */
|
||||||
|
public onIdle(cb: () => void): void {
|
||||||
|
this.idleCallback = cb;
|
||||||
|
}
|
||||||
|
|
||||||
public setConnection(connection: VoiceConnection) {
|
public setConnection(connection: VoiceConnection) {
|
||||||
this.connection = connection;
|
this.connection = connection;
|
||||||
this.connection.subscribe(this.player);
|
this.connection.subscribe(this.player);
|
||||||
@@ -64,6 +85,7 @@ export class DiscordPlayer {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.owner === owner) {
|
if (this.owner === owner) {
|
||||||
|
this.manualStop = true;
|
||||||
this.player.stop();
|
this.player.stop();
|
||||||
}
|
}
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
@@ -97,6 +119,7 @@ export class DiscordPlayer {
|
|||||||
|
|
||||||
public stop(owner?: DiscordPlayerOwner) {
|
public stop(owner?: DiscordPlayerOwner) {
|
||||||
if (!this.canControl(owner)) return;
|
if (!this.canControl(owner)) return;
|
||||||
|
this.manualStop = true;
|
||||||
this.player.stop();
|
this.player.stop();
|
||||||
this.owner = "none";
|
this.owner = "none";
|
||||||
this.resource = null;
|
this.resource = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user