From eabd310db6334fc051491ae2cda5fccd458dbd42 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Thu, 28 Jan 2021 19:38:58 +0100 Subject: [PATCH] fight thing prototype no --- .../com/github/nilstrieb/cofig/Config.java | 2 +- .../com/github/nilstrieb/cofig/Secrets.java | 5 ---- .../nilstrieb/commands/fun/FightCommand.java | 23 +++++++++++++++++++ .../commands/util/EmoteAddCommand.java | 7 ++++-- .../java/com/github/nilstrieb/core/Main.java | 5 ++-- 5 files changed, 32 insertions(+), 10 deletions(-) delete mode 100644 src/main/java/com/github/nilstrieb/cofig/Secrets.java create mode 100644 src/main/java/com/github/nilstrieb/commands/fun/FightCommand.java diff --git a/src/main/java/com/github/nilstrieb/cofig/Config.java b/src/main/java/com/github/nilstrieb/cofig/Config.java index 05b5120..417dfb0 100644 --- a/src/main/java/com/github/nilstrieb/cofig/Config.java +++ b/src/main/java/com/github/nilstrieb/cofig/Config.java @@ -13,7 +13,7 @@ public class Config { public static final String NORMAL_PREFIX = "kil "; public static final String L_PREFIX = "k "; - public static final String PREFIX = NORMAL_PREFIX; + public static final String PREFIX = L_PREFIX; public static final Color DEFAULT_COLOR = new Color(229, 201, 255); diff --git a/src/main/java/com/github/nilstrieb/cofig/Secrets.java b/src/main/java/com/github/nilstrieb/cofig/Secrets.java deleted file mode 100644 index 5d2ee93..0000000 --- a/src/main/java/com/github/nilstrieb/cofig/Secrets.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.github.nilstrieb.cofig; - -public class Secrets { - public static final String TOKEN = "invite the xp bot to your discord"; -} diff --git a/src/main/java/com/github/nilstrieb/commands/fun/FightCommand.java b/src/main/java/com/github/nilstrieb/commands/fun/FightCommand.java new file mode 100644 index 0000000..8f1cf04 --- /dev/null +++ b/src/main/java/com/github/nilstrieb/commands/fun/FightCommand.java @@ -0,0 +1,23 @@ +package com.github.nilstrieb.commands.fun; + +import com.github.nilstrieb.cofig.Config; +import com.github.nilstrieb.commands.handler.Command; +import net.dv8tion.jda.api.EmbedBuilder; + +public class FightCommand extends Command { + + private static String[] abilities = {"Little Flower", "Jajanken", "Lightning", "punch", "Chapter 7 Bankruptcy", "Ripper Cyclotron", "Rising Sun", + "100-Type Guanyin Bodhisattva"}; + + public FightCommand() { + super("fight", "Fight against someone else!", "fight Tonpa", ""); + } + + @Override + public void called(String args) { + EmbedBuilder builder = Config.getDefaultEmbed(); + String author = event.getAuthor().getAsTag(); + builder.addField(author + " x " + args, "A fight breaks out between " + author + " and " + args, false); + reply(builder.build()); + } +} 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 d0394e7..dcb6d5e 100644 --- a/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java +++ b/src/main/java/com/github/nilstrieb/commands/util/EmoteAddCommand.java @@ -36,6 +36,8 @@ public class EmoteAddCommand extends Command { reply("No image attached"); } else if (args.length() < 3) { reply("Name must be at least 3 characters: " + args); + } else if (!args.matches("\\w+")) { + reply("Emote names are only allowed to contain characters, numbers and underscore"); } else { try { Message.Attachment image = attachments.get(0); @@ -72,7 +74,8 @@ public class EmoteAddCommand extends Command { 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)); - image = image.getScaledInstance(size, size, Image.SCALE_SMOOTH); + int ratio = image.getHeight(null) / image.getWidth(null); + image = image.getScaledInstance(size, size * ratio, Image.SCALE_SMOOTH); ByteArrayOutputStream out = new ByteArrayOutputStream(); BufferedImage bufferedImg = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); @@ -82,7 +85,7 @@ public class EmoteAddCommand extends Command { ImageIO.write(bufferedImg, format, out); bytes = out.toByteArray(); - if(bytes.length > MAX_EMOTE_SIZE){ + if (bytes.length > MAX_EMOTE_SIZE) { return resizeImage(bytes, format, size - 100); } else { return bytes; diff --git a/src/main/java/com/github/nilstrieb/core/Main.java b/src/main/java/com/github/nilstrieb/core/Main.java index 03a434a..d29ab8f 100644 --- a/src/main/java/com/github/nilstrieb/core/Main.java +++ b/src/main/java/com/github/nilstrieb/core/Main.java @@ -4,6 +4,7 @@ import com.github.nilstrieb.cofig.Config; import com.github.nilstrieb.cofig.Secrets; //import com.github.nilstrieb.commands.fun.DepartureCommand; import com.github.nilstrieb.commands.fun.DepartureCommand; +import com.github.nilstrieb.commands.fun.FightCommand; import com.github.nilstrieb.commands.fun.QuoteCommand; import com.github.nilstrieb.commands.fun.SayCommand; import com.github.nilstrieb.commands.fun.trivia.TriviaCommand; @@ -16,7 +17,6 @@ import com.github.nilstrieb.listener.ChannelMessageListener; import com.github.nilstrieb.listener.CommandListener; import com.github.nilstrieb.listener.ReactionEventListener; import com.github.nilstrieb.listener.StartUpListener; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; @@ -30,7 +30,7 @@ import java.util.Scanner; public class Main { public static void main(String[] args) throws LoginException { - JDABuilder builder = JDABuilder.createDefault(Secrets.TOKEN); + JDABuilder builder = JDABuilder.createDefault(Secrets.L_TOKEN); builder.setCompression(Compression.ZLIB); builder.setActivity(Activity.watching("over Gon")); @@ -78,5 +78,6 @@ public class Main { new DepartureCommand(); new TriviaCommand(); new EmoteAddCommand(); + new FightCommand(); } }