Change add music + music info display

This commit is contained in:
SebClem 2022-05-15 22:44:38 +02:00
parent d9d5e5d880
commit 79c6f1b5ae
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
2 changed files with 48 additions and 8 deletions

View File

@ -1,9 +1,13 @@
package net.Broken.Tools; package net.Broken.Tools;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.audio.UserAudioTrack;
import net.Broken.audio.Youtube.SearchResult; import net.Broken.audio.Youtube.SearchResult;
import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import java.awt.*; import java.awt.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -17,22 +21,52 @@ import java.util.Map;
public class EmbedMessageUtils { public class EmbedMessageUtils {
public static EmbedBuilder getError(String message) { public static EmbedBuilder getError(String message) {
EmbedBuilder temp = new EmbedBuilder().setTitle(":warning: Error! :warning:").setColor(Color.red).setDescription(message); EmbedBuilder temp = new EmbedBuilder().setTitle(":warning: Error!").setColor(Color.red).setDescription(message);
return temp; return temp;
} }
public static MessageEmbed getMusicError(String message) { public static MessageEmbed getMusicError(String message) {
return new EmbedBuilder().setTitle(":warning: Musique Error :warning:").setDescription(":arrow_right: " + message).setFooter("'//help music' for more info.", MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).setColor(Color.red).setFooter(MainBot.url, MainBot.jda.getSelfUser().getAvatarUrl()).build(); return new EmbedBuilder().setTitle(":warning: Musique Error").setDescription(":arrow_right: " + message).setFooter("'//help music' for more info.", MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).setColor(Color.red).setFooter(MainBot.url, MainBot.jda.getSelfUser().getAvatarUrl()).build();
} }
public static MessageEmbed getMusicOk(String message) { public static MessageEmbed getMusicOk(String message) {
EmbedBuilder temp = new EmbedBuilder().setTitle(":loud_sound: Music :loud_sound:").setDescription(message).setColor(Color.green); // TODO better display for different action (add icon ?)
EmbedBuilder temp = new EmbedBuilder().setTitle(":loud_sound: " + message).setColor(Color.green);
return buildStandar(temp);
}
public static MessageEmbed getMusicInfo(AudioTrackInfo info, UserAudioTrack userAudioTrack) {
EmbedBuilder temp = new EmbedBuilder().setTitle(":loud_sound: Currently playing")
.addField("Title", info.title, false)
.addField("Author", info.author, false)
.addField("URL", info.uri, false)
.addField("Submitted by", userAudioTrack.getSubmittedUser().getName(), false)
.setThumbnail("https://img.youtube.com/vi/" + info.identifier + "/hqdefault.jpg")
.setColor(Color.green);
return buildStandar(temp);
}
public static MessageEmbed getMusicAdded(AudioTrackInfo info, Member member, int playlistSize){
EmbedBuilder temp = new EmbedBuilder()
.addField("Title", info.title, false)
.addField("Author", info.author, false)
.addField("Submitted by", member.getEffectiveName(), true)
.setThumbnail("https://img.youtube.com/vi/" + info.identifier + "/hqdefault.jpg")
.setColor(Color.green);
if(playlistSize != -1){
temp.addField("Loaded tracks", Integer.toString(playlistSize), true)
.setTitle(":loud_sound: Playlist added to queue");
}
else {
temp.setTitle(":loud_sound: Track added to queue");
}
temp.addField("URL", info.uri, false);
return buildStandar(temp); return buildStandar(temp);
} }
public static MessageEmbed getFlushError(String message) { public static MessageEmbed getFlushError(String message) {
return buildStandar(new EmbedBuilder().setTitle(":warning: Flush Error :warning: ").setDescription(message).setColor(Color.red)); return buildStandar(new EmbedBuilder().setTitle(":warning: Flush Error").setDescription(message).setColor(Color.red));
} }
@ -57,7 +91,7 @@ public class EmbedMessageUtils {
} }
public static MessageEmbed getReportUsersError() { public static MessageEmbed getReportUsersError() {
return new EmbedBuilder().setTitle(":warning: Command error :warning: ").setDescription("").setColor(Color.red).setFooter("'//help move' for more info.", MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).build(); return new EmbedBuilder().setTitle(":warning: Command error").setDescription("").setColor(Color.red).setFooter("'//help move' for more info.", MainBot.jda.getSelfUser().getAvatarUrl()).setTimestamp(Instant.now()).build();
} }

View File

@ -11,6 +11,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.Broken.MainBot; import net.Broken.MainBot;
import net.Broken.RestApi.Data.UserAudioTrackData; import net.Broken.RestApi.Data.UserAudioTrackData;
import net.Broken.Tools.EmbedMessageUtils; import net.Broken.Tools.EmbedMessageUtils;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Message;
@ -86,7 +87,9 @@ public class AudioM {
public void trackLoaded(AudioTrack track) { public void trackLoaded(AudioTrack track) {
logger.info("[" + guild + "] Single Track detected!"); logger.info("[" + guild + "] Single Track detected!");
UserAudioTrack uat = new UserAudioTrack(event.getUser(), track); UserAudioTrack uat = new UserAudioTrack(event.getUser(), track);
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Add " + track.getInfo().title + " to playlist")).build(); Message message = new MessageBuilder()
.setEmbeds(EmbedMessageUtils.getMusicAdded(track.getInfo(), event.getMember(), -1))
.build();
event.getHook().sendMessage(message).queue(); event.getHook().sendMessage(message).queue();
play(guild, voiceChannel, musicManager, uat, onHead); play(guild, voiceChannel, musicManager, uat, onHead);
} }
@ -95,7 +98,10 @@ public class AudioM {
public void playlistLoaded(AudioPlaylist playlist) { public void playlistLoaded(AudioPlaylist playlist) {
logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit); logger.info("[" + guild + "] Playlist detected! Limit: " + playlistLimit);
AudioTrack firstTrack = playlist.getSelectedTrack(); AudioTrack firstTrack = playlist.getSelectedTrack();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk("Add " + firstTrack.getInfo().title + " and 30 first videos to playlist !")).build(); int size = Math.min(playlist.getTracks().size(), playlistLimit);
Message message = new MessageBuilder()
.setEmbeds(EmbedMessageUtils.getMusicAdded(firstTrack.getInfo(), event.getMember(), size))
.build();
event.getHook().sendMessage(message).queue(); event.getHook().sendMessage(message).queue();
playListLoader(playlist, playlistLimit, event.getUser(), onHead); playListLoader(playlist, playlistLimit, event.getUser(), onHead);
} }
@ -247,7 +253,7 @@ public class AudioM {
GuildMusicManager musicManager = getGuildAudioPlayer(); GuildMusicManager musicManager = getGuildAudioPlayer();
AudioTrackInfo info = musicManager.scheduler.getInfo(); AudioTrackInfo info = musicManager.scheduler.getInfo();
UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack(); UserAudioTrack userAudioTrack = musicManager.scheduler.getCurrentPlayingTrack();
Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicOk(info.title + "\n" + info.uri + "\nSubmitted by: " + userAudioTrack.getSubmittedUser().getName())).build(); Message message = new MessageBuilder().setEmbeds(EmbedMessageUtils.getMusicInfo(info, userAudioTrack)).build();
event.getHook().sendMessage(message).queue(); event.getHook().sendMessage(message).queue();
} }