2022-03-03 20:56:49 +07:00
import DiscordModule , { HybridInteractionMessage } from "../../utils/DiscordModule" ;
2022-02-28 11:50:47 +07:00
import { Message , CommandInteraction , Interaction , TextChannel } from "discord.js" ;
2022-03-03 20:56:49 +07:00
import { makeErrorEmbed , sendHybridInteractionMessageResponse , makeInfoEmbed } from "../../utils/DiscordMessage" ;
2022-02-28 11:50:47 +07:00
2022-03-03 23:57:30 +07:00
import DiscordMusicPlayer , { DiscordMusicPlayerInstance , DiscordMusicPlayerLoopMode } from "../../providers/DiscordMusicPlayer" ;
2022-01-30 20:10:36 +07:00
const EMBEDS = {
2022-03-03 23:57:30 +07:00
QUEUE : ( data : Message | Interaction , instance : DiscordMusicPlayerInstance ) => {
const queue = instance . queue ;
2022-01-30 20:10:36 +07:00
if ( ! queue . track [ 0 ])
return makeInfoEmbed ({
title : `Queue` ,
description : `The queue is empty!` ,
user : ( data instanceof Interaction ) ? data.user : data.author
});
2022-02-05 00:00:01 +07:00
else {
if ( queue . track . length == 1 ) {
let queueString = `1. [ ${ queue . track [ 0 ]. title } ]( ${ queue . track [ 0 ]. url } )`
return makeInfoEmbed ({
title : `Queue` ,
2022-03-03 23:57:30 +07:00
description : `Now playing ${ instance . getLoopMode () === DiscordMusicPlayerLoopMode . Current ? " (Looping current)" : "" } : [ ${ queue . track [ 0 ]. title } ]( ${ queue . track [ 0 ]. url } ) \ n \ nThere are ${ queue . track . length } song in the queue! \ n ${ queueString } ` ,
2022-02-05 00:00:01 +07:00
user : ( data instanceof Interaction ) ? data.user : data.author
});
}
else if ( queue . track . length >= 10 ) {
let first10 = queue . track . slice ( 0 , 10 );
let queueString = first10 . map (( track , index ) => ` ${ index + 1 } . [ ${ track . title } ]( ${ track . url } )` ). join ( "\n" );
return makeInfoEmbed ({
title : `Queue` ,
2022-03-03 23:57:30 +07:00
description : `Now playing ${ instance . getLoopMode () === DiscordMusicPlayerLoopMode . Current ? " (Looping current)" : "" } : [ ${ queue . track [ 0 ]. title } ]( ${ queue . track [ 0 ]. url } ) \ nUpcoming song: [ ${ queue . track [ 1 ]. title } ]( ${ queue . track [ 1 ]. url } ) \ n \ nThere are ${ queue . track . length } songs in the queue! \ n ${ queueString } \ n ${ queue . track . length > 10 ? `... ${ queue . track . length - 10 } more songs` : "" } ` ,
2022-02-05 00:00:01 +07:00
user : ( data instanceof Interaction ) ? data.user : data.author
});
} else {
let queueString = queue . track . map (( track , index ) => ` ${ index + 1 } . [ ${ track . title } ]( ${ track . url } )` ). join ( "\n" );
return makeInfoEmbed ({
title : `Queue` ,
2022-03-03 23:57:30 +07:00
description : `Now playing ${ instance . getLoopMode () === DiscordMusicPlayerLoopMode . Current ? " (Looping current)" : "" } : [ ${ queue . track [ 0 ]. title } ]( ${ queue . track [ 0 ]. url } ) \ nUpcoming song: [ ${ queue . track [ 1 ]. title } ]( ${ queue . track [ 1 ]. url } ) \ n \ nThere are ${ queue . track . length } songs in the queue! \ n ${ queueString } ` ,
2022-02-05 00:00:01 +07:00
user : ( data instanceof Interaction ) ? data.user : data.author
});
}
}
2022-01-30 22:42:00 +07:00
},
NO_MUSIC_PLAYING : ( data : Message | Interaction ) => {
return makeErrorEmbed ({
title : `There are no music playing` ,
user : ( data instanceof Interaction ) ? data.user : data.author
});
2022-01-30 20:10:36 +07:00
}
}
2022-03-03 20:56:49 +07:00
export default class QueueCommand extends DiscordModule {
public id = "Discord_MusicPlayer_Queue" ;
public commands = [ "queue" , "q" ];
public commandInteractionName = "queue" ;
2022-01-30 20:10:36 +07:00
2022-03-03 20:56:49 +07:00
async GuildOnModuleCommand ( args : any , message : Message ) {
await this . run ( new HybridInteractionMessage ( message ), args );
2022-01-30 20:10:36 +07:00
}
2022-03-03 20:56:49 +07:00
async GuildModuleCommandInteractionCreate ( interaction : CommandInteraction ) {
await this . run ( new HybridInteractionMessage ( interaction ), interaction . options );
2022-01-30 20:10:36 +07:00
}
2022-03-03 20:56:49 +07:00
async run ( data : HybridInteractionMessage , args : any ) {
2022-01-30 20:10:36 +07:00
2022-03-03 20:56:49 +07:00
const guild = data . getGuild ();
2022-01-30 20:10:36 +07:00
2022-03-03 20:56:49 +07:00
if ( ! guild ) return ;
2022-01-30 20:10:36 +07:00
2022-03-03 20:56:49 +07:00
const instance = DiscordMusicPlayer . getGuildInstance ( guild . id );
if ( ! instance ) return await sendHybridInteractionMessageResponse ( data , { embeds : [ EMBEDS . NO_MUSIC_PLAYING ( data . getRaw ())] });
2022-01-30 20:10:36 +07:00
2022-03-03 23:57:30 +07:00
await sendHybridInteractionMessageResponse ( data , { embeds : [ EMBEDS . QUEUE ( data . getRaw (), instance )] });
2022-01-30 20:10:36 +07:00
return ;
}
}