0

Added ability to limit amount of requested tracks per user.

This commit is contained in:
Logan Fick
2019-05-26 21:02:46 -04:00
parent 0b582da060
commit c87200493c
3 changed files with 58 additions and 1 deletions

View File

@@ -123,6 +123,16 @@ public final class TrackScheduler extends AudioEventAdapter {
Collections.shuffle(this.queue);
}
public final int occupiedSlotCount(Member member) {
int count = 0;
for (RequestedTrack requestedTrack : this.queue) {
if (requestedTrack.getRequester().equals(member)) {
count++;
}
}
return count;
}
public final LinkedList<RequestedTrack> getQueue() {
return this.queue;
}

View File

@@ -32,7 +32,7 @@ public final class Settings implements Command {
final Guild guild = executor.getGuild();
if (arguments.length == 0) {
final CommandResponse response = new CommandResponse("tools",
final CommandResponse response = new CommandResponse("wrench",
executor.getAsMention() + ", these are the current settings for this guild:");
final EmbedBuilder builder = new EmbedBuilder();
builder.setTitle("**Current Settings for " + StringUtil.sanitize(guild.getName()) + "**");
@@ -50,6 +50,14 @@ public final class Settings implements Command {
} else {
builder.addField("Default Volume", defaultVolume + "%", true);
}
final String maxSlots = DataManager.getGuildValue(guild, "maximumSlots");
if (maxSlots == null) {
builder.addField("Maximum Queue Slots Per User", "Unlimited", true);
} else {
builder.addField("Maximum Queue Slots Per User", maxSlots, true);
}
response.attachEmbed(builder.build());
return response;
}
@@ -114,6 +122,33 @@ public final class Settings implements Command {
TimeUnit.SECONDS);
}
}
} else if (arguments[0].equalsIgnoreCase("maximumSlots")) {
final int maxSlots;
try {
maxSlots = Integer.parseInt(arguments[1]);
} catch (final NumberFormatException exception) {
return new CommandResponse("no_entry_sign",
"Sorry " + executor.getAsMention()
+ ", but the maximum amount of queue slots per user must be an integer.")
.setDeletionDelay(10, TimeUnit.SECONDS);
}
if (maxSlots == 0) {
DataManager.deleteGuildKey(guild, "maximumSlots");
return new CommandResponse("white_check_mark", executor.getAsMention()
+ ", the maximum amount of queue slots per user has been reset to unlimited.");
}
if (maxSlots <= 249 && maxSlots >= 1) {
DataManager.setGuildValue(guild, "maximumSlots", "" + maxSlots);
return new CommandResponse("white_check_mark", executor.getAsMention()
+ ", the maximum amount of queue slots per user has been set to `" + maxSlots + "`.");
} else {
return new CommandResponse("no_entry_sign",
"Sorry " + executor.getAsMention()
+ ", but the maximum amount of queue slots per user must be between 1 and 249.")
.setDeletionDelay(10, TimeUnit.SECONDS);
}
} else {
return new CommandResponse("no_entry_sign",
"Sorry " + executor.getAsMention() + ", but I do not know what that setting is.")

View File

@@ -22,6 +22,7 @@ import dev.logal.logalbot.audio.TrackScheduler;
import dev.logal.logalbot.commands.Command;
import dev.logal.logalbot.commands.CommandResponse;
import dev.logal.logalbot.utils.AudioUtil;
import dev.logal.logalbot.utils.DataManager;
import dev.logal.logalbot.utils.PermissionManager;
import dev.logal.logalbot.utils.VoiceChannelUtil;
import net.dv8tion.jda.core.Permission;
@@ -76,6 +77,17 @@ public final class Play implements Command {
.setDeletionDelay(10, TimeUnit.SECONDS);
}
try {
final int maxSlots = Integer.parseInt(DataManager.getGuildValue(guild, "maximumSlots"));
if ((scheduler.occupiedSlotCount(executor) >= maxSlots) && !PermissionManager.isWhitelisted(executor)) {
return new CommandResponse("no_entry_sign", "Sorry " + executor.getAsMention()
+ ", you cannot request more than " + maxSlots + " tracks at the same time.")
.setDeletionDelay(10, TimeUnit.SECONDS);
}
} catch (final NumberFormatException exception) {
}
boolean isLink;
try {
new URL(arguments[0]);