mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
🐛 Crash when no items from API are present
This commit is contained in:
parent
c2c2a9d091
commit
9c23ef293f
@ -20,6 +20,11 @@ export class DiscordMessageService {
|
|||||||
description: description,
|
description: description,
|
||||||
mixin(embedBuilder) {
|
mixin(embedBuilder) {
|
||||||
return 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({
|
.setFooter({
|
||||||
text: `${date} - Report an issue: ${Constants.Links.ReportIssue}`,
|
text: `${date} - Report an issue: ${Constants.Links.ReportIssue}`,
|
||||||
})
|
})
|
||||||
|
@ -1,23 +1,9 @@
|
|||||||
import { TransformPipe } from '@discord-nestjs/common';
|
import { TransformPipe } from '@discord-nestjs/common';
|
||||||
|
|
||||||
import {
|
import { Command, DiscordCommand, UsePipes } from '@discord-nestjs/core';
|
||||||
Command,
|
import { CommandInteraction, InteractionReplyOptions } from 'discord.js';
|
||||||
CommandExecutionContext,
|
import { DiscordMessageService } from '../clients/discord/discord.message.service';
|
||||||
DiscordCommand,
|
import { DiscordVoiceService } from '../clients/discord/discord.voice.service';
|
||||||
DiscordTransformedCommand,
|
|
||||||
TransformedCommandExecutionContext,
|
|
||||||
UsePipes,
|
|
||||||
} from '@discord-nestjs/core';
|
|
||||||
import {
|
|
||||||
ButtonInteraction,
|
|
||||||
CacheType,
|
|
||||||
ChatInputCommandInteraction,
|
|
||||||
ContextMenuCommandInteraction,
|
|
||||||
Interaction,
|
|
||||||
InteractionReplyOptions,
|
|
||||||
MessagePayload,
|
|
||||||
StringSelectMenuInteraction,
|
|
||||||
} from 'discord.js';
|
|
||||||
|
|
||||||
@Command({
|
@Command({
|
||||||
name: 'pause',
|
name: 'pause',
|
||||||
@ -25,16 +11,32 @@ import {
|
|||||||
})
|
})
|
||||||
@UsePipes(TransformPipe)
|
@UsePipes(TransformPipe)
|
||||||
export class PausePlaybackCommand implements DiscordCommand {
|
export class PausePlaybackCommand implements DiscordCommand {
|
||||||
|
constructor(
|
||||||
|
private readonly discordVoiceService: DiscordVoiceService,
|
||||||
|
private readonly discordMessageService: DiscordMessageService,
|
||||||
|
) {}
|
||||||
|
|
||||||
handler(
|
handler(
|
||||||
interaction:
|
commandInteraction: CommandInteraction,
|
||||||
| ChatInputCommandInteraction<CacheType>
|
|
||||||
| ContextMenuCommandInteraction<CacheType>,
|
|
||||||
executionContext: CommandExecutionContext<
|
|
||||||
StringSelectMenuInteraction<CacheType> | ButtonInteraction<CacheType>
|
|
||||||
>,
|
|
||||||
): string | InteractionReplyOptions {
|
): string | InteractionReplyOptions {
|
||||||
|
const newStatus = this.discordVoiceService.togglePaused();
|
||||||
|
|
||||||
|
if (newStatus) {
|
||||||
return {
|
return {
|
||||||
content: 'test',
|
embeds: [
|
||||||
|
this.discordMessageService.buildMessage({
|
||||||
|
title: 'Paused',
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
embeds: [
|
||||||
|
this.discordMessageService.buildMessage({
|
||||||
|
title: 'Unpaused',
|
||||||
|
}),
|
||||||
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,17 @@ export class SearchItemCommand
|
|||||||
): Promise<InteractionReplyOptions | string> {
|
): Promise<InteractionReplyOptions | string> {
|
||||||
const items = await this.jellyfinSearchService.search(dto.search);
|
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 firstItems = items.slice(0, 10);
|
||||||
|
|
||||||
const lines: string[] = firstItems.map(
|
const lines: string[] = firstItems.map(
|
||||||
|
Loading…
Reference in New Issue
Block a user