{"size": 2739, "ext": "js", "max_stars_repo_path": "Commands/Music/loop.js", "max_stars_repo_name": "Nikoloz-Grigalashvili/BTU-Bot", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "Commands/Music/loop.js", "max_issues_repo_name": "Nikoloz-Grigalashvili/BTU-Bot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Commands/Music/loop.js", "max_forks_repo_name": "Nikoloz-Grigalashvili/BTU-Bot", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.39, "max_line_length": 142, "alphanum_fraction": 0.5589631252}
const Command = require("../../Structures/Command.js");
const { QueueRepeatMode } = require("discord-player");
const Discord = require("discord.js");

module.exports = new Command({
  name: "loop",
  description: "🎵 Loop The Playlist",
  type: "SLASH",
  options: [
    {
      name: "type",
      description: "Choose Loop Type",
      type: "INTEGER",
      required: true,
      choices: [
        {
          name: "Queue",
          value: QueueRepeatMode.QUEUE,
        },
        {
          name: "Song",
          value: QueueRepeatMode.TRACK,
        },
        {
          name: "Autoplay",
          value: QueueRepeatMode.AUTOPLAY,
        },
        {
          name: "OFF",
          value: QueueRepeatMode.OFF,
        },
      ],
    },
  ],

  async run(interaction, args, client) {
    const player = client.player;
    const queue = player.getQueue(interaction.guild);
    if (!queue?.playing)
      return interaction.reply({
        content: "Music Is Not Being Played",
      });

    if (
      interaction.user.id !== queue.current.requestedBy.id &&
      !interaction.member.roles.cache.some((r) => r.name === "DJ")
    ) {
      return interaction.reply({
        content:
          "Current Song Must Be Requested By You Or You Must Have DJ Role To Use This Command",
        ephemeral: true,
      });
    }

    const mode = interaction.options.getInteger("type");
    const modeBefore = queue.repeatMode;
    const loopBefore =
      modeBefore === QueueRepeatMode.TRACK
        ? "Song"
        : modeBefore === QueueRepeatMode.QUEUE
        ? "Queue"
        : modeBefore === QueueRepeatMode.AUTOPLAY
        ? "Autoplay"
        : "OFF";

    queue.setRepeatMode(mode);

    const loopAfter =
      mode === QueueRepeatMode.TRACK
        ? "Song"
        : mode === QueueRepeatMode.QUEUE
        ? "Queue"
        : mode === QueueRepeatMode.AUTOPLAY
        ? "Autoplay"
        : "OFF";

    const Logo = new Discord.MessageAttachment("./Pictures/BTULogo.png");
    const embed = new Discord.MessageEmbed();
    embed
      .setTitle("Loop Mode Changed")
      .setDescription(`From: \`${loopBefore}\`, To: \`${loopAfter}\``)
      .setAuthor({
        name: queue.current.requestedBy.username,
        iconURL: queue.current.requestedBy.displayAvatarURL({ dynamic: true }),
      })
      .addFields({
        name: "Now Playing",
        value: `<a:CatJam:924585442450489404> | [**\`${queue.current.title}\`**](${queue.current.url}) - <@!${queue.current.requestedBy.id}>`,
      })
      .setColor("PURPLE")
      .setFooter({
        text: `BTU `,
        iconURL: "attachment://BTULogo.png",
      })
      .setTimestamp();

    return interaction.reply({ embeds: [embed], files: [Logo] });
  },
});
