mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-17 00:25:02 +01:00
emote limit check
This commit is contained in:
parent
ff999832f8
commit
f64252f5c0
1 changed files with 15 additions and 5 deletions
|
|
@ -31,7 +31,9 @@ public class EmoteAddCommand extends Command {
|
|||
|
||||
if (!author.getPermissions().contains(Permission.MANAGE_EMOTES)) {
|
||||
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");
|
||||
} else if (args.length() < 3) {
|
||||
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 {
|
||||
String urlString = image.getUrl();
|
||||
URL url = new URL(urlString);
|
||||
|
|
@ -61,11 +70,12 @@ public class EmoteAddCommand extends Command {
|
|||
|
||||
byte[] chunk = new byte[4096];
|
||||
int bytesRead;
|
||||
InputStream stream = url.openStream();
|
||||
|
||||
try (InputStream stream = url.openStream()) {
|
||||
while ((bytesRead = stream.read(chunk)) > 0) {
|
||||
out.write(chunk, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue