✨ Ajout de la commande /nowplaying, /pause, /volume
This commit is contained in:
parent
e2d61d644a
commit
c7b07a5843
@ -0,0 +1,67 @@
|
||||
package org.camelia.studio.kiss.shot.acerola.commands.audio;
|
||||
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.GuildMusicManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.PlayerManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.interfaces.ISlashCommand;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class NowPlayingCommand implements ISlashCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "nowplaying";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Permet de voir la musique en cours de lecture";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
event.deferReply().queue();
|
||||
|
||||
AudioManager audioManager = event.getGuild().getAudioManager();
|
||||
if (!audioManager.isConnected()) {
|
||||
event.getHook().editOriginal("Je ne suis pas connecté à un canal vocal !").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
|
||||
AudioTrack playingTrack = musicManager.audioPlayer.getPlayingTrack();
|
||||
|
||||
if (playingTrack == null) {
|
||||
event.getHook().editOriginal("La file d'attente est vide.").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
EmbedBuilder embed = new EmbedBuilder();
|
||||
embed.setTitle("En cours de lecture");
|
||||
embed.setColor(Color.ORANGE);
|
||||
embed.addField("Titre", playingTrack.getInfo().title, false);
|
||||
embed.addField("Durée", formatTime(playingTrack.getDuration()), false);
|
||||
embed.addField("Auteur", playingTrack.getInfo().author, false);
|
||||
embed.addField("Lien", playingTrack.getInfo().uri, false);
|
||||
embed.setImage(playingTrack.getInfo().artworkUrl);
|
||||
|
||||
event.getHook().editOriginalEmbeds(embed.build()).queue();
|
||||
}
|
||||
|
||||
private String formatTime(long timeInMillis) {
|
||||
long hours = timeInMillis / 3600000;
|
||||
long minutes = (timeInMillis % 3600000) / 60000;
|
||||
long seconds = (timeInMillis % 60000) / 1000;
|
||||
|
||||
if (hours > 0) {
|
||||
return String.format("%d:%02d:%02d", hours, minutes, seconds);
|
||||
} else {
|
||||
return String.format("%d:%02d", minutes, seconds);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package org.camelia.studio.kiss.shot.acerola.commands.audio;
|
||||
|
||||
import net.dv8tion.jda.api.entities.GuildVoiceState;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.GuildMusicManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.PlayerManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.interfaces.ISlashCommand;
|
||||
|
||||
public class PauseCommand implements ISlashCommand {
|
||||
@Override
|
||||
public String getName() {
|
||||
return "pause";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Permet de mettre en pause la musique en cours de lecture";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
event.deferReply().queue();
|
||||
Member member = event.getMember();
|
||||
GuildVoiceState voiceState = member.getVoiceState();
|
||||
|
||||
if (!voiceState.inAudioChannel()) {
|
||||
event.getHook().editOriginal("Vous devez être connecté à un salon vocal pour utiliser cette commande !")
|
||||
.queue();
|
||||
return;
|
||||
}
|
||||
|
||||
AudioManager audioManager = event.getGuild().getAudioManager();
|
||||
if (!audioManager.isConnected()) {
|
||||
event.getHook().editOriginal("Je ne suis pas connecté à un canal vocal !").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
|
||||
|
||||
boolean isPaused = musicManager.audioPlayer.isPaused();
|
||||
|
||||
musicManager.audioPlayer.setPaused(!isPaused);
|
||||
|
||||
if (isPaused) {
|
||||
event.getHook().editOriginal("La musique a été reprise !").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
event.getHook().editOriginal("La musique est en pause !").queue();
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ public class PlayCommand implements ISlashCommand {
|
||||
Member member = event.getMember();
|
||||
GuildVoiceState voiceState = member.getVoiceState();
|
||||
|
||||
if (!member.getVoiceState().inAudioChannel()) {
|
||||
if (!voiceState.inAudioChannel()) {
|
||||
event.getHook().editOriginal("Vous devez être connecté à un salon vocal pour utiliser cette commande !")
|
||||
.queue();
|
||||
return;
|
||||
@ -64,8 +64,11 @@ public class PlayCommand implements ISlashCommand {
|
||||
}
|
||||
});
|
||||
|
||||
audioManager.openAudioConnection(voiceState.getChannel());
|
||||
PlayerManager.getInstance().getMusicManager(event.getGuild()).audioPlayer.setVolume(25);
|
||||
if (!audioManager.isConnected()) {
|
||||
audioManager.openAudioConnection(voiceState.getChannel());
|
||||
PlayerManager.getInstance().getMusicManager(event.getGuild()).audioPlayer.setVolume(25);
|
||||
}
|
||||
|
||||
PlayerManager.getInstance().loadAndPlay(event.getChannel().asGuildMessageChannel(), url);
|
||||
event.getHook().editOriginal("Chargement du fichier audio en cours...").queue();
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ public class QueueCommand implements ISlashCommand {
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Permet de passer à la musique suivante";
|
||||
return "Permet de voir la file d'attente";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,7 +62,6 @@ public class QueueCommand implements ISlashCommand {
|
||||
// On passe aux musiques suivantes
|
||||
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
|
||||
Queue<AudioTrack> queue = musicManager.scheduler.getQueue();
|
||||
AudioTrack currentTrack = musicManager.audioPlayer.getPlayingTrack();
|
||||
|
||||
if (queue.isEmpty()) {
|
||||
event.getHook().editOriginal("La file d'attente est vide.").queue();
|
||||
|
@ -0,0 +1,51 @@
|
||||
package org.camelia.studio.kiss.shot.acerola.commands.audio;
|
||||
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.GuildMusicManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.audio.PlayerManager;
|
||||
import org.camelia.studio.kiss.shot.acerola.interfaces.ISlashCommand;
|
||||
|
||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
|
||||
import net.dv8tion.jda.api.managers.AudioManager;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class VolumeCommand implements ISlashCommand {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "volume";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Permet de changer le volume du bot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OptionData> getOptions() {
|
||||
return List.of(
|
||||
new OptionData(OptionType.INTEGER, "volume", "Le volume souhaité").setRequired(true).setMinValue(0).setMaxValue(100)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(SlashCommandInteractionEvent event) {
|
||||
event.deferReply().queue();
|
||||
|
||||
AudioManager audioManager = event.getGuild().getAudioManager();
|
||||
if (!audioManager.isConnected()) {
|
||||
event.getHook().editOriginal("Je ne suis pas connecté à un canal vocal !").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(event.getGuild());
|
||||
|
||||
int volume = Integer.parseInt(event.getOption("volume").getAsString());
|
||||
|
||||
musicManager.audioPlayer.setVolume(volume);
|
||||
|
||||
event.getHook().editOriginal("Le volume a été changé à " + volume + "%").queue();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user