From 01f7cd11f0395eb0aa3bf037a70cbe0651f937f8 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Mon, 25 Jan 2021 13:53:08 +0100 Subject: [PATCH] fixed emote add command --- KilluaBot.iml | 2 + .../commands/util/EmoteAddCommand.java | 39 +++++++++---------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/KilluaBot.iml b/KilluaBot.iml index b2a132a..920ea54 100644 --- a/KilluaBot.iml +++ b/KilluaBot.iml @@ -5,6 +5,8 @@ + + diff --git a/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java b/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java index 69a02a2..f7f71e9 100644 --- a/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java +++ b/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java @@ -27,30 +27,29 @@ public class EmoteAddCommand extends Command { @Override public void called(String args) { List attachments = event.getMessage().getAttachments(); - Member author = event.getGuild().getMember(event.getAuthor()); + event.getGuild().retrieveMember(event.getAuthor()).queue(member -> { + if(!member.getPermissions().contains(Permission.MANAGE_EMOTES)) { + reply("You don't have the permissions to do that."); + } else if (attachments.size() == 0 || !attachments.get(0).isImage()) { + reply("No image attached"); + } else if (args.length() < 3) { + reply("Name must be at least 3 characters: " + args); + } else { + try { + Message.Attachment image = attachments.get(0); + byte[] bytes = readImage(image); - if (author == null || !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()) { - reply("No image attached"); - } else if (args.length() < 3) { - reply("Name must be at least 3 characters: " + args); - } else { - try { - Message.Attachment image = attachments.get(0); - byte[] bytes = readImage(image); + if (bytes.length > MAX_EMOTE_SIZE) { + bytes = resizeImage(bytes, image.getFileExtension(), DEFAULT_SIZE); + } - if (bytes.length > MAX_EMOTE_SIZE) { - bytes = resizeImage(bytes, image.getFileExtension(), DEFAULT_SIZE); + Icon icon = Icon.from(bytes); + event.getGuild().createEmote(args, icon).queue(emote -> reply("Successfully added emote: " + emote.getAsMention())); + } catch (IOException e) { + reply("Error while reading image. Please try again."); } - - Icon icon = Icon.from(bytes); - event.getGuild().createEmote(args, icon).queue(emote -> reply("Successfully added emote: " + emote.getAsMention())); - } catch (IOException e) { - reply("Error while reading image. Please try again."); } - } - + }); } private byte[] readImage(Message.Attachment image) throws IOException {