🐛 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) { 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,
@ -70,6 +74,10 @@ export class JellyinPlaystateService {
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: {
ItemId: activeTrack.track.jellyfinId, ItemId: activeTrack.track.jellyfinId,

View File

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