Skip to content

Commit

Permalink
Playlist with zero matches/unmatched error handling (#2052)
Browse files Browse the repository at this point in the history
* Playlist with zero matches/unmatched error handling

* Reset playlist

* Rseet option in reloadSongs

* lint
  • Loading branch information
Brainicism authored Apr 3, 2024
1 parent 371d534 commit c5564ca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/commands/game_options/playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,29 @@ export default class PlaylistCommand implements BaseCommand {
});
}

if (attachments.length === 0) {
logger.warn(
`Playlist ${kmqPlaylistIdentifier} unexpectedly empty in sendMatchedSongsFile. playlist = ${JSON.stringify(playlist)}`,
);

await sendErrorMessage(
messageContext,
{
title: i18n.translate(
guildID,
"command.playlist.noMatches.title",
),
description: i18n.translate(
guildID,
"command.playlist.noMatches.description",
),
},
interaction,
);

return;
}

if (interaction.acknowledged) {
await interaction.createFollowup({
attachments,
Expand Down
19 changes: 19 additions & 0 deletions src/structures/song_selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import {
setDifference,
shufflePartitionedArray,
} from "../helpers/utils";
import { getDebugLogHeader } from "../helpers/discord_utils";
import ArtistType from "../enums/option_types/artist_type";
import EnvVariableManager from "../env_variable_manager";
import GameOption from "../enums/game_option_name";
import GameRound from "./game_round";
import LanguageType from "../enums/option_types/language_type";
import OstPreference from "../enums/option_types/ost_preference";
Expand Down Expand Up @@ -279,6 +281,12 @@ export default class SongSelector {
this.guildPreference.gameOptions.forcePlaySongID
) {
this.selectedSongs = await this.querySelectedSongs();
if (messageContext) {
logger.error(
`${getDebugLogHeader(messageContext)} | Returning null matchedPlaylist for either non-playlist ${!kmqPlaylistIdentifier} or forceplay is active ${this.guildPreference.gameOptions.forcePlaySongID}`,
);
}

return null;
}

Expand All @@ -289,6 +297,17 @@ export default class SongSelector {
interaction!,
);

if (
playlist.unmatchedSongs.length === 0 &&
playlist.matchedSongs.length === 0
) {
logger.warn(
`Playlist ${kmqPlaylistIdentifier} unexpectedly has 0 matched/unmatched songs in reloadSongs, resetting playlist. playlist = ${JSON.stringify(playlist)}`,
);

await this.guildPreference.reset(GameOption.PLAYLIST_ID);
}

this.selectedSongs = playlist as SelectedSongs;
return playlist;
}
Expand Down

0 comments on commit c5564ca

Please sign in to comment.