mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-25 02:51:57 +01:00
🐛 Fix activeTrack being null crashing the bot (#57)
Co-authored-by: kawao <beninthepan@icloud.com> Co-authored-by: Manuel <30572287+manuel-rw@users.noreply.github.com>
This commit is contained in:
parent
ad3519ea8c
commit
e150efdc10
@ -58,6 +58,10 @@ export class JellyinPlaystateService {
|
||||
private async onPlaybackPaused(isPaused: boolean) {
|
||||
const activeTrack = this.playbackService.getActiveTrack();
|
||||
|
||||
if (!activeTrack) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.playstateApi.reportPlaybackProgress({
|
||||
playbackProgressInfo: {
|
||||
ItemId: activeTrack.track.jellyfinId,
|
||||
@ -70,6 +74,10 @@ export class JellyinPlaystateService {
|
||||
private async onPlaybackStopped() {
|
||||
const activeTrack = this.playbackService.getActiveTrack();
|
||||
|
||||
if (!activeTrack) {
|
||||
return;
|
||||
}
|
||||
|
||||
await this.playstateApi.reportPlaybackStopped({
|
||||
playbackStopInfo: {
|
||||
ItemId: activeTrack.track.jellyfinId,
|
||||
|
@ -20,15 +20,19 @@ export class StopPlaybackCommand implements DiscordCommand {
|
||||
) {}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
handler(CommandInteraction: CommandInteraction): GenericCustomReply {
|
||||
this.playbackService.clear();
|
||||
this.discordVoiceService.stop(false);
|
||||
const hasActiveTrack = this.playbackService.hasActiveTrack()
|
||||
const title = hasActiveTrack ? 'Playback stopped successfully' : 'Playback failed to stop'
|
||||
const description = hasActiveTrack ? 'In addition, your playlist has been cleared' : 'There is no active track in the queue'
|
||||
if (hasActiveTrack) {
|
||||
this.playbackService.clear();
|
||||
this.discordVoiceService.stop(false);
|
||||
}
|
||||
|
||||
return {
|
||||
embeds: [
|
||||
this.discordMessageService.buildMessage({
|
||||
title: 'Playlist cleared',
|
||||
description:
|
||||
'Playback was stopped and your playlist has been cleared',
|
||||
this.discordMessageService[hasActiveTrack ? 'buildMessage' : 'buildErrorMessage']({
|
||||
title: title,
|
||||
description: description,
|
||||
}),
|
||||
],
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user