Add /loop support for individual songs (#707)

This commit is contained in:
Cleo 2022-06-25 20:20:45 -04:00 committed by GitHub
parent eb07ac6d22
commit 6cdfefe174
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View file

@ -60,6 +60,7 @@ export default class {
public voiceConnection: VoiceConnection | null = null;
public status = STATUS.PAUSED;
public guildId: string;
public loopCurrentSong = false;
private queue: QueuedSong[] = [];
private queuePosition = 0;
@ -69,7 +70,6 @@ export default class {
private lastSongURL = '';
private positionInSeconds = 0;
private readonly fileCache: FileCacheProvider;
private disconnectTimer: NodeJS.Timeout | null = null;
@ -92,6 +92,7 @@ export default class {
this.pause();
}
this.loopCurrentSong = false;
this.voiceConnection.destroy();
this.audioPlayer?.stop();
@ -523,6 +524,11 @@ export default class {
private async onAudioPlayerIdle(_oldState: AudioPlayerState, newState: AudioPlayerState): Promise<void> {
// Automatically advance queued song at end
if (this.loopCurrentSong && newState.status === AudioPlayerStatus.Idle && this.status === STATUS.PLAYING) {
await this.seek(0);
return;
}
if (newState.status === AudioPlayerStatus.Idle && this.status === STATUS.PLAYING) {
await this.forward(1);
}