From dffc5c1aa4c2df4d6c783f2774d860f8f28c28f2 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Mon, 15 Mar 2021 15:34:46 +0100 Subject: [PATCH] emote steal final --- .../commands/util/EmoteAddCommand.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) 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 a3eb4e9..b57da6d 100644 --- a/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java +++ b/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java @@ -11,7 +11,6 @@ import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; -import java.net.MalformedURLException; import java.net.URL; import java.util.List; @@ -29,7 +28,13 @@ public class EmoteAddCommand extends Command { @Override public void called(String args) { List attachments = event.getMessage().getAttachments(); - Member author = event.getGuild().retrieveMember(event.getAuthor()).complete(); + Member author = event.getMember(); + + if (author == null) { + System.err.println("Author of emote add Message is null"); + reply("Error while adding emote. Pleasy try again."); + return; + } if (!author.getPermissions().contains(Permission.MANAGE_EMOTES)) { reply("You don't have the permissions to do that."); @@ -65,25 +70,14 @@ public class EmoteAddCommand extends Command { Emote emote = event.getMessage().getEmotes().get(0); URL url = new URL(emote.getImageUrl()); byte[] data = readUrl(url); - uploadEmote(data, event.getMessage().getContentRaw()); + uploadEmote(data, emote.getName()); } private void uploadEmote(byte[] bytes, String name) { - Icon icon = Icon.from(bytes); event.getGuild().createEmote(name, icon).queue(emote -> reply("Successfully added emote: " + emote.getAsMention())); } - private boolean messageContainsEmote() { - return !event.getMessage().getEmotes().isEmpty(); - } - - 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(); @@ -106,6 +100,17 @@ public class EmoteAddCommand extends Command { return out.toByteArray(); } + private boolean messageContainsEmote() { + return !event.getMessage().getEmotes().isEmpty(); + } + + private boolean emoteLimitReached() { + int max = event.getGuild().getMaxEmotes(); + int count = event.getGuild().retrieveEmotes().complete().size(); + + return max == count; + } + private byte[] resizeImage(byte[] bytes, String format, int size) throws IOException { reply("Image size too big (" + bytes.length / 1000 + "kB). Resizing image..."); Image image = ImageIO.read(new ByteArrayInputStream(bytes));