From 9c23ef293fa32112f017062ce878da56259d7452 Mon Sep 17 00:00:00 2001 From: Manuel Ruwe Date: Sat, 17 Dec 2022 18:31:58 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Crash=20when=20no=20items=20from?= =?UTF-8?q?=20API=20are=20present?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../discord/discord.message.service.ts | 5 ++ src/commands/pause.command.ts | 52 ++++++++++--------- src/commands/search.comands.ts | 11 ++++ 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/clients/discord/discord.message.service.ts b/src/clients/discord/discord.message.service.ts index b8b96cd..4ea303d 100644 --- a/src/clients/discord/discord.message.service.ts +++ b/src/clients/discord/discord.message.service.ts @@ -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}`, }) diff --git a/src/commands/pause.command.ts b/src/commands/pause.command.ts index 833cd3e..6626ad8 100644 --- a/src/commands/pause.command.ts +++ b/src/commands/pause.command.ts @@ -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 - | ContextMenuCommandInteraction, - executionContext: CommandExecutionContext< - StringSelectMenuInteraction | ButtonInteraction - >, + commandInteraction: CommandInteraction, ): string | InteractionReplyOptions { + const newStatus = this.discordVoiceService.togglePaused(); + + if (newStatus) { + return { + embeds: [ + this.discordMessageService.buildMessage({ + title: 'Paused', + }), + ], + }; + } + return { - content: 'test', + embeds: [ + this.discordMessageService.buildMessage({ + title: 'Unpaused', + }), + ], }; } } diff --git a/src/commands/search.comands.ts b/src/commands/search.comands.ts index a6dc466..14de61f 100644 --- a/src/commands/search.comands.ts +++ b/src/commands/search.comands.ts @@ -53,6 +53,17 @@ export class SearchItemCommand ): Promise { 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(