🐛 Crash when no items from API are present

This commit is contained in:
Manuel Ruwe 2022-12-17 18:31:58 +01:00
parent c2c2a9d091
commit 9c23ef293f
3 changed files with 43 additions and 25 deletions

View File

@ -20,6 +20,11 @@ export class DiscordMessageService {
description: description,
mixin(embedBuilder) {
return embedBuilder
.setAuthor({
name: title,
iconURL:
'https://github.com/manuel-rw/jellyfin-discord-music-bot/blob/nestjs-migration/images/icons/alert-circle.png?raw=true',
})
.setFooter({
text: `${date} - Report an issue: ${Constants.Links.ReportIssue}`,
})

View File

@ -1,23 +1,9 @@
import { TransformPipe } from '@discord-nestjs/common';
import {
Command,
CommandExecutionContext,
DiscordCommand,
DiscordTransformedCommand,
TransformedCommandExecutionContext,
UsePipes,
} from '@discord-nestjs/core';
import {
ButtonInteraction,
CacheType,
ChatInputCommandInteraction,
ContextMenuCommandInteraction,
Interaction,
InteractionReplyOptions,
MessagePayload,
StringSelectMenuInteraction,
} from 'discord.js';
import { Command, DiscordCommand, UsePipes } from '@discord-nestjs/core';
import { CommandInteraction, InteractionReplyOptions } from 'discord.js';
import { DiscordMessageService } from '../clients/discord/discord.message.service';
import { DiscordVoiceService } from '../clients/discord/discord.voice.service';
@Command({
name: 'pause',
@ -25,16 +11,32 @@ import {
})
@UsePipes(TransformPipe)
export class PausePlaybackCommand implements DiscordCommand {
constructor(
private readonly discordVoiceService: DiscordVoiceService,
private readonly discordMessageService: DiscordMessageService,
) {}
handler(
interaction:
| ChatInputCommandInteraction<CacheType>
| ContextMenuCommandInteraction<CacheType>,
executionContext: CommandExecutionContext<
StringSelectMenuInteraction<CacheType> | ButtonInteraction<CacheType>
>,
commandInteraction: CommandInteraction,
): string | InteractionReplyOptions {
const newStatus = this.discordVoiceService.togglePaused();
if (newStatus) {
return {
content: 'test',
embeds: [
this.discordMessageService.buildMessage({
title: 'Paused',
}),
],
};
}
return {
embeds: [
this.discordMessageService.buildMessage({
title: 'Unpaused',
}),
],
};
}
}

View File

@ -53,6 +53,17 @@ export class SearchItemCommand
): Promise<InteractionReplyOptions | string> {
const items = await this.jellyfinSearchService.search(dto.search);
if (items.length < 1) {
return {
embeds: [
this.discordMessageService.buildErrorMessage({
title: 'No results for your search query found',
description: `I was not able to find any matches for your query \`\`${dto.search}\`\`. Please check that I have access to the desired libraries and that your query is not misspelled`,
}),
],
};
}
const firstItems = items.slice(0, 10);
const lines: string[] = firstItems.map(