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) {
|
private async onPlaybackPaused(isPaused: boolean) {
|
||||||
const activeTrack = this.playbackService.getActiveTrack();
|
const activeTrack = this.playbackService.getActiveTrack();
|
||||||
|
|
||||||
|
if (!activeTrack) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.playstateApi.reportPlaybackProgress({
|
await this.playstateApi.reportPlaybackProgress({
|
||||||
playbackProgressInfo: {
|
playbackProgressInfo: {
|
||||||
ItemId: activeTrack.track.jellyfinId,
|
ItemId: activeTrack.track.jellyfinId,
|
||||||
@ -69,6 +73,10 @@ export class JellyinPlaystateService {
|
|||||||
@OnEvent('playback.state.stop')
|
@OnEvent('playback.state.stop')
|
||||||
private async onPlaybackStopped() {
|
private async onPlaybackStopped() {
|
||||||
const activeTrack = this.playbackService.getActiveTrack();
|
const activeTrack = this.playbackService.getActiveTrack();
|
||||||
|
|
||||||
|
if (!activeTrack) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.playstateApi.reportPlaybackStopped({
|
await this.playstateApi.reportPlaybackStopped({
|
||||||
playbackStopInfo: {
|
playbackStopInfo: {
|
||||||
|
@ -20,15 +20,19 @@ export class StopPlaybackCommand implements DiscordCommand {
|
|||||||
) {}
|
) {}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
handler(CommandInteraction: CommandInteraction): GenericCustomReply {
|
handler(CommandInteraction: CommandInteraction): GenericCustomReply {
|
||||||
this.playbackService.clear();
|
const hasActiveTrack = this.playbackService.hasActiveTrack()
|
||||||
this.discordVoiceService.stop(false);
|
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 {
|
return {
|
||||||
embeds: [
|
embeds: [
|
||||||
this.discordMessageService.buildMessage({
|
this.discordMessageService[hasActiveTrack ? 'buildMessage' : 'buildErrorMessage']({
|
||||||
title: 'Playlist cleared',
|
title: title,
|
||||||
description:
|
description: description,
|
||||||
'Playback was stopped and your playlist has been cleared',
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user