Skip to content

Commit

Permalink
feat(commands): add command seek
Browse files Browse the repository at this point in the history
  • Loading branch information
larsrickert committed Jun 18, 2022
1 parent 9c4597e commit 4fa37e9
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createQueueCommand,
createRepeatCommand,
createResumeCommand,
createSeekCommand,
createSetVolumeCommand,
createShuffleCommand,
createSkipCommand,
Expand Down Expand Up @@ -45,6 +46,7 @@ export const commands: Command[] = [
createStopCommand(playerManager),
createSetVolumeCommand(playerManager),
createRepeatCommand(playerManager),
createSeekCommand(playerManager),
];
commands.push(
createHelpCommand(playerManager, {
Expand Down
53 changes: 53 additions & 0 deletions src/commands/seek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { ApplicationCommandOptionTypes } from "discord.js/typings/enums";
import { CreateCommandFunc } from "../types/commands";
import { formatDuration } from "../utils/player";

export const createSeekCommand: CreateCommandFunc = (
playerManager,
options
) => {
return {
name: "seek",
description: playerManager.translations.seek.description,
options: [
{
name: "time",
description: playerManager.translations.seek.optionDescription,
type: ApplicationCommandOptionTypes.NUMBER,
required: true,
minValue: 0,
},
],
run: async (interaction) => {
const player = playerManager.find(interaction.guildId);
if (!player) {
await interaction.reply({
content: playerManager.translations.global.noGuildPlayer,
ephemeral: options?.ephemeralError ?? true,
});
return false;
}

await interaction.deferReply({ ephemeral: options?.ephemeral });

const time = interaction.options.getNumber("time", true);

const success = await player.seek(time * 1000);
if (!success) {
await interaction.followUp({
content: playerManager.translations.seek.failure,
});
return false;
}

await interaction.followUp({
content: playerManager.translations.seek.success.replace(
"{duration}",
formatDuration(time)
),
ephemeral: options?.ephemeral,
});
return true;
},
};
};
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { createPlayCommand } from "./commands/play";
export { createQueueCommand } from "./commands/queue";
export { createRepeatCommand } from "./commands/repeat";
export { createResumeCommand } from "./commands/resume";
export { createSeekCommand } from "./commands/seek";
export { createShuffleCommand } from "./commands/shuffle";
export { createSkipCommand } from "./commands/skip";
export { createSongCommand } from "./commands/song";
Expand Down
6 changes: 6 additions & 0 deletions src/languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"track": "Song"
},
"success": "✅ Wiederholungsmodus auf \"{mode}\" geändert."
},
"seek": {
"description": "Spult den aktuellen Song zur gegebenen Zeit vor/zurück.",
"optionDescription": "Zeit, zu der gespult werden soll (in Sekunden).",
"success": "✅ Aktueller Song zu {duration} gespult.",
"failure": "❌ Aktueller Song konnte nicht vor/zurückgespult werden."
}
}
6 changes: 6 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,11 @@
"track": "Song"
},
"success": "✅ Set repeat mode to \"{mode}\"."
},
"seek": {
"description": "Seeks the current song to the given time.",
"optionDescription": "Time to seek to (in seconds).",
"success": "✅ Seeked current song to {duration}",
"failure": "❌ Current song could not be seeked."
}
}

0 comments on commit 4fa37e9

Please sign in to comment.