Added ability to list all playlists
This commit is contained in:
@ -33,7 +33,6 @@ import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.xml.sax.SAXException;
|
||||
|
@ -42,6 +42,11 @@ public interface GuildPlaylistRepository extends CrudRepository<GuildPlaylist, L
|
||||
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3")
|
||||
GuildPlaylist findByGuildAndUserIdAndPlaylist(Long guild, Long userId, String playlist);
|
||||
|
||||
List<GuildPlaylist> findByGuild(DiscordGuild guild);
|
||||
|
||||
@Query("SELECT DISTINCT gpl FROM GuildPlaylist gpl LEFT JOIN FETCH gpl.guildPlaylistSongList WHERE gpl.guild.guildId = ?1")
|
||||
List<GuildPlaylist> findByGuildFetchSongs(Long guild);
|
||||
|
||||
List<GuildPlaylist> findByGuildAndUserId(DiscordGuild guild, Long userId);
|
||||
|
||||
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2")
|
||||
|
@ -356,7 +356,7 @@ public class GuildMusicHandler {
|
||||
event.getChannel().sendMessage(sb.toString()).queue();
|
||||
}
|
||||
|
||||
public void adminPlaylist(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
public void adminPlaylist(GuildMessageReceivedEvent event, List<String> commands) throws IOException {
|
||||
if(!isAdmin(event)) return;
|
||||
if (!checkCommands(event, commands, event.getMember().getAsMention() + ", valid commands are +playst list, play, delete")) return;
|
||||
|
||||
@ -527,7 +527,7 @@ public class GuildMusicHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
int longestPlaylist = 0;
|
||||
int longestPlaylist = 10;
|
||||
for(GuildPlaylist gpl : userPlaylist) {
|
||||
if (gpl.getPlaylist().length() > longestPlaylist) longestPlaylist = gpl.getPlaylist().length();
|
||||
}
|
||||
@ -544,8 +544,7 @@ public class GuildMusicHandler {
|
||||
}
|
||||
sb.append("```");
|
||||
event.getChannel().sendMessage("**" + "Currently available playlists for " + event.getMember().getAsMention() + "**").queue((succcess)->
|
||||
event.getChannel().sendMessage(sb.toString()).queue()
|
||||
);
|
||||
event.getChannel().sendMessage(sb.toString()).queue());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -622,9 +621,30 @@ public class GuildMusicHandler {
|
||||
|
||||
}
|
||||
|
||||
private void listAllPlaylists(GuildMessageReceivedEvent event) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
private void listAllPlaylists(GuildMessageReceivedEvent event) throws IOException {
|
||||
List<GuildPlaylist> userPlaylist = guildSongRepoService.getGuildPlaylistRepo().findByGuildFetchSongs(event.getGuild().getIdLong());
|
||||
if (userPlaylist == null || userPlaylist.isEmpty()) {
|
||||
event.getChannel().sendMessage(event.getAuthor().getAsMention() + ", there are no playlists for this guild").queue();
|
||||
return;
|
||||
}
|
||||
int longestPlaylist = 10;
|
||||
for(GuildPlaylist gpl : userPlaylist) {
|
||||
if (gpl.getPlaylist().length() > longestPlaylist) longestPlaylist = gpl.getPlaylist().length();
|
||||
}
|
||||
|
||||
String fmt = "%6s | %-" + longestPlaylist +"s | %s%n";
|
||||
|
||||
StringBuilder sb = new StringBuilder("```");
|
||||
sb.append(String.format(fmt, "", "Playlist", "Song Count"));
|
||||
sb.append(StringUtils.repeat("-", 24 + longestPlaylist)).append("\n");
|
||||
|
||||
int count = 0;
|
||||
for(GuildPlaylist gpl : userPlaylist) {
|
||||
sb.append(String.format(fmt, ++count, gpl.getPlaylist(), gpl.getGuildPlaylistSongList().size()));
|
||||
}
|
||||
sb.append("```");
|
||||
event.getChannel().sendMessage("**Playlists for " + event.getGuild().getName() + "**").queue((succcess)->
|
||||
event.getChannel().sendMessage(sb.toString()).queue());
|
||||
}
|
||||
|
||||
private void deleteUserPlayList(GuildMessageReceivedEvent event, List<String> commands) {
|
||||
|
Reference in New Issue
Block a user