From cac8338049b8d5fe8cdeb2fa018181684c652dee Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 15:29:49 +0700 Subject: [PATCH 01/24] Minorfix & Update playlist command names --- .../command/GuildPlaylistCommand/PlayPlaylistCommand.java | 1 - src/main/java/command/JoinCommand.java | 1 - src/main/java/command/PlayUrlCommand.java | 5 +++-- src/main/java/command/ShowPaginatedQueueCommand.java | 1 - .../UserPlaylistCommand/AddTrackToPlaylistCommand.java | 6 +++--- .../command/UserPlaylistCommand/CreatePlaylistCommand.java | 4 ++-- .../command/UserPlaylistCommand/DeletePlaylistCommand.java | 4 ++-- .../UserPlaylistCommand/DeleteTrackFromPlaylistCommand.java | 4 ++-- .../command/UserPlaylistCommand/PlayPlaylistCommand.java | 4 ++-- .../command/UserPlaylistCommand/RenamePlaylistCommand.java | 4 ++-- .../command/UserPlaylistCommand/ShowPlaylistCommand.java | 4 ++-- .../UserPlaylistCommand/ShowPlaylistTrackCommand.java | 4 ++-- src/main/java/command/YoutubeSearchCommand.java | 2 +- src/main/java/command/general/InviteCommand.java | 1 - src/main/java/service/music/HelpProcess.java | 3 ++- 15 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/command/GuildPlaylistCommand/PlayPlaylistCommand.java b/src/main/java/command/GuildPlaylistCommand/PlayPlaylistCommand.java index 4ef8477..5640a64 100644 --- a/src/main/java/command/GuildPlaylistCommand/PlayPlaylistCommand.java +++ b/src/main/java/command/GuildPlaylistCommand/PlayPlaylistCommand.java @@ -10,7 +10,6 @@ import service.music.GuildMusicManager; import service.music.HelpProcess; import service.music.MusicUtils; -import service.music.PremiumService; import java.util.ArrayList; diff --git a/src/main/java/command/JoinCommand.java b/src/main/java/command/JoinCommand.java index 9eb815d..35d0e16 100644 --- a/src/main/java/command/JoinCommand.java +++ b/src/main/java/command/JoinCommand.java @@ -4,7 +4,6 @@ import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; import net.dv8tion.jda.api.entities.VoiceChannel; -import net.dv8tion.jda.api.managers.AudioManager; import service.music.GuildMusicManager; import service.music.HelpProcess; import service.music.MusicUtils; diff --git a/src/main/java/command/PlayUrlCommand.java b/src/main/java/command/PlayUrlCommand.java index bba99de..01955c4 100644 --- a/src/main/java/command/PlayUrlCommand.java +++ b/src/main/java/command/PlayUrlCommand.java @@ -3,7 +3,6 @@ import client.NanoClient; import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.VoiceChannel; import net.dv8tion.jda.api.managers.AudioManager; import org.apache.commons.validator.routines.UrlValidator; @@ -35,7 +34,9 @@ protected void execute(CommandEvent event) { } String args = event.getArgs(); - if (args.isEmpty()) { + String[] schemes = {"http","https"}; // DEFAULT schemes = "http", "https", "ftp" + UrlValidator urlValidator = new UrlValidator(schemes); + if (args.isEmpty() || !urlValidator.isValid(args)) { CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); embedBuilder.addField(":x: | Invalid Arguments", "Example usage: " + event.getClient().getPrefix() + this.name + " " + this.arguments, true); diff --git a/src/main/java/command/ShowPaginatedQueueCommand.java b/src/main/java/command/ShowPaginatedQueueCommand.java index 3c84183..ef768e7 100644 --- a/src/main/java/command/ShowPaginatedQueueCommand.java +++ b/src/main/java/command/ShowPaginatedQueueCommand.java @@ -5,7 +5,6 @@ import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.menu.Paginator; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.exceptions.PermissionException; import service.music.GuildMusicManager; diff --git a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java index 973fbd7..157bd54 100644 --- a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java @@ -20,8 +20,8 @@ public AddTrackToPlaylistCommand(YoutubeClient ytc) { this.client = ytc; - this.name = "add_track_to_user_playlist"; - this.aliases = new String[]{"attup"}; + this.name = "add_track_to_my_playlist"; + this.aliases = new String[]{"attmp"}; this.arguments = ", "; this.help = "Add a new track to user playlist. \n" + "Use coma (,) as separator for each arguments."; @@ -41,7 +41,7 @@ protected void execute(CommandEvent event) embed.addField( ":warning:", "Invalid given arguments.\n" + - "This command need 3 arguments: , .\n" + + "This command need 2 arguments: , .\n" + "Use coma (,) as separator for each arguments.", true); event.reply(embed.build()); diff --git a/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java index 73bc384..c76c790 100644 --- a/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java @@ -14,8 +14,8 @@ public class CreatePlaylistCommand extends UserPlaylistBaseCommand public CreatePlaylistCommand() { - this.name = "create_user_playlist"; - this.aliases = new String[]{"aup", "add_user_playlist", "cup"}; + this.name = "create_new_playlist"; + this.aliases = new String[]{"cnp"}; this.arguments = ""; this.help = "Create a new user playlist. \n" + "Playlist name can't be the same with your other playlist name."; diff --git a/src/main/java/command/UserPlaylistCommand/DeletePlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/DeletePlaylistCommand.java index 67e5244..f2a49b8 100644 --- a/src/main/java/command/UserPlaylistCommand/DeletePlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/DeletePlaylistCommand.java @@ -12,8 +12,8 @@ public class DeletePlaylistCommand extends UserPlaylistBaseCommand { public DeletePlaylistCommand() { - this.name = "delete_user_playlist"; - this.aliases = new String[]{"dup"}; + this.name = "delete_my_playlist"; + this.aliases = new String[]{"dmp"}; this.arguments = ""; this.help = "Delete the existing user playlist."; this.cooldown = 2; diff --git a/src/main/java/command/UserPlaylistCommand/DeleteTrackFromPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/DeleteTrackFromPlaylistCommand.java index 0853616..a4bf8ab 100644 --- a/src/main/java/command/UserPlaylistCommand/DeleteTrackFromPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/DeleteTrackFromPlaylistCommand.java @@ -12,8 +12,8 @@ public class DeleteTrackFromPlaylistCommand extends UserPlaylistBaseCommand { public DeleteTrackFromPlaylistCommand() { - this.name = "delete_track_from_user_playlist"; - this.aliases = new String[]{"dtfup"}; + this.name = "delete_track_from_my_playlist"; + this.aliases = new String[]{"dtfmp"}; this.arguments = ", "; this.help = "Delete existing track from user playlist. \n" + "Use coma (,) as separator for each arguments."; diff --git a/src/main/java/command/UserPlaylistCommand/PlayPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/PlayPlaylistCommand.java index 9130b89..b1295eb 100644 --- a/src/main/java/command/UserPlaylistCommand/PlayPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/PlayPlaylistCommand.java @@ -20,8 +20,8 @@ public PlayPlaylistCommand(NanoClient nano) { this.nano = nano; - this.name = "play_user_playlist"; - this.aliases = new String[]{"pup"}; + this.name = "play_my_playlist"; + this.aliases = new String[]{"pmp"}; this.arguments = ""; this.help = "Play all track from the user's own playlist."; this.cooldown = 2; diff --git a/src/main/java/command/UserPlaylistCommand/RenamePlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/RenamePlaylistCommand.java index 0a96ba9..257615d 100644 --- a/src/main/java/command/UserPlaylistCommand/RenamePlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/RenamePlaylistCommand.java @@ -12,8 +12,8 @@ public class RenamePlaylistCommand extends UserPlaylistBaseCommand { public RenamePlaylistCommand() { - this.name = "rename_user_playlist"; - this.aliases = new String[]{"rup"}; + this.name = "rename_my_playlist"; + this.aliases = new String[]{"rmp"}; this.arguments = " , "; this.help = "Rename user playlist. \n" + "Use coma (,) as separator for old and new playlist name."; diff --git a/src/main/java/command/UserPlaylistCommand/ShowPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/ShowPlaylistCommand.java index 6eaafa2..6187f63 100644 --- a/src/main/java/command/UserPlaylistCommand/ShowPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/ShowPlaylistCommand.java @@ -12,8 +12,8 @@ public class ShowPlaylistCommand extends UserPlaylistBaseCommand { public ShowPlaylistCommand() { - this.name = "show_user_playlist"; - this.aliases = new String[]{"sup"}; + this.name = "my_playlists"; + this.aliases = new String[]{"playlists", "mps", "playlist", "mp"}; this.help = "Show all playlists owned by the user."; this.cooldown = 2; this.category = new Category("User Playlist"); diff --git a/src/main/java/command/UserPlaylistCommand/ShowPlaylistTrackCommand.java b/src/main/java/command/UserPlaylistCommand/ShowPlaylistTrackCommand.java index b74fe2c..b30eb6f 100644 --- a/src/main/java/command/UserPlaylistCommand/ShowPlaylistTrackCommand.java +++ b/src/main/java/command/UserPlaylistCommand/ShowPlaylistTrackCommand.java @@ -12,8 +12,8 @@ public class ShowPlaylistTrackCommand extends UserPlaylistBaseCommand { public ShowPlaylistTrackCommand() { - this.name = "show_user_playlist_track"; - this.aliases = new String[]{"supt"}; + this.name = "my_playlists_track"; + this.aliases = new String[]{"mpt", "playlists_track"}; this.arguments = ""; this.help = "Show all track(s) in the playlist owned by the user."; this.cooldown = 2; diff --git a/src/main/java/command/YoutubeSearchCommand.java b/src/main/java/command/YoutubeSearchCommand.java index c0d98fd..282cb25 100644 --- a/src/main/java/command/YoutubeSearchCommand.java +++ b/src/main/java/command/YoutubeSearchCommand.java @@ -101,7 +101,7 @@ protected void execute(CommandEvent event) "(" + video.getUrl() + ")"; if (!video.getDuration().equals("")) - output += "[" + video.getDuration() + "]"; + output += " [" + video.getDuration() + "]"; // add video data to embed embed.appendDescription(output + "\n"); diff --git a/src/main/java/command/general/InviteCommand.java b/src/main/java/command/general/InviteCommand.java index dc2d763..b93c9bf 100644 --- a/src/main/java/command/general/InviteCommand.java +++ b/src/main/java/command/general/InviteCommand.java @@ -2,7 +2,6 @@ import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandEvent; -import net.dv8tion.jda.api.entities.MessageEmbed; import service.music.CustomEmbedBuilder; import service.music.HelpProcess; diff --git a/src/main/java/service/music/HelpProcess.java b/src/main/java/service/music/HelpProcess.java index b948981..3212636 100644 --- a/src/main/java/service/music/HelpProcess.java +++ b/src/main/java/service/music/HelpProcess.java @@ -1,6 +1,7 @@ -package service.music; +package service.general; import com.jagrosh.jdautilities.command.Command; +import service.music.CustomEmbedBuilder; public class HelpProcess { From ae490f3abe6aef31ab15ce5b8abc3c23f7ccfba8 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 15:36:39 +0700 Subject: [PATCH 02/24] Remove unused script --- .../client/CustomGuildSettingsManager.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/client/CustomGuildSettingsManager.java diff --git a/src/main/java/client/CustomGuildSettingsManager.java b/src/main/java/client/CustomGuildSettingsManager.java deleted file mode 100644 index 34d0cf9..0000000 --- a/src/main/java/client/CustomGuildSettingsManager.java +++ /dev/null @@ -1,36 +0,0 @@ -package client; - -import com.jagrosh.jdautilities.command.GuildSettingsManager; -import net.dv8tion.jda.api.entities.Guild; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; - -public class CustomGuildSettingsManager implements GuildSettingsManager { - - private final Map guildSettings; - - public CustomGuildSettingsManager() { - this.guildSettings = new HashMap<>(); - } - - @Nullable - @Override - public Object getSettings(Guild guild) { - long guildId = Long.parseLong(guild.getId()); - database.Entity.GuildSetting guildSetting = guildSettings.get(guildId); - - // if guild setting is not loaded on memory, then check database - if (guildSetting == null) { - // try load database from database. - // ... - - // if no result. create new default guild setting & submit to database & return default setting - // ... - guildSettings.put(guildId, guildSetting); - } - - return guildSetting; - } -} From a739f197566b548f31ca4eb87cb811e09907ff76 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:35:18 +0700 Subject: [PATCH 03/24] Add new guild settings model --- src/main/java/database/GuildModel.java | 51 ++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/database/GuildModel.java diff --git a/src/main/java/database/GuildModel.java b/src/main/java/database/GuildModel.java new file mode 100644 index 0000000..0de3e2d --- /dev/null +++ b/src/main/java/database/GuildModel.java @@ -0,0 +1,51 @@ +package database; + +import database.Entity.GuildSetting; + +import java.sql.*; + +public class GuildModel extends BaseModel { + + public GuildModel() { + super(); + } + + public void createNew(long id, boolean inDjMode, int defaultVolume, String customPrefix, int maxQueueLength, + int maxPlaylistCount, int maxSongDuration) throws SQLException { + String query = "INSERT INTO GUILD (GUILD_ID, DJ_MODE, DEFAULT_VOLUME, CUSTOM_PREFIX, " + + "MAX_QUEUE_LENGTH, MAX_PLAYLIST_COUNT, MAX_SONG_DURATION) " + + "VALUES (" + id + ", " + inDjMode + ", " + defaultVolume + ", '" + customPrefix + "', " + + maxQueueLength + ", " + maxPlaylistCount + ", " + maxSongDuration + ")"; + this.executeUpdateQuery(query); + } + + public void createDefault(long id, String customPrefix) throws SQLException { + String query = "INSERT INTO GUILD (GUILD_ID, CUSTOM_PREFIX) " + + "VALUES (" + id + ", '" + customPrefix + "')"; + this.executeUpdateQuery(query); + } + + public GuildSetting read(long id) throws SQLException { + GuildSetting guildSetting = null; + + String query = "SELECT * FROM GUILD WHERE ID = " + id; + try (Connection connection = DriverManager.getConnection(this.url,this.username,this.password)) { + try (PreparedStatement statement = connection.prepareStatement(query)) { + try (ResultSet result = statement.executeQuery()) { + if (result.next()) { + boolean djMode = result.getBoolean("DJ_MODE"); + int defaultVolume = result.getInt("DEFAULT_VOLUME"); + String customPrefix = result.getString("CUSTOM_PREFIX"); + int maxQueueLength = result.getInt("MAX_QUEUE_LENGTH"); + int maxPlaylistCount = result.getInt("MAX_PLAYLIST_COUNT"); + int maxSongDuration = result.getInt("MAX_SONG_DURATION"); + guildSetting = new GuildSetting(id, djMode, defaultVolume, customPrefix, + maxQueueLength, maxPlaylistCount, maxSongDuration); + } + } + } + } + + return guildSetting; + } +} From e54324da6a40571048b6d0c87d66e0520add1021 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:35:38 +0700 Subject: [PATCH 04/24] Add new CustomPrefixCommand --- .../command/general/CustomPrefixCommand.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/command/general/CustomPrefixCommand.java diff --git a/src/main/java/command/general/CustomPrefixCommand.java b/src/main/java/command/general/CustomPrefixCommand.java new file mode 100644 index 0000000..c145321 --- /dev/null +++ b/src/main/java/command/general/CustomPrefixCommand.java @@ -0,0 +1,39 @@ +package command.general; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import service.music.GuildMusicManager; + +import java.sql.SQLException; + +public class CustomPrefixCommand extends Command { + + public CustomPrefixCommand() { + this.name = "set_prefix"; + this.arguments = ""; + this.cooldown = 16; + this.guildOnly = true; + this.category = new Category("General"); + } + + @Override + protected void execute(CommandEvent event) { + GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); + + String prefix = event.getArgs().trim(); + + if (prefix.length() > 8) { + event.reply(":x: | Cannot use prefix with characters length greater than 8"); + return; + } + + musicManager.setCustomPrefix(prefix); + + try { + musicManager.savePrefix(event.getGuild().getIdLong()); + event.reply(":white_check_mark: | Added new custom prefix: " + prefix); + } catch (SQLException sqlException) { + event.reply(":x: | Fail to set custom prefix: " + sqlException.getMessage()); + } + } +} From d390eca6adf97ca87b8c213425e2198019451f42 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:36:35 +0700 Subject: [PATCH 05/24] Update command client settings manager to nano. Add prefix command --- src/main/java/Main.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 49b3af5..9303630 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,6 +5,7 @@ import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import command.*; import command.UserPlaylistCommand.CreatePlaylistCommand; +import command.general.CustomPrefixCommand; import command.general.HelpCommand; import command.general.InviteCommand; import command.general.VoteCommand; @@ -58,11 +59,13 @@ public static void main(String[] args) { commandClientBuilder.setCoOwnerIds("456130311365984267"); commandClientBuilder.setActivity(Activity.listening(prefix + "help")); commandClientBuilder.useHelpBuilder(false); + commandClientBuilder.setGuildSettingsManager(nano); // Add Command & Inject Dependencies. // Free Commands commandClientBuilder.addCommand(new VoteCommand(nano)); commandClientBuilder.addCommand(new InviteCommand()); + commandClientBuilder.addCommand(new CustomPrefixCommand()); commandClientBuilder.addCommand(new DjModeCommand(nano)); commandClientBuilder.addCommand(new JoinCommand(nano)); commandClientBuilder.addCommand(new LeaveCommand(nano)); From 5804aeb8aa7c0f9753b4bbb811ad45266b645820 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:37:14 +0700 Subject: [PATCH 06/24] Implements GuildSettingsManager and update getGuildAudioPlayer --- src/main/java/client/NanoClient.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index 484d542..3c458f7 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -1,6 +1,7 @@ package client; import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.jdautilities.command.GuildSettingsManager; import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; @@ -14,12 +15,14 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.TextChannel; +import org.jetbrains.annotations.Nullable; import service.music.*; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; -public class NanoClient { +public class NanoClient implements GuildSettingsManager { private JDA jda; private final Map musicManagers; @@ -46,6 +49,16 @@ public synchronized GuildMusicManager getGuildAudioPlayer(Guild guild) { if (musicManager == null) { musicManager = new GuildMusicManager(playerManager); musicManagers.put(guildId, musicManager); + + try { + musicManager.loadSetting(guildId); + + if (!musicManager.canLoadSetting()) { + musicManager.loadDefaultSetting(guildId); + } + } catch (SQLException sqlException) { + sqlException.printStackTrace(); + } } guild.getAudioManager().setSendingHandler(musicManager.getSendHandler()); @@ -217,4 +230,10 @@ public CustomEmbedBuilder getEmbeddedVoteLink(ClassicUser classicUser, CommandEv return embedBuilder; } + + @Nullable + @Override + public Object getSettings(Guild guild) { + return this.getGuildAudioPlayer(guild); + } } From fd4df4af825f9e7a55037049a3b6cb6d7967bf44 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:37:56 +0700 Subject: [PATCH 07/24] Refactor HelpProcess back to service.music --- src/main/java/service/music/HelpProcess.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/service/music/HelpProcess.java b/src/main/java/service/music/HelpProcess.java index 3212636..b948981 100644 --- a/src/main/java/service/music/HelpProcess.java +++ b/src/main/java/service/music/HelpProcess.java @@ -1,7 +1,6 @@ -package service.general; +package service.music; import com.jagrosh.jdautilities.command.Command; -import service.music.CustomEmbedBuilder; public class HelpProcess { From c482e5a62b39acb43d24b38f29f4cf6fa6f34270 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:42:10 +0700 Subject: [PATCH 08/24] Update guild settings entitiy --- .../java/database/Entity/GuildSetting.java | 104 +++++++++++++++--- 1 file changed, 89 insertions(+), 15 deletions(-) diff --git a/src/main/java/database/Entity/GuildSetting.java b/src/main/java/database/Entity/GuildSetting.java index de9fd2b..c55ba5b 100644 --- a/src/main/java/database/Entity/GuildSetting.java +++ b/src/main/java/database/Entity/GuildSetting.java @@ -1,33 +1,53 @@ package database.Entity; -public class GuildSetting { +import database.GuildModel; + +import java.sql.*; + +public class GuildSetting extends GuildModel { - private long id; - private boolean inDjMode; - private int defaultVolume; - private String customPrefix; - private int maxQueueLength; - private int maxPlaylistCount; - private long maxSongDuration; - private boolean premium; + protected long id; + protected boolean inDjMode; + protected int defaultVolume; + protected String customPrefix; + protected int maxQueueLength; + protected int maxPlaylistCount; + protected int maxSongDuration; + protected boolean premium; + + private boolean canLoadSetting; + + public GuildSetting() { + + } public GuildSetting(long id, boolean inDjMode) { this.id = id; this.inDjMode = inDjMode; + this.canLoadSetting = false; } public GuildSetting(long id, boolean inDjMode, int defaultVolume) { this.id = id; this.inDjMode = inDjMode; this.defaultVolume = defaultVolume; + this.canLoadSetting = false; } - public long getId() { - return id; + public GuildSetting(long id, boolean inDjMode, int defaultVolume, String customPrefix, int maxQueueLength, + int maxPlaylistCount, int maxSongDuration) { + this.id = id; + this.inDjMode = inDjMode; + this.defaultVolume = defaultVolume; + this.customPrefix = customPrefix; + this.maxQueueLength = maxQueueLength; + this.maxPlaylistCount = maxPlaylistCount; + this.maxSongDuration = maxSongDuration; + this.canLoadSetting = false; } - public void setId(long id) { - this.id = id; + public long getId() { + return id; } public boolean isInDjMode() { @@ -70,11 +90,65 @@ public void setMaxPlaylistCount(int maxPlaylistCount) { this.maxPlaylistCount = maxPlaylistCount; } - public long getMaxSongDuration() { + public int getMaxSongDuration() { return maxSongDuration; } - public void setMaxSongDuration(long maxSongDuration) { + public void setMaxSongDuration(int maxSongDuration) { this.maxSongDuration = maxSongDuration; } + + public boolean isPremium() { + return premium; + } + + public void setPremium(boolean premium) { + this.premium = premium; + } + + public boolean canLoadSetting() { + return canLoadSetting; + } + + public void loadDefaultSetting(long id) { + this.inDjMode = false; + this.defaultVolume = 100; + this.customPrefix = null; + this.maxQueueLength = 60; + this.maxPlaylistCount = 20; + this.maxSongDuration = 900000; + this.canLoadSetting = false; + + try { + this.createDefault(id, null); + } catch (SQLException sqlException) { + sqlException.printStackTrace(); + } + } + + public void loadSetting(long id) throws SQLException { + String query = "SELECT * FROM GUILD WHERE GUILD_ID = " + id; + try (Connection connection = DriverManager.getConnection(this.url,this.username,this.password)) { + try (PreparedStatement statement = connection.prepareStatement(query)) { + try (ResultSet result = statement.executeQuery()) { + if (result.next()) { + this.id = id; + this.inDjMode = result.getBoolean("DJ_MODE"); + this.defaultVolume = result.getInt("DEFAULT_VOLUME"); + this.customPrefix = result.getString("CUSTOM_PREFIX"); + this.maxQueueLength = result.getInt("MAX_QUEUE_LENGTH"); + this.maxPlaylistCount = result.getInt("MAX_PLAYLIST_COUNT"); + this.maxSongDuration = result.getInt("MAX_SONG_DURATION"); + + this.canLoadSetting = true; + } + } + } + } + } + + public void savePrefix(long id) throws SQLException { + String query = "UPDATE GUILD SET CUSTOM_PREFIX = '" + this.customPrefix + "' WHERE GUILD_ID = " + id; + this.executeUpdateQuery(query); + } } From 2abc2f3e3f158e4b72a97644eba1aa83918a57d0 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 16:42:59 +0700 Subject: [PATCH 09/24] Update GuildMusicManager implements GuildSettingsProvider and extends GuildSetting entity --- .../java/service/music/GuildMusicManager.java | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/main/java/service/music/GuildMusicManager.java b/src/main/java/service/music/GuildMusicManager.java index 7e73f18..9b6850f 100644 --- a/src/main/java/service/music/GuildMusicManager.java +++ b/src/main/java/service/music/GuildMusicManager.java @@ -1,18 +1,24 @@ package service.music; import com.jagrosh.jdautilities.command.CommandEvent; +import com.jagrosh.jdautilities.command.GuildSettingsProvider; import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import database.Entity.GuildSetting; import net.dv8tion.jda.api.entities.Member; +import org.jetbrains.annotations.Nullable; import org.jsoup.internal.StringUtil; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.ScheduledFuture; /** * Holder for both the player and a track scheduler for one guild. */ -public class GuildMusicManager { +public class GuildMusicManager extends GuildSetting implements GuildSettingsProvider { /** * Audio player for the guild. */ @@ -28,20 +34,22 @@ public class GuildMusicManager { private ScheduledFuture waitingFuture; - private int maxQueueSize = 60; - - private boolean inDjMode = false; - private boolean pauseStatus = false; + private final Set prefixes; + /** * Creates a player and a track scheduler. * @param manager Audio player manager to use for creating the player. */ public GuildMusicManager(AudioPlayerManager manager) { + super(); + player = manager.createPlayer(); scheduler = new TrackScheduler(player); player.addListener(scheduler); + + prefixes = new HashSet<>(); } /** @@ -157,14 +165,13 @@ public void setWaitingFuture(ScheduledFuture waitingFuture) { } public boolean isQueueFull() { - return this.scheduler.getQueue().size() >= this.maxQueueSize; - } - - public boolean isInDjMode() { - return inDjMode; + return this.scheduler.getQueue().size() >= this.maxQueueLength; } - public void setInDjMode(boolean djMode) { - this.inDjMode = djMode; + @Nullable + @Override + public Collection getPrefixes() { + prefixes.add(this.customPrefix); + return prefixes; } } \ No newline at end of file From 63d741b2343197c9239d2bea44a69475f1302541 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Tue, 10 Nov 2020 22:04:53 +0700 Subject: [PATCH 10/24] Fix basemodel & update helpcommand footer --- src/main/java/command/general/HelpCommand.java | 2 +- src/main/java/database/BaseModel.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/command/general/HelpCommand.java b/src/main/java/command/general/HelpCommand.java index ff916c0..5a781d6 100644 --- a/src/main/java/command/general/HelpCommand.java +++ b/src/main/java/command/general/HelpCommand.java @@ -74,7 +74,7 @@ private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda embedBuilder.addField("Detail", "For more detail try `" + commandClient.getPrefix() + "help `", false); - embedBuilder.setFooter("If you need additional help, contact Made Y#8195", + embedBuilder.setFooter("For additional help, contact Made Y#8195", jda.getSelfUser().getEffectiveAvatarUrl()); return embedBuilder.build(); diff --git a/src/main/java/database/BaseModel.java b/src/main/java/database/BaseModel.java index e88a45d..4a60dde 100644 --- a/src/main/java/database/BaseModel.java +++ b/src/main/java/database/BaseModel.java @@ -79,12 +79,11 @@ public int executeUpdateQuery(String query) throws SQLException } catch (SQLException e) { - if (!e.getMessage().equals("Unhandled user-defined exception condition")) + if (!e.getMessage().contains("Unhandled user-defined exception condition")) { throw new SQLException(e); } } return -1; } - } From dd2fb1608b7b05880be7cec631b88da84410f845 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Wed, 11 Nov 2020 22:06:45 +0700 Subject: [PATCH 11/24] Move getEmbeddedVoteLink to MusicService --- src/main/java/client/NanoClient.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index 3c458f7..ce15392 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -213,24 +213,6 @@ public void setWaiter(EventWaiter waiter) { this.waiter = waiter; } - public CustomEmbedBuilder getEmbeddedVoteLink(ClassicUser classicUser, CommandEvent event) { - String voteUrl = ""; - String message = "[Vote]() & use **" + event.getClient().getPrefix() + - "claim** command to claim rewards :>\n" + voteUrl; - - CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); - embedBuilder.setTitle(":headphones: | Thank you for using " + event.getSelfUser().getName() + "!"); - embedBuilder.setAuthor(event.getAuthor().getName() + " Stocks", - event.getAuthor().getEffectiveAvatarUrl(), - event.getAuthor().getEffectiveAvatarUrl()); - embedBuilder.addField("Daily Quota", String.valueOf(classicUser.getDailyQuota()), true); - embedBuilder.addField("Claimed Reward", String.valueOf(classicUser.getRecommendationQuota()), true); - embedBuilder.addField("Increase your stocks :chart_with_upwards_trend: ", message, false); - embedBuilder.setFooter("Have a nice dayy~"); - - return embedBuilder; - } - @Nullable @Override public Object getSettings(Guild guild) { From 03a7bfcf2dc93d45ba363423315780327981e242 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Wed, 11 Nov 2020 22:07:15 +0700 Subject: [PATCH 12/24] Remove unused import --- src/main/java/client/NanoClient.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index ce15392..894dfd1 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -1,6 +1,5 @@ package client; -import com.jagrosh.jdautilities.command.CommandEvent; import com.jagrosh.jdautilities.command.GuildSettingsManager; import com.jagrosh.jdautilities.commons.waiter.EventWaiter; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; @@ -10,7 +9,6 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -import database.Entity.ClassicUser; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; From 9c929029a58a8cb82c5ae430e2813ffa2ef00bce Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Wed, 11 Nov 2020 22:07:33 +0700 Subject: [PATCH 13/24] Add new static method getEmbeddedVoteLink --- src/main/java/service/music/MusicService.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/service/music/MusicService.java b/src/main/java/service/music/MusicService.java index 1422de0..014e61c 100644 --- a/src/main/java/service/music/MusicService.java +++ b/src/main/java/service/music/MusicService.java @@ -6,6 +6,7 @@ import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; +import database.Entity.ClassicUser; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.managers.AudioManager; @@ -104,4 +105,22 @@ public boolean isMemberInVoiceState(Member member) { } return true; } + + public static CustomEmbedBuilder getEmbeddedVoteLink(ClassicUser classicUser, CommandEvent event) { + String voteUrl = ""; + String message = "[Vote]() & use **" + event.getClient().getPrefix() + + "claim** command to claim rewards :>\n" + voteUrl; + + CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); + embedBuilder.setTitle(":headphones: | Thank you for using " + event.getSelfUser().getName() + "!"); + embedBuilder.setAuthor(event.getAuthor().getName() + " Stocks", + event.getAuthor().getEffectiveAvatarUrl(), + event.getAuthor().getEffectiveAvatarUrl()); + embedBuilder.addField("Daily Quota", String.valueOf(classicUser.getDailyQuota()), true); + embedBuilder.addField("Claimed Reward", String.valueOf(classicUser.getRecommendationQuota()), true); + embedBuilder.addField("Increase your stocks :chart_with_upwards_trend: ", message, false); + embedBuilder.setFooter("Have a nice dayy~"); + + return embedBuilder; + } } From 42d044222438ba8d48c2dc18c50ed808f00400bd Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Wed, 11 Nov 2020 22:07:57 +0700 Subject: [PATCH 14/24] Update VoteCommand --- src/main/java/command/general/VoteCommand.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/command/general/VoteCommand.java b/src/main/java/command/general/VoteCommand.java index 1278ec9..f09a49d 100644 --- a/src/main/java/command/general/VoteCommand.java +++ b/src/main/java/command/general/VoteCommand.java @@ -7,6 +7,7 @@ import database.UserModel; import service.music.CustomEmbedBuilder; import service.music.HelpProcess; +import service.music.MusicService; import java.sql.SQLException; import java.util.concurrent.CompletableFuture; @@ -49,7 +50,8 @@ protected void execute(CommandEvent event) { classicUser.setDailyQuota(1); } - CustomEmbedBuilder embedBuilder = this.nanoClient.getEmbeddedVoteLink(classicUser, event); + CustomEmbedBuilder embedBuilder = MusicService.getEmbeddedVoteLink(classicUser, event); + event.reply(embedBuilder.build()); } } From 28698195c41a4e96aafaadd487ec4d73e50fdcfd Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Wed, 11 Nov 2020 22:20:01 +0700 Subject: [PATCH 15/24] Update recommendation command --- src/main/java/command/RecommendationCommand.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/command/RecommendationCommand.java b/src/main/java/command/RecommendationCommand.java index d428fe4..daa8e66 100644 --- a/src/main/java/command/RecommendationCommand.java +++ b/src/main/java/command/RecommendationCommand.java @@ -8,11 +8,8 @@ import com.jagrosh.jdautilities.command.CommandEvent; import database.Entity.ClassicUser; import database.UserModel; -import service.music.CustomEmbedBuilder; +import service.music.*; import net.dv8tion.jda.api.entities.VoiceChannel; -import service.music.GuildMusicManager; -import service.music.HelpProcess; -import service.music.MusicUtils; import java.io.IOException; import java.sql.SQLException; @@ -126,7 +123,7 @@ protected void execute(CommandEvent event) { // if Daily Quota not available & Claimed quota is not available if (classicUser.getRecommendationQuota() < 1) { - CustomEmbedBuilder embedBuilder = this.nanoClient.getEmbeddedVoteLink(classicUser, event); + CustomEmbedBuilder embedBuilder = MusicService.getEmbeddedVoteLink(classicUser, event); event.reply(embedBuilder.build()); return; } From 0551cfd205ae99681ae0fa253afd22e266fc6c10 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 00:26:19 +0700 Subject: [PATCH 16/24] Update HelpCommand --- src/main/java/Main.java | 6 ++- .../java/command/RecommendationCommand.java | 2 +- .../command/general/CustomPrefixCommand.java | 19 ++++++-- .../java/command/general/HelpCommand.java | 48 ++++++++++++------- .../java/database/Entity/GuildSetting.java | 17 ++++++- src/main/java/database/GuildModel.java | 13 +++-- 6 files changed, 73 insertions(+), 32 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9303630..6982e06 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -57,7 +57,7 @@ public static void main(String[] args) { commandClientBuilder.setEmojis("\uD83D\uDC4C", "\u26A0", "\u2717"); commandClientBuilder.setOwnerId("213866895806300161"); // Mandatory commandClientBuilder.setCoOwnerIds("456130311365984267"); - commandClientBuilder.setActivity(Activity.listening(prefix + "help")); + commandClientBuilder.setActivity(Activity.listening("m$help")); commandClientBuilder.useHelpBuilder(false); commandClientBuilder.setGuildSettingsManager(nano); @@ -111,6 +111,9 @@ public static void main(String[] args) { CommandClient commandClient = commandClientBuilder.build(); + // Help command + commandClient.addCommand(new HelpCommand(commandClient)); + // JDA Builder JDABuilder builder = JDABuilder.createDefault(botToken); @@ -126,7 +129,6 @@ public static void main(String[] args) { try { JDA jda = builder.build(); nano.setJda(jda); - commandClient.addCommand(new HelpCommand(commandClient, jda)); } catch (LoginException e) { e.printStackTrace(); } diff --git a/src/main/java/command/RecommendationCommand.java b/src/main/java/command/RecommendationCommand.java index daa8e66..829c7dd 100644 --- a/src/main/java/command/RecommendationCommand.java +++ b/src/main/java/command/RecommendationCommand.java @@ -63,7 +63,7 @@ protected void execute(CommandEvent event) { } // if a number, then check if number is in valid range. - if (requestNumber <= 0 || requestNumber >= 24) { + if (requestNumber <= 0 || requestNumber > 24) { event.reply(":x: | Please provide a number `(1 - 24)`. Example `" +event.getClient().getPrefix()+"recommend 5` to request 5 recommendations"); return; diff --git a/src/main/java/command/general/CustomPrefixCommand.java b/src/main/java/command/general/CustomPrefixCommand.java index c145321..f0f7b47 100644 --- a/src/main/java/command/general/CustomPrefixCommand.java +++ b/src/main/java/command/general/CustomPrefixCommand.java @@ -10,6 +10,7 @@ public class CustomPrefixCommand extends Command { public CustomPrefixCommand() { this.name = "set_prefix"; + this.help = "Set guild custom prefix with maximum 8 characters length."; this.arguments = ""; this.cooldown = 16; this.guildOnly = true; @@ -20,18 +21,30 @@ public CustomPrefixCommand() { protected void execute(CommandEvent event) { GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); - String prefix = event.getArgs().trim(); + if (event.getArgs().isEmpty()) { + event.reply(":x: | Invalid syntax: Argument for prefix is empty. Valid syntax: `" + + event.getClient().getPrefix() + "set_prefix `"); + return; + } + + String prefix = event.getArgs().replace(" ", "").trim(); if (prefix.length() > 8) { event.reply(":x: | Cannot use prefix with characters length greater than 8"); return; } + if (prefix.contains("$")) { + event.reply(":x: | Cannot use prefix that contains `$` and whitespaces"); + return; + } + musicManager.setCustomPrefix(prefix); try { - musicManager.savePrefix(event.getGuild().getIdLong()); - event.reply(":white_check_mark: | Added new custom prefix: " + prefix); + musicManager.saveCurrentPrefix(event.getGuild().getIdLong()); + event.reply(":white_check_mark: | Custom prefix has been set to `" + prefix + + "`, you can test it using `" + prefix + "help`"); } catch (SQLException sqlException) { event.reply(":x: | Fail to set custom prefix: " + sqlException.getMessage()); } diff --git a/src/main/java/command/general/HelpCommand.java b/src/main/java/command/general/HelpCommand.java index 5a781d6..23e7ccb 100644 --- a/src/main/java/command/general/HelpCommand.java +++ b/src/main/java/command/general/HelpCommand.java @@ -3,10 +3,9 @@ import com.jagrosh.jdautilities.command.Command; import com.jagrosh.jdautilities.command.CommandClient; import com.jagrosh.jdautilities.command.CommandEvent; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.entities.MessageEmbed; import service.music.CustomEmbedBuilder; +import service.music.GuildMusicManager; import service.music.HelpProcess; import java.util.HashMap; @@ -15,30 +14,49 @@ public class HelpCommand extends Command { - MessageEmbed messageEmbed; Map commandMap; - public HelpCommand(CommandClient commandClient, JDA jda) { + public HelpCommand(CommandClient commandClient) { this.name = "help"; + this.arguments = " (this argument is optional)"; this.aliases = new String[] { "helps" }; this.help = "Shows help & all commands"; - this.cooldown = 3; + this.cooldown = 4; this.category = new Category("General"); this.guildOnly = false; this.commandMap = new HashMap<>(); - this.messageEmbed = this.createHelpMessageEmbed(commandClient, jda); + + this.initCommandMap(commandClient); } - private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda) { + private void initCommandMap(CommandClient commandClient) { + List commands = commandClient.getCommands(); + + for (Command command : commands) { + // Use memory to access the command in the future. + commandMap.put(command.getName(), command); + for (String alias : command.getAliases()) { + commandMap.put(alias, command); + } + } + commandMap.put("help", this); + } + private CustomEmbedBuilder getHelpEmbedBuilder(CommandClient commandClient, JDA jda, GuildMusicManager musicManager) { List commands = commandClient.getCommands(); - EmbedBuilder embedBuilder = new CustomEmbedBuilder(); + CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); + + String customPrefix = "\nCustom Prefix: `" + musicManager.getCustomPrefix() + "`"; + + if (musicManager.getCustomPrefix() == null || musicManager.getCustomPrefix().equals("null")) { + customPrefix = "\nCustom Prefix: None, please use `set_prefix` command to add custom prefix"; + } // Theme Color: RGB(211, 0, 137) embedBuilder.setTitle("Musicfy Commands"); embedBuilder.setDescription("Prefix: `" + commandClient.getPrefix() + - "` | Alternative prefix: `" + commandClient.getAltPrefix() + "` the bot."); + "` | Alternative prefix: `" + commandClient.getAltPrefix() + "` the bot." + customPrefix); // Temporary memory Map dictionary = new HashMap<>(); @@ -47,12 +65,6 @@ private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda String currentCategoryName = "**" + command.getCategory().getName() + "**"; String categoryValue = "`" + command.getName() + "`, "; - // Use memory to access the command in the future. - commandMap.put(command.getName(), command); - for (String alias : command.getAliases()) { - commandMap.put(alias, command); - } - // Use the temporary memory for Main Embed if (currentCategoryName.equals("Owner")) continue; @@ -77,7 +89,7 @@ private MessageEmbed createHelpMessageEmbed(CommandClient commandClient, JDA jda embedBuilder.setFooter("For additional help, contact Made Y#8195", jda.getSelfUser().getEffectiveAvatarUrl()); - return embedBuilder.build(); + return embedBuilder; } @Override @@ -101,6 +113,8 @@ protected void execute(CommandEvent event) { return; } - event.reply(this.messageEmbed); + + event.reply(this.getHelpEmbedBuilder(event.getClient(), event.getJDA(), + event.getClient().getSettingsFor(event.getGuild())).build()); } } diff --git a/src/main/java/database/Entity/GuildSetting.java b/src/main/java/database/Entity/GuildSetting.java index c55ba5b..96c00fd 100644 --- a/src/main/java/database/Entity/GuildSetting.java +++ b/src/main/java/database/Entity/GuildSetting.java @@ -127,7 +127,10 @@ public void loadDefaultSetting(long id) { } public void loadSetting(long id) throws SQLException { - String query = "SELECT * FROM GUILD WHERE GUILD_ID = " + id; + String query = "SELECT * FROM GUILD JOIN GUILD_SETTINGS " + + "ON GUILD.GUILD_SETTINGS_ID = GUILD_SETTINGS.GUILD_SETTINGS_ID " + + "WHERE GUILD_ID = " + id; + try (Connection connection = DriverManager.getConnection(this.url,this.username,this.password)) { try (PreparedStatement statement = connection.prepareStatement(query)) { try (ResultSet result = statement.executeQuery()) { @@ -147,8 +150,18 @@ public void loadSetting(long id) throws SQLException { } } - public void savePrefix(long id) throws SQLException { + public void saveCurrentPrefix(long id) throws SQLException { String query = "UPDATE GUILD SET CUSTOM_PREFIX = '" + this.customPrefix + "' WHERE GUILD_ID = " + id; this.executeUpdateQuery(query); } + + public void saveCurrentVolume(long id) throws SQLException { + String query = "UPDATE GUILD SET DEFAULT_VOLUME = " + this.defaultVolume + " WHERE GUILD_ID = " + id; + this.executeUpdateQuery(query); + } + + public void saveCurrentDjMode(long id) throws SQLException { + String query = "UPDATE GUILD SET DJ_MODE = " + this.isInDjMode() + " WHERE GUILD_ID = " + id; + this.executeUpdateQuery(query); + } } diff --git a/src/main/java/database/GuildModel.java b/src/main/java/database/GuildModel.java index 0de3e2d..2d6b759 100644 --- a/src/main/java/database/GuildModel.java +++ b/src/main/java/database/GuildModel.java @@ -10,12 +10,9 @@ public GuildModel() { super(); } - public void createNew(long id, boolean inDjMode, int defaultVolume, String customPrefix, int maxQueueLength, - int maxPlaylistCount, int maxSongDuration) throws SQLException { - String query = "INSERT INTO GUILD (GUILD_ID, DJ_MODE, DEFAULT_VOLUME, CUSTOM_PREFIX, " + - "MAX_QUEUE_LENGTH, MAX_PLAYLIST_COUNT, MAX_SONG_DURATION) " + - "VALUES (" + id + ", " + inDjMode + ", " + defaultVolume + ", '" + customPrefix + "', " + - maxQueueLength + ", " + maxPlaylistCount + ", " + maxSongDuration + ")"; + public void createNew(long id, boolean inDjMode, int defaultVolume, String customPrefix) throws SQLException { + String query = "INSERT INTO GUILD (GUILD_ID, DJ_MODE, DEFAULT_VOLUME, CUSTOM_PREFIX,) " + + "VALUES (" + id + ", " + inDjMode + ", " + defaultVolume + ", '" + customPrefix + "', )"; this.executeUpdateQuery(query); } @@ -28,7 +25,9 @@ public void createDefault(long id, String customPrefix) throws SQLException { public GuildSetting read(long id) throws SQLException { GuildSetting guildSetting = null; - String query = "SELECT * FROM GUILD WHERE ID = " + id; + String query = "SELECT * FROM GUILD JOIN GUILD_SETTINGS " + + "ON GUILD.GUILD_SETTINGS_ID = GUILD_SETTINGS.GUILD_SETTINGS_ID " + + "WHERE GUILD_ID = " + id; try (Connection connection = DriverManager.getConnection(this.url,this.username,this.password)) { try (PreparedStatement statement = connection.prepareStatement(query)) { try (ResultSet result = statement.executeQuery()) { From c6aba64f89697d1db175a5911cb7c00c2d9fb4ec Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 12:04:05 +0700 Subject: [PATCH 17/24] Change hardcoded duration with musicManager.getMaxSongDuration --- .../java/service/music/AudioLoadResultHandlerKeyword.java | 4 ++-- src/main/java/service/music/AudioLoadResultHandlerUrl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java index 4b1267e..3ca11fa 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java +++ b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java @@ -22,7 +22,7 @@ public AudioLoadResultHandlerKeyword(GuildMusicManager musicManager, TextChannel @Override public void trackLoaded(AudioTrack track) { - if (channel != null && track.getDuration() > 900000) { + if (channel != null && track.getDuration() > musicManager.getMaxSongDuration()) { String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; channel.sendMessage(errorMessage).queue(); return; @@ -55,7 +55,7 @@ public void trackLoaded(AudioTrack track) { @Override public void playlistLoaded(AudioPlaylist playlist) { for (AudioTrack track : playlist.getTracks()) { - if (track.getDuration() > 900000) { + if (track.getDuration() > musicManager.getMaxSongDuration()) { continue; } track.setUserData(requester); diff --git a/src/main/java/service/music/AudioLoadResultHandlerUrl.java b/src/main/java/service/music/AudioLoadResultHandlerUrl.java index d8d365c..a444961 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerUrl.java +++ b/src/main/java/service/music/AudioLoadResultHandlerUrl.java @@ -24,7 +24,7 @@ public AudioLoadResultHandlerUrl(GuildMusicManager musicManager, TextChannel cha @Override public void trackLoaded(AudioTrack track) { - if (channel != null && track.getDuration() > 900000) { + if (channel != null && track.getDuration() > musicManager.getMaxSongDuration()) { String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; channel.sendMessage(errorMessage).queue(); return; @@ -57,7 +57,7 @@ public void trackLoaded(AudioTrack track) { public void playlistLoaded(AudioPlaylist playlist) { int addedSize = 0; for (AudioTrack track : playlist.getTracks()) { - if (track.getDuration() > 900000) { + if (track.getDuration() > musicManager.getMaxSongDuration()) { continue; } track.setUserData(requester); From c1b2bbdda30178181d415f46f1acd61147f99917 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 12:05:27 +0700 Subject: [PATCH 18/24] Update after alter column to max playlist track count --- .../java/database/Entity/GuildSetting.java | 18 +++++++++--------- src/main/java/database/GuildModel.java | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/database/Entity/GuildSetting.java b/src/main/java/database/Entity/GuildSetting.java index 96c00fd..4a467ef 100644 --- a/src/main/java/database/Entity/GuildSetting.java +++ b/src/main/java/database/Entity/GuildSetting.java @@ -11,7 +11,7 @@ public class GuildSetting extends GuildModel { protected int defaultVolume; protected String customPrefix; protected int maxQueueLength; - protected int maxPlaylistCount; + protected int maxPlaylistTrackCount; protected int maxSongDuration; protected boolean premium; @@ -35,13 +35,13 @@ public GuildSetting(long id, boolean inDjMode, int defaultVolume) { } public GuildSetting(long id, boolean inDjMode, int defaultVolume, String customPrefix, int maxQueueLength, - int maxPlaylistCount, int maxSongDuration) { + int maxPlaylistTrackCount, int maxSongDuration) { this.id = id; this.inDjMode = inDjMode; this.defaultVolume = defaultVolume; this.customPrefix = customPrefix; this.maxQueueLength = maxQueueLength; - this.maxPlaylistCount = maxPlaylistCount; + this.maxPlaylistTrackCount = maxPlaylistTrackCount; this.maxSongDuration = maxSongDuration; this.canLoadSetting = false; } @@ -82,12 +82,12 @@ public void setMaxQueueLength(int maxQueueLength) { this.maxQueueLength = maxQueueLength; } - public int getMaxPlaylistCount() { - return maxPlaylistCount; + public int getMaxPlaylistTrackCount() { + return maxPlaylistTrackCount; } - public void setMaxPlaylistCount(int maxPlaylistCount) { - this.maxPlaylistCount = maxPlaylistCount; + public void setMaxPlaylistTrackCount(int maxPlaylistTrackCount) { + this.maxPlaylistTrackCount = maxPlaylistTrackCount; } public int getMaxSongDuration() { @@ -115,7 +115,7 @@ public void loadDefaultSetting(long id) { this.defaultVolume = 100; this.customPrefix = null; this.maxQueueLength = 60; - this.maxPlaylistCount = 20; + this.maxPlaylistTrackCount = 20; this.maxSongDuration = 900000; this.canLoadSetting = false; @@ -140,7 +140,7 @@ public void loadSetting(long id) throws SQLException { this.defaultVolume = result.getInt("DEFAULT_VOLUME"); this.customPrefix = result.getString("CUSTOM_PREFIX"); this.maxQueueLength = result.getInt("MAX_QUEUE_LENGTH"); - this.maxPlaylistCount = result.getInt("MAX_PLAYLIST_COUNT"); + this.maxPlaylistTrackCount = result.getInt("MAX_PLAYLIST_TRACK_COUNT"); this.maxSongDuration = result.getInt("MAX_SONG_DURATION"); this.canLoadSetting = true; diff --git a/src/main/java/database/GuildModel.java b/src/main/java/database/GuildModel.java index 2d6b759..43e59f8 100644 --- a/src/main/java/database/GuildModel.java +++ b/src/main/java/database/GuildModel.java @@ -36,7 +36,7 @@ public GuildSetting read(long id) throws SQLException { int defaultVolume = result.getInt("DEFAULT_VOLUME"); String customPrefix = result.getString("CUSTOM_PREFIX"); int maxQueueLength = result.getInt("MAX_QUEUE_LENGTH"); - int maxPlaylistCount = result.getInt("MAX_PLAYLIST_COUNT"); + int maxPlaylistCount = result.getInt("MAX_PLAYLIST_TRACK_COUNT"); int maxSongDuration = result.getInt("MAX_SONG_DURATION"); guildSetting = new GuildSetting(id, djMode, defaultVolume, customPrefix, maxQueueLength, maxPlaylistCount, maxSongDuration); From 9335a64985f9815afd91e9ff994c937b753b50bb Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 12:05:55 +0700 Subject: [PATCH 19/24] Change hardcoded duration --- src/main/java/client/NanoClient.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index 894dfd1..589de30 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -95,7 +95,7 @@ public void loadAndPlayUrl(GuildMusicManager musicManager, final TextChannel cha playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() { @Override public void trackLoaded(AudioTrack track) { - if (track.getDuration() > 900000) { + if (track.getDuration() > musicManager.getMaxSongDuration()) { String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; channel.sendMessage(errorMessage).queue(); return; @@ -133,7 +133,7 @@ public void playlistLoaded(AudioPlaylist playlist) { index += 1; continue; } - if (track.getDuration() > 900000) { + if (track.getDuration() > musicManager.getMaxSongDuration()) { continue; } track.setUserData(requester); From 93c700215edf58baa080fbe2f954daae078a5e2d Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 12:06:33 +0700 Subject: [PATCH 20/24] Remove hardcoded max playlist track count. --- .../UserPlaylistCommand/AddTrackToPlaylistCommand.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java index 157bd54..52bb04f 100644 --- a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java @@ -6,6 +6,7 @@ import database.TrackModel; import database.PlaylistModel; import service.music.CustomEmbedBuilder; +import service.music.GuildMusicManager; import service.music.HelpProcess; import java.sql.SQLException; @@ -13,7 +14,6 @@ public class AddTrackToPlaylistCommand extends UserPlaylistBaseCommand { - private final int maxTrack = 20; private final YoutubeClient client; public AddTrackToPlaylistCommand(YoutubeClient ytc) @@ -63,7 +63,10 @@ protected void execute(CommandEvent event) return; } - if (db.countPlaylistTrack(db.getPlaylistId(event.getAuthor().getIdLong(), playlistName, this.table), this.table) >= this.maxTrack) + GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); + int userPlaylistTrackCount = db.countPlaylistTrack( + db.getPlaylistId(event.getAuthor().getIdLong(), playlistName, this.table), this.table); + if (userPlaylistTrackCount >= musicManager.getMaxPlaylistTrackCount()) { embed.setTitle("Failed"); embed.addField( @@ -74,7 +77,7 @@ protected void execute(CommandEvent event) return; } - YoutubeVideo video = null; + YoutubeVideo video; try { video = this.client.getInfoByVideoUrl(url); From 8743cac31abe627705c9e9aedfc4b3ba9868f35b Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Thu, 12 Nov 2020 20:10:10 +0700 Subject: [PATCH 21/24] Decrease default value --- py/vote_webhook.py | 20 +++++++++---------- .../java/command/RecommendationCommand.java | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/py/vote_webhook.py b/py/vote_webhook.py index 89bbfc5..7963188 100644 --- a/py/vote_webhook.py +++ b/py/vote_webhook.py @@ -6,12 +6,6 @@ user = os.environ['MYSQL_USER'] password = '' -connection = mysql.connector.connect(user=user, - password=password, - host='127.0.0.1', - database='nano') -cursor = connection.cursor() - insert_vote_query = """ INSERT INTO vote (user_id, weekend) VALUES ({}, {}); @@ -36,7 +30,7 @@ create_user_query = """ INSERT INTO USER (ID, RECOMMENDATION_QUOTA, DAILY_QUOTA) - VALUES ({}, 8, 1) + VALUES ({}, 5, 1) """ VOTE_AUTH_TOKEN = os.environ["VOTE_AUTH_NANO"] @@ -50,6 +44,12 @@ def vote_post(): # Invalid Authorization code if headers["Authorization"] != VOTE_AUTH_TOKEN: return 'error', 401 + + connection = mysql.connector.connect(user=user, + password=password, + host='127.0.0.1', + database='nano') + cursor = connection.cursor() data = flask.request.get_json(force=True) @@ -104,11 +104,11 @@ def vote_post(): connection.commit() + cursor.close() + connection.close() + return 'success', 200 if __name__ == '__main__': app.run(host="0.0.0.0", port="5000") print("End") - -cursor.close() -connection.close() diff --git a/src/main/java/command/RecommendationCommand.java b/src/main/java/command/RecommendationCommand.java index 829c7dd..b4906d4 100644 --- a/src/main/java/command/RecommendationCommand.java +++ b/src/main/java/command/RecommendationCommand.java @@ -98,7 +98,7 @@ protected void execute(CommandEvent event) { recommend(event, musicManager, requestNumber); CompletableFuture.runAsync(() -> { try { - userModel.create(event.getAuthor().getIdLong(), 8, 0); + userModel.create(event.getAuthor().getIdLong(), 5, 0); } catch (SQLException sqlException) { sqlException.printStackTrace(); } From 064a19904e17c1009a3d71e0c140fb00f756cd42 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Fri, 13 Nov 2020 11:16:10 +0700 Subject: [PATCH 22/24] Fix load long duration --- .../java/service/music/AudioLoadResultHandlerKeyword.java | 8 +++++--- .../java/service/music/AudioLoadResultHandlerUrl.java | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java index 3ca11fa..9b9dc83 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java +++ b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java @@ -22,9 +22,11 @@ public AudioLoadResultHandlerKeyword(GuildMusicManager musicManager, TextChannel @Override public void trackLoaded(AudioTrack track) { - if (channel != null && track.getDuration() > musicManager.getMaxSongDuration()) { - String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; - channel.sendMessage(errorMessage).queue(); + if (track.getDuration() > musicManager.getMaxSongDuration()) { + if (channel != null) { + String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 15 minutes"; + channel.sendMessage(errorMessage).queue(); + } return; } track.setUserData(requester); diff --git a/src/main/java/service/music/AudioLoadResultHandlerUrl.java b/src/main/java/service/music/AudioLoadResultHandlerUrl.java index a444961..731f8e7 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerUrl.java +++ b/src/main/java/service/music/AudioLoadResultHandlerUrl.java @@ -24,9 +24,11 @@ public AudioLoadResultHandlerUrl(GuildMusicManager musicManager, TextChannel cha @Override public void trackLoaded(AudioTrack track) { - if (channel != null && track.getDuration() > musicManager.getMaxSongDuration()) { - String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; - channel.sendMessage(errorMessage).queue(); + if (track.getDuration() > musicManager.getMaxSongDuration()) { + if (channel != null) { + String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 15 minutes"; + channel.sendMessage(errorMessage).queue(); + } return; } track.setUserData(requester); From 2e26248f48a55b2a56da262796e11be553faa4f0 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Fri, 13 Nov 2020 11:33:00 +0700 Subject: [PATCH 23/24] Update song dduration limit --- src/main/java/client/NanoClient.java | 6 ++++-- .../java/service/music/AudioLoadResultHandlerKeyword.java | 2 +- src/main/java/service/music/AudioLoadResultHandlerUrl.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index 589de30..e04d4d5 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -96,8 +96,10 @@ public void loadAndPlayUrl(GuildMusicManager musicManager, final TextChannel cha @Override public void trackLoaded(AudioTrack track) { if (track.getDuration() > musicManager.getMaxSongDuration()) { - String errorMessage = ":negative_squared_cross_mark: | cannot load song with duration longer than 15 minutes"; - channel.sendMessage(errorMessage).queue(); + if (channel != null) { + String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 1 hour"; + channel.sendMessage(errorMessage).queue(); + } return; } track.setUserData(requester); diff --git a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java index 9b9dc83..fc8f142 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerKeyword.java +++ b/src/main/java/service/music/AudioLoadResultHandlerKeyword.java @@ -24,7 +24,7 @@ public AudioLoadResultHandlerKeyword(GuildMusicManager musicManager, TextChannel public void trackLoaded(AudioTrack track) { if (track.getDuration() > musicManager.getMaxSongDuration()) { if (channel != null) { - String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 15 minutes"; + String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 1 hour"; channel.sendMessage(errorMessage).queue(); } return; diff --git a/src/main/java/service/music/AudioLoadResultHandlerUrl.java b/src/main/java/service/music/AudioLoadResultHandlerUrl.java index 731f8e7..a8ddff9 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerUrl.java +++ b/src/main/java/service/music/AudioLoadResultHandlerUrl.java @@ -26,7 +26,7 @@ public AudioLoadResultHandlerUrl(GuildMusicManager musicManager, TextChannel cha public void trackLoaded(AudioTrack track) { if (track.getDuration() > musicManager.getMaxSongDuration()) { if (channel != null) { - String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 15 minutes"; + String errorMessage = ":negative_squared_cross_mark: | Cannot load song with duration longer than 1 hour"; channel.sendMessage(errorMessage).queue(); } return; From 385968c62846d7c81077a52c33191a2802c4e530 Mon Sep 17 00:00:00 2001 From: MadeYoga Date: Fri, 13 Nov 2020 12:37:21 +0700 Subject: [PATCH 24/24] Update limits --- src/main/java/client/NanoClient.java | 15 ++++++++++++--- .../AddTrackToPlaylistCommand.java | 6 +++++- .../CreatePlaylistCommand.java | 2 +- .../AddTrackToPlaylistCommand.java | 4 ++-- .../CreatePlaylistCommand.java | 2 +- .../service/music/AudioLoadResultHandlerUrl.java | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/client/NanoClient.java b/src/main/java/client/NanoClient.java index e04d4d5..228dc24 100644 --- a/src/main/java/client/NanoClient.java +++ b/src/main/java/client/NanoClient.java @@ -148,9 +148,18 @@ public void playlistLoaded(AudioPlaylist playlist) { PremiumService.addHistory(playlist.getName(), trackUrl, requester.getGuild(), requester.getUser()); - if (channel != null) - channel.sendMessage(":white_check_mark: | " + addedSize + - " entries from **"+ playlist.getName() + "** has been added to queue").queue(); + if (channel != null) { + CustomEmbedBuilder embedBuilder = new CustomEmbedBuilder(); + + embedBuilder.setDescription(":white_check_mark: | " + addedSize + + " entries from **" + playlist.getName() + "** has been added to queue"); + + embedBuilder.setAuthor("Added to queue", requester.getUser().getEffectiveAvatarUrl(), + requester.getUser().getEffectiveAvatarUrl()); + + embedBuilder.setFooter("Only song with duration less than 1 hour added to queue"); + channel.sendMessage(embedBuilder.build()).queue(); + } } @Override diff --git a/src/main/java/command/GuildPlaylistCommand/AddTrackToPlaylistCommand.java b/src/main/java/command/GuildPlaylistCommand/AddTrackToPlaylistCommand.java index d004664..7936ba7 100644 --- a/src/main/java/command/GuildPlaylistCommand/AddTrackToPlaylistCommand.java +++ b/src/main/java/command/GuildPlaylistCommand/AddTrackToPlaylistCommand.java @@ -5,6 +5,7 @@ import database.PremiumModel; import database.TrackModel; import net.dv8tion.jda.api.EmbedBuilder; +import service.music.GuildMusicManager; import service.music.HelpProcess; import java.sql.SQLException; @@ -93,7 +94,10 @@ protected void execute(CommandEvent event) return; } - if (db.countPlaylistTrack(db.getPlaylistId(event.getGuild().getIdLong(), playlistName, this.table), this.table) >= this.maxTrack) + GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); + int guildPlaylistTrackCount = db.countPlaylistTrack( + db.getPlaylistId(event.getGuild().getIdLong(), playlistName, this.table), this.table); + if (guildPlaylistTrackCount >= musicManager.getMaxPlaylistTrackCount()) { embed.setTitle("Failed"); embed.addField( diff --git a/src/main/java/command/GuildPlaylistCommand/CreatePlaylistCommand.java b/src/main/java/command/GuildPlaylistCommand/CreatePlaylistCommand.java index a4063c6..2cfca73 100644 --- a/src/main/java/command/GuildPlaylistCommand/CreatePlaylistCommand.java +++ b/src/main/java/command/GuildPlaylistCommand/CreatePlaylistCommand.java @@ -11,7 +11,7 @@ public class CreatePlaylistCommand extends GuildPlaylistBaseCommand { - private final int maxPlaylist = 3; + private final int maxPlaylist = 5; public CreatePlaylistCommand() { diff --git a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java index 52bb04f..d2b341f 100644 --- a/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/AddTrackToPlaylistCommand.java @@ -14,6 +14,7 @@ public class AddTrackToPlaylistCommand extends UserPlaylistBaseCommand { + private final int maxTrack = 5; private final YoutubeClient client; public AddTrackToPlaylistCommand(YoutubeClient ytc) @@ -63,10 +64,9 @@ protected void execute(CommandEvent event) return; } - GuildMusicManager musicManager = event.getClient().getSettingsFor(event.getGuild()); int userPlaylistTrackCount = db.countPlaylistTrack( db.getPlaylistId(event.getAuthor().getIdLong(), playlistName, this.table), this.table); - if (userPlaylistTrackCount >= musicManager.getMaxPlaylistTrackCount()) + if (userPlaylistTrackCount >= this.maxTrack) { embed.setTitle("Failed"); embed.addField( diff --git a/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java b/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java index c76c790..c6383d8 100644 --- a/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java +++ b/src/main/java/command/UserPlaylistCommand/CreatePlaylistCommand.java @@ -10,7 +10,7 @@ public class CreatePlaylistCommand extends UserPlaylistBaseCommand { - private final int maxPlaylist = 3; + private final int maxPlaylist = 5; public CreatePlaylistCommand() { diff --git a/src/main/java/service/music/AudioLoadResultHandlerUrl.java b/src/main/java/service/music/AudioLoadResultHandlerUrl.java index a8ddff9..b9ad762 100644 --- a/src/main/java/service/music/AudioLoadResultHandlerUrl.java +++ b/src/main/java/service/music/AudioLoadResultHandlerUrl.java @@ -81,7 +81,7 @@ public void playlistLoaded(AudioPlaylist playlist) { embedBuilder.setAuthor("Added to queue", requester.getUser().getEffectiveAvatarUrl(), requester.getUser().getEffectiveAvatarUrl()); - embedBuilder.setFooter("Only song with duration less than 15 minutes added to queue"); + embedBuilder.setFooter("Only song with duration less than 1 hour added to queue"); channel.sendMessage(embedBuilder.build()).queue(); } }