fixed emote add command

This commit is contained in:
nora 2021-01-25 13:53:08 +01:00
parent 08b91df73b
commit 01f7cd11f0
2 changed files with 21 additions and 20 deletions

View file

@ -5,6 +5,8 @@
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />

View file

@ -27,30 +27,29 @@ public class EmoteAddCommand extends Command {
@Override
public void called(String args) {
List<Message.Attachment> 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 {