Added ability to limit amount of requested tracks per user.
This commit is contained in:
@@ -123,6 +123,16 @@ public final class TrackScheduler extends AudioEventAdapter {
|
|||||||
Collections.shuffle(this.queue);
|
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() {
|
public final LinkedList<RequestedTrack> getQueue() {
|
||||||
return this.queue;
|
return this.queue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public final class Settings implements Command {
|
|||||||
final Guild guild = executor.getGuild();
|
final Guild guild = executor.getGuild();
|
||||||
|
|
||||||
if (arguments.length == 0) {
|
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:");
|
executor.getAsMention() + ", these are the current settings for this guild:");
|
||||||
final EmbedBuilder builder = new EmbedBuilder();
|
final EmbedBuilder builder = new EmbedBuilder();
|
||||||
builder.setTitle("**Current Settings for " + StringUtil.sanitize(guild.getName()) + "**");
|
builder.setTitle("**Current Settings for " + StringUtil.sanitize(guild.getName()) + "**");
|
||||||
@@ -50,6 +50,14 @@ public final class Settings implements Command {
|
|||||||
} else {
|
} else {
|
||||||
builder.addField("Default Volume", defaultVolume + "%", true);
|
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());
|
response.attachEmbed(builder.build());
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
@@ -114,6 +122,33 @@ public final class Settings implements Command {
|
|||||||
TimeUnit.SECONDS);
|
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 {
|
} else {
|
||||||
return new CommandResponse("no_entry_sign",
|
return new CommandResponse("no_entry_sign",
|
||||||
"Sorry " + executor.getAsMention() + ", but I do not know what that setting is.")
|
"Sorry " + executor.getAsMention() + ", but I do not know what that setting is.")
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import dev.logal.logalbot.audio.TrackScheduler;
|
|||||||
import dev.logal.logalbot.commands.Command;
|
import dev.logal.logalbot.commands.Command;
|
||||||
import dev.logal.logalbot.commands.CommandResponse;
|
import dev.logal.logalbot.commands.CommandResponse;
|
||||||
import dev.logal.logalbot.utils.AudioUtil;
|
import dev.logal.logalbot.utils.AudioUtil;
|
||||||
|
import dev.logal.logalbot.utils.DataManager;
|
||||||
import dev.logal.logalbot.utils.PermissionManager;
|
import dev.logal.logalbot.utils.PermissionManager;
|
||||||
import dev.logal.logalbot.utils.VoiceChannelUtil;
|
import dev.logal.logalbot.utils.VoiceChannelUtil;
|
||||||
import net.dv8tion.jda.core.Permission;
|
import net.dv8tion.jda.core.Permission;
|
||||||
@@ -76,6 +77,17 @@ public final class Play implements Command {
|
|||||||
.setDeletionDelay(10, TimeUnit.SECONDS);
|
.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;
|
boolean isLink;
|
||||||
try {
|
try {
|
||||||
new URL(arguments[0]);
|
new URL(arguments[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user