diff options
author | Tyler Murphy <tylermurphy534@gmail.com> | 2022-10-05 08:50:42 -0400 |
---|---|---|
committer | Tyler Murphy <tylermurphy534@gmail.com> | 2022-10-05 08:50:42 -0400 |
commit | 146d1ee7ff07c351e5249880ad2095a34fd3c7e7 (patch) | |
tree | 9e55e03b59167f650170e8f63e616cfae52a66d5 | |
parent | change image fetch timeout (diff) | |
download | ken-146d1ee7ff07c351e5249880ad2095a34fd3c7e7.tar.gz ken-146d1ee7ff07c351e5249880ad2095a34fd3c7e7.tar.bz2 ken-146d1ee7ff07c351e5249880ad2095a34fd3c7e7.zip |
local image fetch
62 files changed, 39 insertions, 21 deletions
diff --git a/src/main/java/net/tylermurphy/ken/command/Responder.java b/src/main/java/net/tylermurphy/ken/command/Responder.java index d7bdc15..eee9bb7 100644 --- a/src/main/java/net/tylermurphy/ken/command/Responder.java +++ b/src/main/java/net/tylermurphy/ken/command/Responder.java @@ -147,6 +147,7 @@ public class Responder extends ListenerAdapter { Response response = (Response)temp; reply(response, event.getHook()); } catch (Exception e) { + e.printStackTrace(); EmbedBuilder builder = Ken.getInstance().getDefaultEmbed() .setColor(Color.RED) .setTitle(":x: **Error**") diff --git a/src/main/java/net/tylermurphy/ken/command/fun/CrabRave.java b/src/main/java/net/tylermurphy/ken/command/fun/CrabRave.java index b0d3b0f..f530de9 100644 --- a/src/main/java/net/tylermurphy/ken/command/fun/CrabRave.java +++ b/src/main/java/net/tylermurphy/ken/command/fun/CrabRave.java @@ -4,7 +4,6 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.tylermurphy.ken.Ken; -import net.tylermurphy.ken.api.Request; import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.annotation.Command; import net.tylermurphy.ken.command.annotation.Option; @@ -33,8 +32,8 @@ public class CrabRave { } private byte[] generateGif(User u) throws IOException, NullPointerException { - BufferedImage crab = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/crab.png", true); - BufferedImage avatar = Ken.getInstance().getImageFetcher().getImage(u.getAvatarUrl(), false); + BufferedImage crab = Ken.getInstance().getImageFetcher().getCdnImage("crab.png", true); + BufferedImage avatar = Ken.getInstance().getImageFetcher().getRawImage(u.getAvatarUrl(), false); BufferedImage[] frames = new BufferedImage[26]; for(int i = 0; i < frames.length; i++) { frames[i] = generateFrame(i, avatar, crab); diff --git a/src/main/java/net/tylermurphy/ken/command/fun/Eject.java b/src/main/java/net/tylermurphy/ken/command/fun/Eject.java index 29900be..7a08991 100644 --- a/src/main/java/net/tylermurphy/ken/command/fun/Eject.java +++ b/src/main/java/net/tylermurphy/ken/command/fun/Eject.java @@ -4,7 +4,6 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.tylermurphy.ken.Ken; -import net.tylermurphy.ken.api.Request; import net.tylermurphy.ken.command.annotation.Command; import net.tylermurphy.ken.command.annotation.Option; import net.tylermurphy.ken.command.Response; @@ -28,6 +27,7 @@ public class Eject { byte[] data = generateGif(ejected.getUser()); return Response.success(ejected.getEffectiveName() +" was ejected by "+sender.getEffectiveName()).setFile(data, "eject.gif"); } catch (IOException e) { + e.printStackTrace(); return Response.error("Failed to generate gif"); } } @@ -39,8 +39,8 @@ public class Eject { else message = u.getName() + " was not An Impostor"; - BufferedImage space = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/space.jpg", true); - BufferedImage avatar = Ken.getInstance().getImageFetcher().getImage(u.getAvatarUrl(), false); + BufferedImage space = Ken.getInstance().getImageFetcher().getCdnImage("space.jpg", true); + BufferedImage avatar = Ken.getInstance().getImageFetcher().getRawImage(u.getAvatarUrl(), false); BufferedImage[] frames = new BufferedImage[30]; for (int i = 0; i < frames.length; i++) { diff --git a/src/main/java/net/tylermurphy/ken/command/fun/GayMeme.java b/src/main/java/net/tylermurphy/ken/command/fun/GayMeme.java index b538606..20737f0 100644 --- a/src/main/java/net/tylermurphy/ken/command/fun/GayMeme.java +++ b/src/main/java/net/tylermurphy/ken/command/fun/GayMeme.java @@ -4,7 +4,6 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.tylermurphy.ken.Ken; -import net.tylermurphy.ken.api.Request; import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.annotation.Command; import net.tylermurphy.ken.command.annotation.Option; @@ -12,7 +11,6 @@ import net.tylermurphy.ken.util.GifSequenceWriter; import javax.imageio.ImageIO; import javax.imageio.stream.ImageOutputStream; -import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -34,9 +32,9 @@ public class GayMeme { } private byte[] generateGif(User u) throws IOException, NullPointerException { - BufferedImage avatar = Ken.getInstance().getImageFetcher().getImage(u.getAvatarUrl(), false); - BufferedImage background = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/theMoreYouKnow.png", true); - BufferedImage gay = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/gay.png", true); + BufferedImage avatar = Ken.getInstance().getImageFetcher().getRawImage(u.getAvatarUrl(), false); + BufferedImage background = Ken.getInstance().getImageFetcher().getCdnImage("theMoreYouKnow.png", true); + BufferedImage gay = Ken.getInstance().getImageFetcher().getCdnImage("gay.png", true); BufferedImage[] frames = new BufferedImage[40]; for(int i = 0; i < frames.length; i++) { diff --git a/src/main/java/net/tylermurphy/ken/command/fun/Headpat.java b/src/main/java/net/tylermurphy/ken/command/fun/Headpat.java index 5a2239e..cf5a08f 100644 --- a/src/main/java/net/tylermurphy/ken/command/fun/Headpat.java +++ b/src/main/java/net/tylermurphy/ken/command/fun/Headpat.java @@ -4,7 +4,6 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.tylermurphy.ken.Ken; -import net.tylermurphy.ken.api.Request; import net.tylermurphy.ken.command.Response; import net.tylermurphy.ken.command.annotation.Command; import net.tylermurphy.ken.command.annotation.Option; @@ -33,8 +32,8 @@ public class Headpat { } private byte[] generateGif(User u) throws IOException, NullPointerException { - BufferedImage hand = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/headpat.png", true); - BufferedImage avatar = Ken.getInstance().getImageFetcher().getImage(u.getAvatarUrl(), false); + BufferedImage hand = Ken.getInstance().getImageFetcher().getCdnImage("headpat.png", true); + BufferedImage avatar = Ken.getInstance().getImageFetcher().getRawImage(u.getAvatarUrl(), false); BufferedImage[] frames = new BufferedImage[5]; for(int i = 0; i < frames.length; i++) { diff --git a/src/main/java/net/tylermurphy/ken/command/fun/Wank.java b/src/main/java/net/tylermurphy/ken/command/fun/Wank.java index c2cb6f1..a2918f8 100644 --- a/src/main/java/net/tylermurphy/ken/command/fun/Wank.java +++ b/src/main/java/net/tylermurphy/ken/command/fun/Wank.java @@ -32,8 +32,8 @@ public class Wank { } private byte[] generateGif(User u) throws IOException { - BufferedImage wank = Ken.getInstance().getImageFetcher().getImage("https://cdn.tylermurphy.net/ken/laptop.png", true); - BufferedImage avatar = Ken.getInstance().getImageFetcher().getImage(u.getAvatarUrl(), false); + BufferedImage wank = Ken.getInstance().getImageFetcher().getCdnImage("laptop.png", true); + BufferedImage avatar = Ken.getInstance().getImageFetcher().getRawImage(u.getAvatarUrl(), false); BufferedImage[] frames = new BufferedImage[4]; for (int i = 0; i < frames.length; i++) { diff --git a/src/main/java/net/tylermurphy/ken/util/ImageFetcher.java b/src/main/java/net/tylermurphy/ken/util/ImageFetcher.java index d3bddbc..686eb7e 100644 --- a/src/main/java/net/tylermurphy/ken/util/ImageFetcher.java +++ b/src/main/java/net/tylermurphy/ken/util/ImageFetcher.java @@ -1,8 +1,11 @@ package net.tylermurphy.ken.util; +import net.tylermurphy.ken.Ken; + import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; +import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util.HashMap; @@ -12,7 +15,21 @@ public class ImageFetcher { private final Map<String,BufferedImage> CACHE = new HashMap<>(); - public BufferedImage getImage(String url, boolean cache) throws IOException { + public BufferedImage getCdnImage(String name, boolean cache) throws IOException { + if(Ken.getInstance().getConfig().getBoolean("fetchLocal")) { + if(CACHE.containsKey(name)) return CACHE.get(name); + InputStream in = Ken.getInstance().getResource("cdn/"+name); + if(in == null) return null; + BufferedImage image = ImageIO.read(in); + if(cache && image != null) CACHE.put(name, image); + return image; + } else { + String url = Ken.getInstance().getConfig().getString("cdn") + name; + return getRawImage(url, cache); + } + } + + public BufferedImage getRawImage(String url, boolean cache) throws IOException { if(CACHE.containsKey(url)) return CACHE.get(url); HttpURLConnection connection = getConnection(url); BufferedImage image = ImageIO.read(connection.getInputStream()); diff --git a/src/main/resources/cdn/coin_heads.png b/src/main/resources/cdn/coin_heads.png Binary files differnew file mode 100644 index 0000000..066edb3 --- /dev/null +++ b/src/main/resources/cdn/coin_heads.png diff --git a/src/main/resources/cdn/coin_tails.png b/src/main/resources/cdn/coin_tails.png Binary files differnew file mode 100644 index 0000000..c25c369 --- /dev/null +++ b/src/main/resources/cdn/coin_tails.png diff --git a/src/main/resources/cdn/crab.png b/src/main/resources/cdn/crab.png Binary files differnew file mode 100644 index 0000000..d51d761 --- /dev/null +++ b/src/main/resources/cdn/crab.png diff --git a/src/main/resources/cdn/d12_1.png b/src/main/resources/cdn/d12_1.png Binary files differnew file mode 100644 index 0000000..be39c24 --- /dev/null +++ b/src/main/resources/cdn/d12_1.png diff --git a/src/main/resources/cdn/d12_10.png b/src/main/resources/cdn/d12_10.png Binary files differnew file mode 100644 index 0000000..c0dbbc9 --- /dev/null +++ b/src/main/resources/cdn/d12_10.png diff --git a/src/main/resources/cdn/d12_11.png b/src/main/resources/cdn/d12_11.png Binary files differnew file mode 100644 index 0000000..bde3331 --- /dev/null +++ b/src/main/resources/cdn/d12_11.png diff --git a/src/main/resources/cdn/d12_12.png b/src/main/resources/cdn/d12_12.png Binary files differnew file mode 100644 index 0000000..080c00f --- /dev/null +++ b/src/main/resources/cdn/d12_12.png diff --git a/src/main/resources/cdn/d12_2.png b/src/main/resources/cdn/d12_2.png Binary files differnew file mode 100644 index 0000000..b5eee21 --- /dev/null +++ b/src/main/resources/cdn/d12_2.png diff --git a/src/main/resources/cdn/d12_3.png b/src/main/resources/cdn/d12_3.png Binary files differnew file mode 100644 index 0000000..3e99211 --- /dev/null +++ b/src/main/resources/cdn/d12_3.png diff --git a/src/main/resources/cdn/d12_4.png b/src/main/resources/cdn/d12_4.png Binary files differnew file mode 100644 index 0000000..4812627 --- /dev/null +++ b/src/main/resources/cdn/d12_4.png diff --git a/src/main/resources/cdn/d12_5.png b/src/main/resources/cdn/d12_5.png Binary files differnew file mode 100644 index 0000000..2e3d48f --- /dev/null +++ b/src/main/resources/cdn/d12_5.png diff --git a/src/main/resources/cdn/d12_6.png b/src/main/resources/cdn/d12_6.png Binary files differnew file mode 100644 index 0000000..ce971f9 --- /dev/null +++ b/src/main/resources/cdn/d12_6.png diff --git a/src/main/resources/cdn/d12_7.png b/src/main/resources/cdn/d12_7.png Binary files differnew file mode 100644 index 0000000..d1d9118 --- /dev/null +++ b/src/main/resources/cdn/d12_7.png diff --git a/src/main/resources/cdn/d12_8.png b/src/main/resources/cdn/d12_8.png Binary files differnew file mode 100644 index 0000000..7504d95 --- /dev/null +++ b/src/main/resources/cdn/d12_8.png diff --git a/src/main/resources/cdn/d12_9.png b/src/main/resources/cdn/d12_9.png Binary files differnew file mode 100644 index 0000000..796987a --- /dev/null +++ b/src/main/resources/cdn/d12_9.png diff --git a/src/main/resources/cdn/d20_1.png b/src/main/resources/cdn/d20_1.png Binary files differnew file mode 100644 index 0000000..da84394 --- /dev/null +++ b/src/main/resources/cdn/d20_1.png diff --git a/src/main/resources/cdn/d20_10.png b/src/main/resources/cdn/d20_10.png Binary files differnew file mode 100644 index 0000000..4174b5e --- /dev/null +++ b/src/main/resources/cdn/d20_10.png diff --git a/src/main/resources/cdn/d20_11.png b/src/main/resources/cdn/d20_11.png Binary files differnew file mode 100644 index 0000000..ad0500d --- /dev/null +++ b/src/main/resources/cdn/d20_11.png diff --git a/src/main/resources/cdn/d20_12.png b/src/main/resources/cdn/d20_12.png Binary files differnew file mode 100644 index 0000000..7ea847f --- /dev/null +++ b/src/main/resources/cdn/d20_12.png diff --git a/src/main/resources/cdn/d20_13.png b/src/main/resources/cdn/d20_13.png Binary files differnew file mode 100644 index 0000000..5c126de --- /dev/null +++ b/src/main/resources/cdn/d20_13.png diff --git a/src/main/resources/cdn/d20_14.png b/src/main/resources/cdn/d20_14.png Binary files differnew file mode 100644 index 0000000..90629d3 --- /dev/null +++ b/src/main/resources/cdn/d20_14.png diff --git a/src/main/resources/cdn/d20_15.png b/src/main/resources/cdn/d20_15.png Binary files differnew file mode 100644 index 0000000..2c98859 --- /dev/null +++ b/src/main/resources/cdn/d20_15.png diff --git a/src/main/resources/cdn/d20_16.png b/src/main/resources/cdn/d20_16.png Binary files differnew file mode 100644 index 0000000..11a99d3 --- /dev/null +++ b/src/main/resources/cdn/d20_16.png diff --git a/src/main/resources/cdn/d20_17.png b/src/main/resources/cdn/d20_17.png Binary files differnew file mode 100644 index 0000000..8e18b98 --- /dev/null +++ b/src/main/resources/cdn/d20_17.png diff --git a/src/main/resources/cdn/d20_18.png b/src/main/resources/cdn/d20_18.png Binary files differnew file mode 100644 index 0000000..04fefb1 --- /dev/null +++ b/src/main/resources/cdn/d20_18.png diff --git a/src/main/resources/cdn/d20_19.png b/src/main/resources/cdn/d20_19.png Binary files differnew file mode 100644 index 0000000..bbfe88e --- /dev/null +++ b/src/main/resources/cdn/d20_19.png diff --git a/src/main/resources/cdn/d20_2.png b/src/main/resources/cdn/d20_2.png Binary files differnew file mode 100644 index 0000000..c3f09a0 --- /dev/null +++ b/src/main/resources/cdn/d20_2.png diff --git a/src/main/resources/cdn/d20_20.png b/src/main/resources/cdn/d20_20.png Binary files differnew file mode 100644 index 0000000..a184f18 --- /dev/null +++ b/src/main/resources/cdn/d20_20.png diff --git a/src/main/resources/cdn/d20_3.png b/src/main/resources/cdn/d20_3.png Binary files differnew file mode 100644 index 0000000..cf4741d --- /dev/null +++ b/src/main/resources/cdn/d20_3.png diff --git a/src/main/resources/cdn/d20_4.png b/src/main/resources/cdn/d20_4.png Binary files differnew file mode 100644 index 0000000..90f8cb6 --- /dev/null +++ b/src/main/resources/cdn/d20_4.png diff --git a/src/main/resources/cdn/d20_5.png b/src/main/resources/cdn/d20_5.png Binary files differnew file mode 100644 index 0000000..ba323f3 --- /dev/null +++ b/src/main/resources/cdn/d20_5.png diff --git a/src/main/resources/cdn/d20_6.png b/src/main/resources/cdn/d20_6.png Binary files differnew file mode 100644 index 0000000..e7af576 --- /dev/null +++ b/src/main/resources/cdn/d20_6.png diff --git a/src/main/resources/cdn/d20_7.png b/src/main/resources/cdn/d20_7.png Binary files differnew file mode 100644 index 0000000..ddc502c --- /dev/null +++ b/src/main/resources/cdn/d20_7.png diff --git a/src/main/resources/cdn/d20_8.png b/src/main/resources/cdn/d20_8.png Binary files differnew file mode 100644 index 0000000..f34cf45 --- /dev/null +++ b/src/main/resources/cdn/d20_8.png diff --git a/src/main/resources/cdn/d20_9.png b/src/main/resources/cdn/d20_9.png Binary files differnew file mode 100644 index 0000000..b0f8311 --- /dev/null +++ b/src/main/resources/cdn/d20_9.png diff --git a/src/main/resources/cdn/d6_1.png b/src/main/resources/cdn/d6_1.png Binary files differnew file mode 100644 index 0000000..2920ff6 --- /dev/null +++ b/src/main/resources/cdn/d6_1.png diff --git a/src/main/resources/cdn/d6_2.png b/src/main/resources/cdn/d6_2.png Binary files differnew file mode 100644 index 0000000..f274b45 --- /dev/null +++ b/src/main/resources/cdn/d6_2.png diff --git a/src/main/resources/cdn/d6_3.png b/src/main/resources/cdn/d6_3.png Binary files differnew file mode 100644 index 0000000..324ade3 --- /dev/null +++ b/src/main/resources/cdn/d6_3.png diff --git a/src/main/resources/cdn/d6_4.png b/src/main/resources/cdn/d6_4.png Binary files differnew file mode 100644 index 0000000..928e15d --- /dev/null +++ b/src/main/resources/cdn/d6_4.png diff --git a/src/main/resources/cdn/d6_5.png b/src/main/resources/cdn/d6_5.png Binary files differnew file mode 100644 index 0000000..0973c4c --- /dev/null +++ b/src/main/resources/cdn/d6_5.png diff --git a/src/main/resources/cdn/d6_6.png b/src/main/resources/cdn/d6_6.png Binary files differnew file mode 100644 index 0000000..a02def3 --- /dev/null +++ b/src/main/resources/cdn/d6_6.png diff --git a/src/main/resources/cdn/d8_1.png b/src/main/resources/cdn/d8_1.png Binary files differnew file mode 100644 index 0000000..14d2dfb --- /dev/null +++ b/src/main/resources/cdn/d8_1.png diff --git a/src/main/resources/cdn/d8_2.png b/src/main/resources/cdn/d8_2.png Binary files differnew file mode 100644 index 0000000..26b8f63 --- /dev/null +++ b/src/main/resources/cdn/d8_2.png diff --git a/src/main/resources/cdn/d8_3.png b/src/main/resources/cdn/d8_3.png Binary files differnew file mode 100644 index 0000000..1776d70 --- /dev/null +++ b/src/main/resources/cdn/d8_3.png diff --git a/src/main/resources/cdn/d8_4.png b/src/main/resources/cdn/d8_4.png Binary files differnew file mode 100644 index 0000000..2332c29 --- /dev/null +++ b/src/main/resources/cdn/d8_4.png diff --git a/src/main/resources/cdn/d8_5.png b/src/main/resources/cdn/d8_5.png Binary files differnew file mode 100644 index 0000000..fc5a8a6 --- /dev/null +++ b/src/main/resources/cdn/d8_5.png diff --git a/src/main/resources/cdn/d8_6.png b/src/main/resources/cdn/d8_6.png Binary files differnew file mode 100644 index 0000000..dfd27b3 --- /dev/null +++ b/src/main/resources/cdn/d8_6.png diff --git a/src/main/resources/cdn/d8_7.png b/src/main/resources/cdn/d8_7.png Binary files differnew file mode 100644 index 0000000..85d3ee2 --- /dev/null +++ b/src/main/resources/cdn/d8_7.png diff --git a/src/main/resources/cdn/d8_8.png b/src/main/resources/cdn/d8_8.png Binary files differnew file mode 100644 index 0000000..20f4f8d --- /dev/null +++ b/src/main/resources/cdn/d8_8.png diff --git a/src/main/resources/cdn/gay.png b/src/main/resources/cdn/gay.png Binary files differnew file mode 100644 index 0000000..a886509 --- /dev/null +++ b/src/main/resources/cdn/gay.png diff --git a/src/main/resources/cdn/headpat.png b/src/main/resources/cdn/headpat.png Binary files differnew file mode 100644 index 0000000..a8f49db --- /dev/null +++ b/src/main/resources/cdn/headpat.png diff --git a/src/main/resources/cdn/laptop.png b/src/main/resources/cdn/laptop.png Binary files differnew file mode 100644 index 0000000..685dd99 --- /dev/null +++ b/src/main/resources/cdn/laptop.png diff --git a/src/main/resources/cdn/space.jpg b/src/main/resources/cdn/space.jpg Binary files differnew file mode 100644 index 0000000..8e5a990 --- /dev/null +++ b/src/main/resources/cdn/space.jpg diff --git a/src/main/resources/cdn/theMoreYouKnow.png b/src/main/resources/cdn/theMoreYouKnow.png Binary files differnew file mode 100644 index 0000000..1690eb7 --- /dev/null +++ b/src/main/resources/cdn/theMoreYouKnow.png diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f050e38..7612f48 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -45,11 +45,15 @@ botName: "Ken" # Example: "ChFRPDF" supportServer: "" -# Send welcome messages when a player joins the server -welcomeMessages: true +# This is the cdn that will contain all KenBoReborn images, I host one myself so there is no +# need for you to use your own. If you want, you can use your own. A cdn is required because discord +# requires a url for embeds instead of just uploading an image. +cdn: "https://cdn.tylermurphy.net/ken/" -# Send level up messages when a player levels up -levelMessages: true +# Fetch image url. For the gif generation commands, instead of sending discord a url to a cdn, Ken has to +# manually pull images to work on them to create the gifs. For most people, you can just keep it as the cdn, and +# have images automatically update. But if you want, you can set images to locally fetch instead from inside the jar. +fetchLocal: false # The RGB color value of the discord bot. Used for bot theming. colors: |