Skip to content

Commit

Permalink
Spotify command interaction bug fixes (#1790)
Browse files Browse the repository at this point in the history
* Spotify command bug fixes

* Fix bug where /spotify slash command wasn't responding
* Fix bug where /spotify matches wasn't responding when playlist
  uncached

* Use enum for spotify actions
  • Loading branch information
taahamahdi authored Dec 11, 2023
1 parent bcd224a commit 19b2828
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions src/commands/game_options/spotify.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { IPCLogger } from "../../logger";
import {
OptionAction,
SPOTIFY_BASE_URL,
SPOTIFY_SHORTHAND_BASE_URL,
} from "../../constants";
import { SPOTIFY_BASE_URL, SPOTIFY_SHORTHAND_BASE_URL } from "../../constants";
import {
clickableSlashCommand,
friendlyFormattedNumber,
Expand Down Expand Up @@ -47,6 +43,12 @@ import type HelpDocumentation from "../../interfaces/help";
const COMMAND_NAME = "spotify";
const logger = new IPCLogger(COMMAND_NAME);

const enum SpotifyCommandAction {
SET = "set",
RESET = "reset",
MATCHES = "matches",
}

export default class SpotifyCommand implements BaseCommand {
aliases = ["playlist"];

Expand All @@ -70,7 +72,7 @@ export default class SpotifyCommand implements BaseCommand {
type: Eris.Constants.ApplicationCommandTypes.CHAT_INPUT,
options: [
{
name: OptionAction.SET,
name: SpotifyCommandAction.SET,
description: i18n.translate(
LocaleType.EN,
"command.spotify.help.description",
Expand Down Expand Up @@ -117,7 +119,7 @@ export default class SpotifyCommand implements BaseCommand {
],
},
{
name: OptionAction.RESET,
name: SpotifyCommandAction.RESET,
description: i18n.translate(
LocaleType.EN,
"misc.interaction.resetOption",
Expand All @@ -142,7 +144,7 @@ export default class SpotifyCommand implements BaseCommand {
options: [],
},
{
name: "matches",
name: SpotifyCommandAction.MATCHES,
description: i18n.translate(
LocaleType.EN,
"command.spotify.help.interaction.matches",
Expand Down Expand Up @@ -200,7 +202,7 @@ export default class SpotifyCommand implements BaseCommand {
{
example: `${clickableSlashCommand(
COMMAND_NAME,
OptionAction.SET,
SpotifyCommandAction.SET,
)} playlist_url:${SPOTIFY_BASE_URL}...`,
explanation: i18n.translate(
guildID,
Expand All @@ -210,7 +212,7 @@ export default class SpotifyCommand implements BaseCommand {
{
example: `${clickableSlashCommand(
COMMAND_NAME,
OptionAction.SET,
SpotifyCommandAction.SET,
)} playlist_url:${SPOTIFY_SHORTHAND_BASE_URL}...`,
explanation: i18n.translate(
guildID,
Expand All @@ -220,7 +222,7 @@ export default class SpotifyCommand implements BaseCommand {
{
example: clickableSlashCommand(
COMMAND_NAME,
OptionAction.RESET,
SpotifyCommandAction.RESET,
),
explanation: i18n.translate(
guildID,
Expand Down Expand Up @@ -528,7 +530,7 @@ export default class SpotifyCommand implements BaseCommand {
{
spotifySet: clickableSlashCommand(
"spotify",
OptionAction.SET,
SpotifyCommandAction.SET,
),
},
),
Expand Down Expand Up @@ -601,12 +603,18 @@ export default class SpotifyCommand implements BaseCommand {
});
}

await sendMessage(
messageContext.textChannelID,
{ attachments },
undefined,
interaction,
);
if (interaction.acknowledged) {
await interaction.createFollowup({
attachments,
});
} else {
await sendMessage(
messageContext.textChannelID,
{ attachments },
undefined,
interaction,
);
}
}

/**
Expand All @@ -620,22 +628,22 @@ export default class SpotifyCommand implements BaseCommand {
const { interactionName, interactionOptions } =
getInteractionValue(interaction);

let playlistURL: string | undefined;
if (interactionName! in OptionAction) {
const action = interactionName as OptionAction;
if (action === OptionAction.RESET) {
playlistURL = undefined;
} else if (action === OptionAction.SET) {
playlistURL = encodeURI(interactionOptions["playlist_url"]);
}
if (
interactionName === SpotifyCommandAction.RESET ||
interactionName === SpotifyCommandAction.SET
) {
const playlistURL =
interactionName === SpotifyCommandAction.SET
? encodeURI(interactionOptions["playlist_url"])
: undefined;

await SpotifyCommand.updateOption(
messageContext,
playlistURL,
interaction,
playlistURL == null,
);
} else if (interactionName === "matches") {
} else if (interactionName === SpotifyCommandAction.MATCHES) {
const showLink = interactionOptions["show_link"] ?? false;
await SpotifyCommand.sendMatchedSongsFile(
interaction,
Expand Down

0 comments on commit 19b2828

Please sign in to comment.