emote limit check

This commit is contained in:
nora 2021-03-15 09:07:20 +01:00
parent ff999832f8
commit f64252f5c0

View file

@ -31,7 +31,9 @@ public class EmoteAddCommand extends Command {
if (!author.getPermissions().contains(Permission.MANAGE_EMOTES)) { if (!author.getPermissions().contains(Permission.MANAGE_EMOTES)) {
reply("You don't have the permissions to do that."); reply("You don't have the permissions to do that.");
} else if (attachments.size() == 0 || !attachments.get(0).isImage()) { } else if (emoteLimitReached()) {
reply("Emote limit reached");
} else if (attachments.isEmpty() || !attachments.get(0).isImage()) {
reply("No image attached"); reply("No image attached");
} else if (args.length() < 3) { } else if (args.length() < 3) {
reply("Name must be at least 3 characters: " + args); reply("Name must be at least 3 characters: " + args);
@ -54,6 +56,13 @@ public class EmoteAddCommand extends Command {
} }
} }
private boolean emoteLimitReached() {
int max = event.getGuild().getMaxEmotes();
int count = event.getGuild().retrieveEmotes().complete().size();
return max == count;
}
private byte[] readImage(Message.Attachment image) throws IOException { private byte[] readImage(Message.Attachment image) throws IOException {
String urlString = image.getUrl(); String urlString = image.getUrl();
URL url = new URL(urlString); URL url = new URL(urlString);
@ -61,11 +70,12 @@ public class EmoteAddCommand extends Command {
byte[] chunk = new byte[4096]; byte[] chunk = new byte[4096];
int bytesRead; int bytesRead;
InputStream stream = url.openStream();
try (InputStream stream = url.openStream()) {
while ((bytesRead = stream.read(chunk)) > 0) { while ((bytesRead = stream.read(chunk)) > 0) {
out.write(chunk, 0, bytesRead); out.write(chunk, 0, bytesRead);
} }
}
return out.toByteArray(); return out.toByteArray();
} }