Added ability to list all playlists
This commit is contained in:
10
pom.xml
10
pom.xml
@ -19,11 +19,11 @@
|
||||
|
||||
<properties>
|
||||
|
||||
<flyway.version>6.0.6</flyway.version>
|
||||
<mariadb.version>2.5.0</mariadb.version>
|
||||
<flyway.version>6.0.7</flyway.version>
|
||||
<mariadb.version>2.5.1</mariadb.version>
|
||||
<hibernate.version>5.4.6.Final</hibernate.version>
|
||||
<spring.version>5.2.0.RELEASE</spring.version>
|
||||
<spring.boot.version>2.1.9.RELEASE</spring.boot.version>
|
||||
<spring.boot.version>2.2.0.RELEASE</spring.boot.version>
|
||||
<spring.data.version>2.2.0.RELEASE</spring.data.version>
|
||||
<log4j.version>2.12.1</log4j.version>
|
||||
<slf4j.version>1.7.28</slf4j.version>
|
||||
@ -154,7 +154,7 @@
|
||||
<dependency>
|
||||
<groupId>net.dv8tion</groupId>
|
||||
<artifactId>JDA</artifactId>
|
||||
<version>4.0.0_52</version>
|
||||
<version>4.0.0_54</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
@ -194,7 +194,7 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.17</version>
|
||||
<version>8.0.18</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -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