diff --git a/icons/audioplayer/player/favorite.png b/icons/audioplayer/player/favorite.png new file mode 100644 index 0000000..b28a537 Binary files /dev/null and b/icons/audioplayer/player/favorite.png differ diff --git a/src/audioplayer/LoadPlugins.ts b/src/audioplayer/LoadPlugins.ts index b267d25..311f817 100644 --- a/src/audioplayer/LoadPlugins.ts +++ b/src/audioplayer/LoadPlugins.ts @@ -97,7 +97,7 @@ function setupYtCookieSchedule() { const cookies = await getYoutubeCookie(); if (!cookies) return; YtPlugin.cookies = cookies; - loggerSend('Cookies is fetched again through Google Auth', loggerPrefixAudioplayerPluginsLoader); + loggerSend('Cookies is fetched by cron job through Google Auth', loggerPrefixAudioplayerPluginsLoader); }); } } diff --git a/src/commands/audio/pl-remove.command.ts b/src/commands/audio/pl-remove.command.ts index 556cf3d..f869110 100644 --- a/src/commands/audio/pl-remove.command.ts +++ b/src/commands/audio/pl-remove.command.ts @@ -2,7 +2,12 @@ import { CommandArgument, ICommand } from '../../CommandTypes.js'; import { GroupAudio } from './AudioTypes.js'; import { ChatInputCommandInteraction, Message, PermissionsBitField, SlashCommandBuilder } from 'discord.js'; import i18next from 'i18next'; -import { UserPlaylistNamesAutocomplete, UserPlaylistRemoveSong } from '../../schemas/SchemaPlaylist.js'; +import { + PlaylistIsNotExists, + PlaylistSongNotExists, + UserPlaylistNamesAutocomplete, + UserPlaylistRemoveSong +} from '../../schemas/SchemaPlaylist.js'; import { generateSimpleEmbed } from '../../utilities/generateSimpleEmbed.js'; import { generateErrorEmbed } from '../../utilities/generateErrorEmbed.js'; import { ENV } from '../../EnvironmentVariables.js'; @@ -75,6 +80,37 @@ async function plRemoveAndReply( ephemeral: true }); } catch (e) { + if (e instanceof PlaylistIsNotExists) { + await ctx.reply({ + embeds: [ + generateErrorEmbed( + i18next.t('commands:pl_error_playlist_not_exists', { + name: playlistName, + interpolation: { escapeValue: false } + }) + ) + ], + ephemeral: true + }); + return; + } + + if (e instanceof PlaylistSongNotExists) { + await ctx.reply({ + embeds: [ + generateErrorEmbed( + i18next.t('commands:pl_error_song_is_not_exists_in_playlist', { + name: playlistName, + id: songID + 1, + interpolation: { escapeValue: false } + }) + ) + ], + ephemeral: true + }); + return; + } + await ctx.reply({ embeds: [generateErrorEmbed(i18next.t('commands:pl-remove_error_unknown'))], ephemeral: true diff --git a/src/locales/en/commands.json b/src/locales/en/commands.json index 67085f8..41c97f8 100644 --- a/src/locales/en/commands.json +++ b/src/locales/en/commands.json @@ -81,6 +81,7 @@ "pl_arg_name": "playlist name", "pl_arg_song_id": "song id in playlist", "pl_error_playlist_not_exists": "Playlist ``{{name}}`` is not exists", + "pl_error_song_is_not_exists_in_playlist": "Song with ID ``{{id}}`` is not exists in playlist ``{{name}}``", "pl-create_desc": "Create a empty playlist", "pl-create_success": "Playlist ``{{name}}`` created", "pl-create_error_duplicate": "Playlist with name ``{{name}}`` already exists", diff --git a/src/locales/ru/commands.json b/src/locales/ru/commands.json index 0aed42d..2d4aaf7 100644 --- a/src/locales/ru/commands.json +++ b/src/locales/ru/commands.json @@ -81,6 +81,7 @@ "pl_arg_name": "имя плейлиста", "pl_arg_song_id": "номер песни в плейлисте", "pl_error_playlist_not_exists": "Плейлист ``{{name}}`` не существует", + "pl_error_song_is_not_exists_in_playlist": "Песня с ID ``{{id}}`` не существует в плейлисте ``{{name}}``", "pl-create_desc": "Создание пустого плейлиста", "pl-create_success": "Плейлист ``{{name}}`` создан", "pl-create_error_duplicate": "Плейлист с именем ``{{name}}`` уже существует", diff --git a/src/schemas/SchemaPlaylist.ts b/src/schemas/SchemaPlaylist.ts index 46940a8..c826bb3 100644 --- a/src/schemas/SchemaPlaylist.ts +++ b/src/schemas/SchemaPlaylist.ts @@ -87,6 +87,14 @@ export class PlaylistSongIsNotValid extends Error { } } +export class PlaylistSongNotExists extends Error { + constructor(playlistName: string, songID: number) { + super(); + this.name = 'PlaylistSongNotExists'; + this.message = `Song with id ${songID} not exists in playlist ${playlistName}`; + } +} +/* export class PlaylistSongAlreadyInPlaylist extends Error { constructor(playlistName: string, songName: string) { super(); @@ -94,7 +102,7 @@ export class PlaylistSongAlreadyInPlaylist extends Error { this.message = `Song ${songName} already in playlist ${playlistName}`; } } - +*/ export async function UserPlaylistCreate(userID: string, name: string): Promise { const playlist = await UserPlaylistGet(userID, name); if (playlist) throw new PlaylistAlreadyExists(name); @@ -180,6 +188,7 @@ export async function UserPlaylistRemoveSong( if (!playlist) throw new PlaylistIsNotExists(name); const song = playlist.songs[index]; + if (!song) throw new PlaylistSongNotExists(name, index); playlist.songs.splice(index, 1); await playlist.save();