🐛 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:
nanako 2023-01-17 06:35:51 +09:00 committed by GitHub
parent ad3519ea8c
commit e150efdc10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -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,

View File

@ -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,
}),
],
};