From 8b606215ed02b5f5302fb47e1befcdb88c31153d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 11 Feb 2023 15:37:00 +0100 Subject: [PATCH] add repeat command --- src/commands/music/repeat.ts | 102 +++++++++++++++++++++++++++++++++++ src/locales/fr.json | 18 ++++++- 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 src/commands/music/repeat.ts diff --git a/src/commands/music/repeat.ts b/src/commands/music/repeat.ts new file mode 100644 index 0000000..9c811f7 --- /dev/null +++ b/src/commands/music/repeat.ts @@ -0,0 +1,102 @@ +import { SlashCommandBuilder } from "@discordjs/builders"; +import { QueueRepeatMode } from "discord-player"; +import { ChatInputCommandInteraction, Client } from "discord.js"; +import { getLocale, getLocalizations } from "../../utils/locales"; +import { getFilename } from "../../utils/misc"; + +export default { + scope: () => [], + + data: (client: Client) => { + const filename = getFilename(__filename); + const loc_default = client.locales.get(client.config.default_lang); + if (!loc_default) { + return; + } + + return ( + new SlashCommandBuilder() + .setName(filename.toLowerCase()) + .setDescription(loc_default.get(`c_${filename}_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)) + + // Disable repeat + .addSubcommand((subcommand) => + subcommand + .setName(loc_default.get(`c_${filename}_sub1_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub1_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub1_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub1_desc`)) + ) + + // Repeat current track + .addSubcommand((subcommand) => + subcommand + .setName(loc_default.get(`c_${filename}_sub2_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub2_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub2_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub2_desc`)) + ) + + // Repeat queue + .addSubcommand((subcommand) => + subcommand + .setName(loc_default.get(`c_${filename}_sub3_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub3_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub3_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub3_desc`)) + ) + + // Enable autoplay + .addSubcommand((subcommand) => + subcommand + .setName(loc_default.get(`c_${filename}_sub4_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub4_desc`) ?? "") + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub4_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub4_desc`)) + ) + ); + }, + + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { + const loc_default = client.locales.get(client.config.default_lang); + const filename = getFilename(__filename); + + const loc = getLocale(client, interaction.locale); + const queue = client.player.queues.get(interaction.guildId ?? ""); + + if (queue) { + const subcommand = interaction.options.getSubcommand(); + switch (subcommand) { + // Disable + case loc_default?.get(`c_${filename}_sub1_name`)?.toLowerCase() ?? "": { + queue.setRepeatMode(QueueRepeatMode.OFF); + return interaction.reply(loc.get("c_repeat2")); + } + + // Queue Repeat + case loc_default?.get(`c_${filename}_sub3_name`)?.toLowerCase() ?? "": { + queue.setRepeatMode(QueueRepeatMode.QUEUE); + return interaction.reply(loc.get("c_repeat3") + " " + loc.get("c_repeat6")); + } + + // Autoplay + case loc_default?.get(`c_${filename}_sub4_name`)?.toLowerCase() ?? "": { + queue.setRepeatMode(QueueRepeatMode.AUTOPLAY); + return interaction.reply(loc.get("c_repeat4") + " " + loc.get("c_repeat6")); + } + + // Track repeat + case loc_default?.get(`c_${filename}_sub2_name`)?.toLowerCase() ?? "": { + queue.setRepeatMode(QueueRepeatMode.TRACK); + return interaction.reply( + loc.get("c_repeat5") + ` ${queue.nowPlaying()?.title} ` + loc.get("c_repeat6") + ); + } + } + } + + return await interaction.reply(loc.get("c_repeat1")); + }, +}; diff --git a/src/locales/fr.json b/src/locales/fr.json index ce2afb7..0251f04 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -115,5 +115,21 @@ "c_lyrics_opt1_desc": "Chanson recherchée", "c_lyrics1": "Le bot ne joue rien en ce moment et aucune chanson n'est renseignée.", "c_lyrics2": "Paroles trop longues pour être affichées.", - "c_lyrics3": "Impossible de trouver les paroles pour" + "c_lyrics3": "Impossible de trouver les paroles pour", + "c_repeat_name": "repeat", + "c_repeat_desc": "Commande relative à la répétition des musiques", + "c_repeat_sub1_name": "stop", + "c_repeat_sub1_desc": "Désactive la répétition", + "c_repeat_sub2_name": "track", + "c_repeat_sub2_desc": "Active la répétition pour la chanson en cours", + "c_repeat_sub3_name": "queue", + "c_repeat_sub3_desc": "Active la répétition pour la file actuelle", + "c_repeat_sub4_name": "autoplay", + "c_repeat_sub4_desc": "Active la lecture automatique", + "c_repeat1": "Le bot ne joue rien en ce moment.", + "c_repeat2": "Répétition désactivé.", + "c_repeat3": "Répétition de la file d'attente", + "c_repeat4": "Lecture automatique", + "c_repeat5": "Répétition de la chanson", + "c_repeat6": "activé." }