mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-15 07:35:02 +01:00
fixed emote add command
This commit is contained in:
parent
08b91df73b
commit
01f7cd11f0
2 changed files with 21 additions and 20 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue