mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-16 16:15:03 +01:00
emote limit check
This commit is contained in:
parent
ff999832f8
commit
f64252f5c0
1 changed files with 15 additions and 5 deletions
|
|
@ -29,9 +29,11 @@ public class EmoteAddCommand extends Command {
|
||||||
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
||||||
Member author = event.getGuild().retrieveMember(event.getAuthor()).complete();
|
Member author = event.getGuild().retrieveMember(event.getAuthor()).complete();
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue