mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-14 15:15:01 +01:00
fixed emote add command
This commit is contained in:
parent
08b91df73b
commit
01f7cd11f0
2 changed files with 21 additions and 20 deletions
|
|
@ -5,6 +5,8 @@
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
<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" />
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
|
|
|
||||||
|
|
@ -27,30 +27,29 @@ public class EmoteAddCommand extends Command {
|
||||||
@Override
|
@Override
|
||||||
public void called(String args) {
|
public void called(String args) {
|
||||||
List<Message.Attachment> attachments = event.getMessage().getAttachments();
|
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)) {
|
if (bytes.length > MAX_EMOTE_SIZE) {
|
||||||
reply("You don't have the permissions to do that.");
|
bytes = resizeImage(bytes, image.getFileExtension(), DEFAULT_SIZE);
|
||||||
} 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) {
|
Icon icon = Icon.from(bytes);
|
||||||
bytes = resizeImage(bytes, image.getFileExtension(), DEFAULT_SIZE);
|
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 {
|
private byte[] readImage(Message.Attachment image) throws IOException {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue