diff --git a/.gitignore b/.gitignore index af48262..9025a13 100644 --- a/.gitignore +++ b/.gitignore @@ -363,4 +363,6 @@ MigrationBackup/ FodyWeavers.xsd # typescript restrictions -dist/ \ No newline at end of file +dist/ +*.js +*.js.map \ No newline at end of file diff --git a/src/commands/music/loop.ts b/src/commands/music/loop.ts index 3d3b145..b018786 100644 --- a/src/commands/music/loop.ts +++ b/src/commands/music/loop.ts @@ -2,11 +2,12 @@ import { design } from "../../config"; import { ColorResolvable, CommandInteraction, MessageEmbed } from "discord.js"; import { MyClient } from "../../types/Client"; +import { loopOption } from "../../types/Types"; export async function run(client: MyClient, ctx: CommandInteraction) { - const query = ctx.options.getString("position"); + const query = ctx.options.getString("option"); if (ctx.guild === null || query === null) return; @@ -19,22 +20,23 @@ export async function run(client: MyClient, ctx: CommandInteraction) { await ctx.deferReply(); - let state: boolean; - - if (!isNaN(Number(query))) { - state = await player.jump(Number(query) - 1); - } else { - state = await player.jump(query); - } + player.repeat(query as loopOption); let embed = new MessageEmbed() - .setColor(design.color as ColorResolvable) - .setTitle("Could not find track specified."); + .setColor(design.color as ColorResolvable); - if (state) { - embed = new MessageEmbed() - .setColor(design.color as ColorResolvable) - .setTitle("Jumped."); + switch (query as loopOption) { + case "LOOP": { + embed.setTitle("Now looping queue."); + break; + } + case "SONG": { + embed.setTitle("Now looping current song."); + break; + } + case "NONE": { + embed.setTitle("After queue end player will be destroyed.") + } } await ctx.editReply({ embeds: [embed] }); diff --git a/src/types/Music.ts b/src/types/Music.ts index 862ab9c..f973ab5 100644 --- a/src/types/Music.ts +++ b/src/types/Music.ts @@ -204,7 +204,7 @@ export class Player { async remove(query: number | string): Promise { if (typeof query === "number" && query < this.queue.length && query >= 0) { - this.queue.splice(query); + this.queue.splice(query, 1); if (query === this.queuePosition) await this.play(); return true; @@ -213,7 +213,7 @@ export class Player { for (let i = 0; i < this.queue.length; i++) { const track = this.queue[i]; if (track.title.toLowerCase().includes(String(query).toLowerCase())) { - this.queue.splice(i); + this.queue.splice(i, 1); if (i === this.queuePosition) await this.play(); return true;