Skip to content

Commit

Permalink
feat: commands run method returning boolean
Browse files Browse the repository at this point in the history
BREAKING CHANGE: commands `run` method returning boolean
  • Loading branch information
larsrickert committed Jun 17, 2022
1 parent f97dc90 commit 3031a21
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 19 deletions.
6 changes: 4 additions & 2 deletions src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export const createAddCommand: CreateCommandFunc = (playerManager, options) => {
false,
options
);
if (!searchResult) return;
if (!searchResult) return false;

if (searchResult.playlist) {
return await interaction.followUp({
await interaction.followUp({
content: playerManager.translations.add.successPlaylist.replace(
"{playlist}",
urlToMarkdown(
Expand All @@ -35,6 +35,7 @@ export const createAddCommand: CreateCommandFunc = (playerManager, options) => {
)
),
});
return true;
}

await interaction.followUp({
Expand All @@ -43,6 +44,7 @@ export const createAddCommand: CreateCommandFunc = (playerManager, options) => {
trackToMarkdown(searchResult.tracks[0], true)
),
});
return true;
},
};
};
4 changes: 3 additions & 1 deletion src/commands/clear.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const createClearCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const count = player.clear();
Expand All @@ -24,6 +25,7 @@ export const createClearCommand: CreateCommandFunc = (
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
1 change: 1 addition & 0 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const createHelpCommand = (
],
ephemeral: true,
});
return true;
},
};
};
7 changes: 5 additions & 2 deletions src/commands/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ export const createPauseCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const paused = player.setPause(true);
if (!paused) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.pause.failure,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.reply({
content: playerManager.translations.pause.success,
ephemeral: options?.ephemeral,
});
return true;
},
};
};
6 changes: 4 additions & 2 deletions src/commands/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export const createPlayCommand: CreateCommandFunc = (
true,
options
);
if (!searchResult) return;
if (!searchResult) return false;

if (searchResult.playlist) {
return await interaction.followUp({
await interaction.followUp({
content: playerManager.translations.play.successPlaylist.replace(
"{playlist}",
urlToMarkdown(
Expand All @@ -37,6 +37,7 @@ export const createPlayCommand: CreateCommandFunc = (
)
),
});
return true;
}

await interaction.followUp({
Expand All @@ -45,6 +46,7 @@ export const createPlayCommand: CreateCommandFunc = (
trackToMarkdown(searchResult.tracks[0])
),
});
return true;
},
};
};
7 changes: 5 additions & 2 deletions src/commands/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@ export const createQueueCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const currentTrack = player.getCurrentTrack();
const tracks = player.getQueue();

if (!currentTrack || !tracks.length) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.queue.empty,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

let content = `>>> **Queue (${tracks.length})**`;
Expand All @@ -47,6 +49,7 @@ export const createQueueCommand: CreateCommandFunc = (
}

await interaction.reply({ content, ephemeral: options?.ephemeral });
return true;
},
};
};
4 changes: 3 additions & 1 deletion src/commands/repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export const createRepeatCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const mode = interaction.options.getInteger(
Expand All @@ -56,6 +57,7 @@ export const createRepeatCommand: CreateCommandFunc = (
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
7 changes: 5 additions & 2 deletions src/commands/resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@ export const createResumeCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const paused = player.setPause(false);
if (!paused) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.resume.failure,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.reply({
content: playerManager.translations.resume.success,
ephemeral: options?.ephemeral,
});
return true;
},
};
};
4 changes: 3 additions & 1 deletion src/commands/shuffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const createShuffleCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

player.shuffle();
Expand All @@ -22,6 +23,7 @@ export const createShuffleCommand: CreateCommandFunc = (
content: playerManager.translations.shuffle.success,
ephemeral: options?.ephemeral,
});
return true;
},
};
};
7 changes: 5 additions & 2 deletions src/commands/skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@ export const createSkipCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const track = player.skip();

if (!track) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.skip.failure,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.reply({
Expand All @@ -33,6 +35,7 @@ export const createSkipCommand: CreateCommandFunc = (
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
4 changes: 3 additions & 1 deletion src/commands/song.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export const createSongCommand: CreateCommandFunc = (
const currentTrack = player?.getCurrentTrack();

if (!player || !currentTrack) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.reply({
Expand All @@ -26,6 +27,7 @@ export const createSongCommand: CreateCommandFunc = (
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
4 changes: 3 additions & 1 deletion src/commands/stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ export const createStopCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

player.stop();
Expand All @@ -22,6 +23,7 @@ export const createStopCommand: CreateCommandFunc = (
content: playerManager.translations.stop.success,
ephemeral: options?.ephemeral,
});
return true;
},
};
};
5 changes: 4 additions & 1 deletion src/commands/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export const createSetVolumeCommand: CreateCommandFunc = (
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
return await interaction.reply({
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

const volume = interaction.options.getNumber("volume", true);
Expand All @@ -34,6 +35,7 @@ export const createSetVolumeCommand: CreateCommandFunc = (
content: playerManager.translations.setvolume.failure,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.reply({
Expand All @@ -43,6 +45,7 @@ export const createSetVolumeCommand: CreateCommandFunc = (
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
2 changes: 1 addition & 1 deletion src/types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
import en from "../languages/en.json";
import { PlayerManager } from "../player-manager";

export interface Command<T = unknown> extends ChatInputApplicationCommandData {
export interface Command<T = boolean> extends ChatInputApplicationCommandData {
run: (interaction: CommandInteraction<"cached">) => Promise<T>;
}

Expand Down

0 comments on commit 3031a21

Please sign in to comment.