Skip to content

Commit

Permalink
feat: Add move command
Browse files Browse the repository at this point in the history
  • Loading branch information
hmes98318 committed Oct 19, 2024
1 parent bc7ec8b commit 136b5f1
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/commands/move.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import {
ChatInputCommandInteraction,
Client,
Message
} from "discord.js";
import type { Bot } from "../@types";


export const name = 'move';
export const aliases = ['mv', 'swap', 'change'];
export const description = 'Swap the positions of two songs in the queue';
export const usage = 'move <index1> <index2>';
export const voiceChannel = true;
export const showHelp = true;
export const sendTyping = true;
export const requireAdmin = false;
export const options = [
{
name: "moveindex1",
description: "To swap song position 1",
type: 4,
required: true,
min_value: 1
},
{
name: "moveindex2",
description: "To swap song position 2",
type: 4,
required: true,
min_value: 1
}
];


export const execute = async (bot: Bot, client: Client, message: Message, args: string[]) => {
const player = client.lavashark.getPlayer(message.guild!.id);

if (!player) {
return message.reply({ content: '❌ | There is no music currently playing.', allowedMentions: { repliedUser: false } });
}


if (!player.queue.size) {
return message.reply({ content: '❌ | There is currently no music to be play in the queue.', allowedMentions: { repliedUser: false } });
}


const index1 = parseInt(args[0], 10);
const index2 = parseInt(args[1], 10);

if (isNaN(index1) || isNaN(index2)) {
return message.reply({ content: `❌ | Please enter a valid index range. (1 - ${player.queue.size})`, allowedMentions: { repliedUser: false } });
}


const isSuccess = player.queue.move(index1 - 1, index2 - 1);

if (!isSuccess) {
return message.reply({ content: `❌ | Please enter a valid index range. (1 - ${player.queue.size})`, allowedMentions: { repliedUser: false } });
}


return message.react('👍');
};


export const slashExecute = async (bot: Bot, client: Client, interaction: ChatInputCommandInteraction) => {
const player = client.lavashark.getPlayer(interaction.guild!.id);

if (!player) {
return interaction.editReply({ content: '❌ | There is no music currently playing.', allowedMentions: { repliedUser: false } });
}


if (!player.queue.size) {
return interaction.editReply({ content: '❌ | There is currently no music to be play in the queue.', allowedMentions: { repliedUser: false } });
}


const index1 = Math.floor(interaction.options.getInteger("moveindex1")!);
const index2 = Math.floor(interaction.options.getInteger("moveindex2")!);

const isSuccess = player.queue.move(index1 - 1, index2 - 1);

if (!isSuccess) {
return interaction.editReply({ content: `❌ | Please enter a valid index range. (1 - ${player.queue.size})`, allowedMentions: { repliedUser: false } });
}


return interaction.editReply({ content: `✅ | Song order exchange successful.`, allowedMentions: { repliedUser: false } });
};

0 comments on commit 136b5f1

Please sign in to comment.