From 34322ac0c0231d47a5882e7797a4a09514c34804 Mon Sep 17 00:00:00 2001 From: Ymerald Date: Mon, 1 Mar 2021 22:11:14 -0800 Subject: [PATCH 1/6] Submitting Samquotes time :)) --- .../command/impl/other/SamQuotesCommand.java | 55 ------------------- 1 file changed, 55 deletions(-) delete mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java deleted file mode 100644 index 2a43c35f..00000000 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.diamondfire.helpbot.bot.command.impl.other; - -import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; -import com.diamondfire.helpbot.bot.command.help.*; -import com.diamondfire.helpbot.bot.command.impl.Command; -import com.diamondfire.helpbot.bot.command.permissions.Permission; -import com.diamondfire.helpbot.bot.events.CommandEvent; -import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; -import net.dv8tion.jda.api.EmbedBuilder; - -import java.awt.*; -import java.io.File; -import java.util.Random; - -public class SamQuotesCommand extends Command { - - private static final Random random = new Random(); - - @Override - public String getName() { - return "samquote"; - } - - @Override - public HelpContext getHelpContext() { - return new HelpContext() - .description("Gets a quote from Sam the Man.") - .category(CommandCategory.OTHER); - } - - @Override - public ArgumentSet compileArguments() { - return new ArgumentSet(); - } - - @Override - public Permission getPermission() { - return Permission.USER; - } - - @Override - public void run(CommandEvent event) { - String[] strings = ExternalFiles.SAM_DIR.list(); - File file = new File(ExternalFiles.SAM_DIR, strings[random.nextInt(strings.length)]); - EmbedBuilder builder = new EmbedBuilder(); - builder.setTitle("Sam Quote"); - builder.setImage("attachment://quote.png"); - builder.setColor(new Color(87, 177, 71)); - - event.getChannel().sendMessage(builder.build()).addFile(file, "quote.png").queue(); - } - -} - - From 698affbe5ec50a081f1d9f477125a1c6724f8128 Mon Sep 17 00:00:00 2001 From: Ymerald Date: Mon, 1 Mar 2021 22:13:47 -0800 Subject: [PATCH 2/6] Submitting Samquotes time v2 :)) --- .../command/impl/other/SamQuotesCommand.java | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java new file mode 100644 index 00000000..d338df8f --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -0,0 +1,217 @@ +package com.diamondfire.helpbot.bot.command.impl.other; + +import com.diamondfire.helpbot.bot.command.argument.ArgumentSet; +import com.diamondfire.helpbot.bot.command.argument.impl.parsing.types.SingleArgumentContainer; +import com.diamondfire.helpbot.bot.command.argument.impl.types.DefinedObjectArgument; +import com.diamondfire.helpbot.bot.command.help.*; +import com.diamondfire.helpbot.bot.command.impl.Command; +import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.events.CommandEvent; +import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; +import com.diamondfire.helpbot.util.IOUtil; +import net.dv8tion.jda.api.EmbedBuilder; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.Ellipse2D; +import java.awt.image.BufferedImage; +import java.io.*; +import java.util.*; + +public class SamQuotesCommand extends Command { + + private static final Random random = new Random(); + + @Override + public String getName() { + return "samquote"; + } + + @Override + public HelpContext getHelpContext() { + return new HelpContext() + .description("Gets a quote from Sam the Man.") + .category(CommandCategory.OTHER); + } + + @Override + public Permission getPermission() { + return Permission.USER; + } + + @Override + public void run(CommandEvent event) { + + if (event.getArgument("action") == "submit") { + + String[] message = event.getMessage().getContentRaw().split("/"); + + long channelID = Long.parseLong(message[5]); + long messageID = Long.parseLong(message[6]); + + Objects.requireNonNull(event.getGuild().getTextChannelById(channelID)).retrieveMessageById(messageID).queue((messageText) -> { + + if(messageText.getAuthor().getIdLong() == 132092551782989824L) { + + String samProfilePic = messageText.getAuthor().getAvatarUrl(); + + try { + + BufferedImage samPfp = ImageIO.read(Objects.requireNonNull(IOUtil.getFileFromSite(samProfilePic, "sampfp.png"))); + + String text = " " + messageText.getContentRaw().replaceAll("[^a-zA-Z0-9 ]", ""); + + int pfpWidth = samPfp.getWidth(); + + //crop pfp into a circle + + BufferedImage circleBuffer = new BufferedImage(pfpWidth, pfpWidth, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2 = circleBuffer.createGraphics(); + + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + g2.setClip(new Ellipse2D.Float(0, 0, pfpWidth, pfpWidth)); + g2.drawImage(samPfp, 0, 0, pfpWidth, pfpWidth, null); + + //convert text into image + + BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2d = img.createGraphics(); + + Font font = new Font("Whitney", Font.PLAIN, 14); + g2d.setFont(font); + FontMetrics fm = g2d.getFontMetrics(); + + int width = fm.stringWidth(text); + int height = fm.getHeight() * 2; + + g2d.dispose(); + + img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + + g2d = img.createGraphics(); + + g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); + g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + g2d.setFont(font); + g2d.setColor(Color.WHITE); + g2d.drawString(text, 0, fm.getAscent() * 2.2f); + + g2d.dispose(); + + //convert SamMan_ into image + + BufferedImage img2 = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2d2 = img2.createGraphics(); + + Font font2 = new Font("Whitney", Font.BOLD, 14); + g2d2.setFont(font2); + FontMetrics fm2 = g2d.getFontMetrics(); + + int width2 = fm2.stringWidth(" SamMan_"); + int height2 = fm2.getHeight(); + + g2d2.dispose(); + + img2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_ARGB); + + g2d2 = img2.createGraphics(); + + g2d2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); + g2d2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g2d2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + g2d2.setFont(font); + Color nameColor = new Color(45, 102, 212); + g2d2.setColor(nameColor); + g2d2.drawString(" SamMan_", 0, fm2.getAscent()); + + g2d2.dispose(); + + //create background image + + BufferedImage combined = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, img.getHeight() + 10, BufferedImage.TYPE_INT_ARGB); + + Graphics g = combined.getGraphics(); + + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + Color bgColor = new Color(54,57,63); + + BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, height + 10, BufferedImage.TYPE_INT_ARGB); + Graphics2D bgg = bg.createGraphics(); + bgg.setPaint (bgColor); + bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); + bgg.dispose(); + + //combine images + + g.drawImage(bg, 0, 0, bgColor, null); + g.drawImage(img, 5, 5, bgColor, null); + g.drawImage(img2, 5, 5, bgColor, null); + g.drawImage(circleBuffer, 5, 5, height, height, bgColor, null); + + //save image + + File imageFile = new File(ExternalFiles.SAM_DIR, messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "") + ".png"); + ImageIO.write(combined, "PNG", imageFile); + + event.getChannel().sendFile(imageFile).queue(); + + } catch (IOException e) { + + e.printStackTrace(); + + } + + } else { + + EmbedBuilder eb = new EmbedBuilder(); + eb.setTitle("Error!"); + eb.setColor(Color.RED); + eb.setDescription("That's not a samquote!"); + + event.getChannel().sendMessage(eb.build()).queue(); + + } + + }); + + } else { + + String[] strings = ExternalFiles.SAM_DIR.list(); + File file = new File(ExternalFiles.SAM_DIR, strings[random.nextInt(strings.length)]); + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Sam Quote"); + builder.setImage("attachment://quote.png"); + builder.setColor(new Color(87, 177, 71)); + + event.getChannel().sendMessage(builder.build()).addFile(file, "quote.png").queue(); + + } + + } + + @Override + public ArgumentSet compileArguments() { + return new ArgumentSet() + .addArgument("action", + new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit")).optional(null)); + } + +} \ No newline at end of file From b200095509397339743838fbdcafcb3cf8e55de9 Mon Sep 17 00:00:00 2001 From: Ymerald Date: Tue, 2 Mar 2021 10:21:51 -0800 Subject: [PATCH 3/6] Submitting Samquotes time v3 :)) --- .../command/impl/other/SamQuotesCommand.java | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java index d338df8f..8a070a90 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -6,6 +6,8 @@ import com.diamondfire.helpbot.bot.command.help.*; import com.diamondfire.helpbot.bot.command.impl.Command; import com.diamondfire.helpbot.bot.command.permissions.Permission; +import com.diamondfire.helpbot.bot.command.reply.PresetBuilder; +import com.diamondfire.helpbot.bot.command.reply.feature.informative.*; import com.diamondfire.helpbot.bot.events.CommandEvent; import com.diamondfire.helpbot.sys.externalfile.ExternalFiles; import com.diamondfire.helpbot.util.IOUtil; @@ -46,10 +48,21 @@ public void run(CommandEvent event) { String[] message = event.getMessage().getContentRaw().split("/"); + if(message.length != 6 || message[5] == null || message[6] == null || message[5].length() != 18 || message[6].length() != 18) { + + PresetBuilder error = new PresetBuilder(); + + error.withPreset( + new InformativeReply(InformativeReplyType.ERROR, "This is not a samquote!") + ); + + return; + } + long channelID = Long.parseLong(message[5]); long messageID = Long.parseLong(message[6]); - Objects.requireNonNull(event.getGuild().getTextChannelById(channelID)).retrieveMessageById(messageID).queue((messageText) -> { + event.getGuild().getTextChannelById(channelID).retrieveMessageById(messageID).queue((messageText) -> { if(messageText.getAuthor().getIdLong() == 132092551782989824L) { @@ -171,7 +184,11 @@ public void run(CommandEvent event) { File imageFile = new File(ExternalFiles.SAM_DIR, messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "") + ".png"); ImageIO.write(combined, "PNG", imageFile); - event.getChannel().sendFile(imageFile).queue(); + PresetBuilder success = new PresetBuilder(); + + success.withPreset( + new InformativeReply(InformativeReplyType.SUCCESS, "Your SamQuote has been added!") + ); } catch (IOException e) { @@ -180,13 +197,12 @@ public void run(CommandEvent event) { } } else { - - EmbedBuilder eb = new EmbedBuilder(); - eb.setTitle("Error!"); - eb.setColor(Color.RED); - eb.setDescription("That's not a samquote!"); - - event.getChannel().sendMessage(eb.build()).queue(); + + PresetBuilder error = new PresetBuilder(); + + error.withPreset( + new InformativeReply(InformativeReplyType.ERROR, "This is not a samquote!") + ); } From 5bc86a5cc4b6aa1dac4c9938e2080e41003d6e96 Mon Sep 17 00:00:00 2001 From: Ymerald Date: Tue, 9 Mar 2021 17:37:20 -0800 Subject: [PATCH 4/6] AI Samquotes (+ text gen util) --- .../command/impl/other/SamQuotesCommand.java | 168 +++++++++++++++++- .../helpbot/util/textgen/CacheData.java | 39 ++++ .../util/textgen/MarkovManipulation.java | 113 ++++++++++++ 3 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java create mode 100644 src/main/java/com/diamondfire/helpbot/util/textgen/MarkovManipulation.java diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java index 8a070a90..3896f38c 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -20,6 +20,8 @@ import java.io.*; import java.util.*; +import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.getNextWord; + public class SamQuotesCommand extends Command { private static final Random random = new Random(); @@ -207,7 +209,171 @@ public void run(CommandEvent event) { } }); + } else if (event.getArgument("action") == "generate") { + + File file = new File("samquotes.txt"); + + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + ArrayList startingTexts = new ArrayList<>(); + + String line = null; + while (true) { + try { + if ((line = br.readLine()) == null) break; + } catch (IOException e) { + e.printStackTrace(); + } + + startingTexts.add(line.split(" ")[0]); + } + + String word = startingTexts.get((int) Math.rint(Math.random() * startingTexts.size())); + + String string = ""; + for (int i = 0; i < 50; i++) { + + if (word == null || word.equals(".")) break; + string += word + " "; + try { + word = getNextWord(word); + } catch (IOException e) { + e.printStackTrace(); + } + } + + BufferedImage samPfp = null; + try { + samPfp = ImageIO.read(Objects.requireNonNull(IOUtil.getFileFromSite("https://cdn.discordapp.com/avatars/132092551782989824/14368bddad31d5fb5501acc8338a8ab4.png?size=1024", "sampfp.png"))); + } catch (IOException e) { + e.printStackTrace(); + } + + String text = " " + string; + + int pfpWidth = samPfp.getWidth(); + + //crop pfp into a circle + + BufferedImage circleBuffer = new BufferedImage(pfpWidth, pfpWidth, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2 = circleBuffer.createGraphics(); + + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + g2.setClip(new Ellipse2D.Float(0, 0, pfpWidth, pfpWidth)); + g2.drawImage(samPfp, 0, 0, pfpWidth, pfpWidth, null); + + //convert text into image + + BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2d = img.createGraphics(); + + Font font = new Font("Whitney", Font.PLAIN, 14); + g2d.setFont(font); + FontMetrics fm = g2d.getFontMetrics(); + + int width = fm.stringWidth(text); + int height = fm.getHeight() * 2; + + g2d.dispose(); + + img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); + + g2d = img.createGraphics(); + + g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); + g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + g2d.setFont(font); + g2d.setColor(Color.WHITE); + g2d.drawString(text, 0, fm.getAscent() * 2.2f); + + g2d.dispose(); + + //convert SamMan_ into image + + BufferedImage img2 = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); + + Graphics2D g2d2 = img2.createGraphics(); + + Font font2 = new Font("Whitney", Font.BOLD, 14); + g2d2.setFont(font2); + FontMetrics fm2 = g2d.getFontMetrics(); + + int width2 = fm2.stringWidth(" SamMan_"); + int height2 = fm2.getHeight(); + + g2d2.dispose(); + + img2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_ARGB); + + g2d2 = img2.createGraphics(); + + g2d2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); + g2d2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); + g2d2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + + g2d2.setFont(font); + Color nameColor = new Color(45, 102, 212); + g2d2.setColor(nameColor); + g2d2.drawString(" SamMan_", 0, fm2.getAscent()); + + g2d2.dispose(); + + //create background image + + BufferedImage combined = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, img.getHeight() + 10, BufferedImage.TYPE_INT_ARGB); + + Graphics g = combined.getGraphics(); + + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + Color bgColor = new Color(54,57,63); + + BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, height + 10, BufferedImage.TYPE_INT_ARGB); + Graphics2D bgg = bg.createGraphics(); + bgg.setPaint (bgColor); + bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); + bgg.dispose(); + + //combine images + + g.drawImage(bg, 0, 0, bgColor, null); + g.drawImage(img, 5, 5, bgColor, null); + g.drawImage(img2, 5, 5, bgColor, null); + g.drawImage(circleBuffer, 5, 5, height, height, bgColor, null); + + File samQuote = new File(ExternalFiles.IMAGES_DIR, "quote.png"); + try { + ImageIO.write(combined, "PNG", samQuote); + } catch (IOException e) { + e.printStackTrace(); + } + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Sam Quote"); + builder.setImage("attachment://quote.png"); + builder.setColor(new Color(87, 177, 71)); + + event.getChannel().sendMessage(builder.build()).addFile(samQuote, "quote.png").queue(); + } else { String[] strings = ExternalFiles.SAM_DIR.list(); @@ -227,7 +393,7 @@ public void run(CommandEvent event) { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("action", - new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit")).optional(null)); + new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit", "generate")).optional(null)); } } \ No newline at end of file diff --git a/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java b/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java new file mode 100644 index 00000000..c016036e --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/textgen/CacheData.java @@ -0,0 +1,39 @@ +package com.diamondfire.helpbot.util.textgen; + +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; + +import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.addWord; + +public class CacheData { + + public static void CacheData() throws IOException { + + File file = new File("samquotes.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + + FileWriter fileWriter = new FileWriter("markov.txt"); + fileWriter.write(""); + fileWriter.close(); + + String line; + while ((line = br.readLine()) != null) { + + ArrayList splitLine = new ArrayList<>(); + splitLine.addAll(Arrays.asList(line.split(" "))); + + for (int i = 0; i < splitLine.size(); i++) { + + if (i == splitLine.size() - 1) { + + addWord(splitLine.get(i), "."); + + } else { + + addWord(splitLine.get(i), splitLine.get(i + 1)); + } + } + } + } +} diff --git a/src/main/java/com/diamondfire/helpbot/util/textgen/MarkovManipulation.java b/src/main/java/com/diamondfire/helpbot/util/textgen/MarkovManipulation.java new file mode 100644 index 00000000..0c8100a5 --- /dev/null +++ b/src/main/java/com/diamondfire/helpbot/util/textgen/MarkovManipulation.java @@ -0,0 +1,113 @@ +package com.diamondfire.helpbot.util.textgen; + +import java.io.*; +import java.util.ArrayList; + +public class MarkovManipulation { + + public static String getNextWord(String word) throws IOException { + + File file = new File("markov.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + + float num = (float) Math.random(); + float currentNum = 0f; + + String line; + String[] split; + String[] split2; + while ((line = br.readLine()) != null) { + + split = line.split("//"); + if (split[0].split("/")[0].equals(word)) { + + for (int i = 1; i < split.length; i++) { + + split2 = split[i].split("/"); + currentNum += Float.parseFloat(split2[1]); + + if (currentNum >= num) { + + return split2[0]; + } + } + } + } + + return null; + } + + public static void addWord(String word, String word2) throws IOException { + + File file = new File("markov.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + + ArrayList newFile = new ArrayList<>(); + String newLine; + float newChance; + int newAmount; + + String line; + String[] split; + String[] split2; + + boolean addNewWord = true; + boolean addNewLine = true; + + while ((line = br.readLine()) != null) { + + split = line.split("//"); + + String wordTest = split[0].split("/")[0]; + + newAmount = Integer.parseInt(split[0].split("/")[1]) + 1; + + if (wordTest.equals(word)) { + + newLine = split[0].split("/")[0] + "/" + newAmount; + + for (int i = 1; i < split.length; i++) { + + split2 = split[i].split("/"); + + if (split2[0].equals(word2)) { + + newChance = (Float.parseFloat(split[0].split("/")[1]) * Float.parseFloat(split2[1]) + 1) / newAmount; + newLine += "//" + split2[0] + "/" + newChance; + + addNewWord = false; + + } else { + + newChance = (Float.parseFloat(split[0].split("/")[1]) * Float.parseFloat(split2[1])) / newAmount; + newLine += "//" + split2[0] + "/" + newChance; + } + } + + if (addNewWord) { + + newLine += "//" + word2 + "/" + (1f / newAmount); + } + + newFile.add(newLine); + + addNewLine = false; + + } else { + + newFile.add(line); + } + } + + if (addNewLine) { + + newFile.add(word + "/1//" + word2 + "/1"); + } + + String newFileString = String.join("\n", newFile); + + FileWriter fileWriter = new FileWriter("markov.txt"); + fileWriter.write(newFileString); + fileWriter.close(); + } +} From 45d36326938bd389d867a0ecb5c113d44703c98e Mon Sep 17 00:00:00 2001 From: Ymerald Date: Tue, 9 Mar 2021 18:14:13 -0800 Subject: [PATCH 5/6] High res samquotes --- .../command/impl/other/SamQuotesCommand.java | 106 +++++++++--------- 1 file changed, 54 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java index 3896f38c..3e4ed727 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -50,7 +50,9 @@ public void run(CommandEvent event) { String[] message = event.getMessage().getContentRaw().split("/"); - if(message.length != 6 || message[5] == null || message[6] == null || message[5].length() != 18 || message[6].length() != 18) { + System.out.println(message.length); + + if(message.length != 7 || message[5] == null || message[6] == null || message[5].length() != 18 || message[6].length() != 18) { PresetBuilder error = new PresetBuilder(); @@ -75,39 +77,39 @@ public void run(CommandEvent event) { BufferedImage samPfp = ImageIO.read(Objects.requireNonNull(IOUtil.getFileFromSite(samProfilePic, "sampfp.png"))); String text = " " + messageText.getContentRaw().replaceAll("[^a-zA-Z0-9 ]", ""); - - int pfpWidth = samPfp.getWidth(); - + + int pfpWidth = samPfp.getWidth() * 10; + //crop pfp into a circle - + BufferedImage circleBuffer = new BufferedImage(pfpWidth, pfpWidth, BufferedImage.TYPE_INT_ARGB); - + Graphics2D g2 = circleBuffer.createGraphics(); - + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); - + g2.setClip(new Ellipse2D.Float(0, 0, pfpWidth, pfpWidth)); g2.drawImage(samPfp, 0, 0, pfpWidth, pfpWidth, null); - + //convert text into image - + BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - + Graphics2D g2d = img.createGraphics(); - - Font font = new Font("Whitney", Font.PLAIN, 14); + + Font font = new Font("Whitney", Font.PLAIN, 140); g2d.setFont(font); FontMetrics fm = g2d.getFontMetrics(); - + int width = fm.stringWidth(text); int height = fm.getHeight() * 2; - + g2d.dispose(); - + img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - + g2d = img.createGraphics(); - + g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); @@ -116,32 +118,32 @@ public void run(CommandEvent event) { g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - + g2d.setFont(font); g2d.setColor(Color.WHITE); g2d.drawString(text, 0, fm.getAscent() * 2.2f); - + g2d.dispose(); - + //convert SamMan_ into image - + BufferedImage img2 = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); - + Graphics2D g2d2 = img2.createGraphics(); - - Font font2 = new Font("Whitney", Font.BOLD, 14); + + Font font2 = new Font("Whitney", Font.BOLD, 140); g2d2.setFont(font2); - FontMetrics fm2 = g2d.getFontMetrics(); - - int width2 = fm2.stringWidth(" SamMan_"); + FontMetrics fm2 = g2d2.getFontMetrics(); + + int width2 = fm2.stringWidth(" SamMan_"); int height2 = fm2.getHeight(); - + g2d2.dispose(); - + img2 = new BufferedImage(width2, height2, BufferedImage.TYPE_INT_ARGB); - + g2d2 = img2.createGraphics(); - + g2d2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2d2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); @@ -150,32 +152,32 @@ public void run(CommandEvent event) { g2d2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); - + g2d2.setFont(font); Color nameColor = new Color(45, 102, 212); g2d2.setColor(nameColor); - g2d2.drawString(" SamMan_", 0, fm2.getAscent()); - + g2d2.drawString(" SamMan_", 0, fm2.getAscent()); + g2d2.dispose(); - + //create background image - + BufferedImage combined = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, img.getHeight() + 10, BufferedImage.TYPE_INT_ARGB); - + Graphics g = combined.getGraphics(); - + g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - + Color bgColor = new Color(54,57,63); - - BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, height + 10, BufferedImage.TYPE_INT_ARGB); + + BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 30, height + 30, BufferedImage.TYPE_INT_ARGB); Graphics2D bgg = bg.createGraphics(); bgg.setPaint (bgColor); bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); bgg.dispose(); - + //combine images - + g.drawImage(bg, 0, 0, bgColor, null); g.drawImage(img, 5, 5, bgColor, null); g.drawImage(img2, 5, 5, bgColor, null); @@ -254,9 +256,9 @@ public void run(CommandEvent event) { e.printStackTrace(); } - String text = " " + string; + String text = " " + string; - int pfpWidth = samPfp.getWidth(); + int pfpWidth = samPfp.getWidth() * 10; //crop pfp into a circle @@ -275,7 +277,7 @@ public void run(CommandEvent event) { Graphics2D g2d = img.createGraphics(); - Font font = new Font("Whitney", Font.PLAIN, 14); + Font font = new Font("Whitney", Font.PLAIN, 140); g2d.setFont(font); FontMetrics fm = g2d.getFontMetrics(); @@ -309,11 +311,11 @@ public void run(CommandEvent event) { Graphics2D g2d2 = img2.createGraphics(); - Font font2 = new Font("Whitney", Font.BOLD, 14); + Font font2 = new Font("Whitney", Font.BOLD, 140); g2d2.setFont(font2); - FontMetrics fm2 = g2d.getFontMetrics(); + FontMetrics fm2 = g2d2.getFontMetrics(); - int width2 = fm2.stringWidth(" SamMan_"); + int width2 = fm2.stringWidth(" SamMan_"); int height2 = fm2.getHeight(); g2d2.dispose(); @@ -334,7 +336,7 @@ public void run(CommandEvent event) { g2d2.setFont(font); Color nameColor = new Color(45, 102, 212); g2d2.setColor(nameColor); - g2d2.drawString(" SamMan_", 0, fm2.getAscent()); + g2d2.drawString(" SamMan_", 0, fm2.getAscent()); g2d2.dispose(); @@ -348,7 +350,7 @@ public void run(CommandEvent event) { Color bgColor = new Color(54,57,63); - BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 10, height + 10, BufferedImage.TYPE_INT_ARGB); + BufferedImage bg = new BufferedImage(Math.max(img.getWidth(), img2.getWidth()) + 30, height + 30, BufferedImage.TYPE_INT_ARGB); Graphics2D bgg = bg.createGraphics(); bgg.setPaint (bgColor); bgg.fillRect (0, 0, bg.getWidth(), bg.getHeight()); From 1be9cb53fc6f272b29437c3bcf201742cc9a4b12 Mon Sep 17 00:00:00 2001 From: Ymerald Date: Tue, 9 Mar 2021 23:34:30 -0800 Subject: [PATCH 6/6] small bugfix --- .../command/impl/other/SamQuotesCommand.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java index 3e4ed727..696cd329 100644 --- a/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java +++ b/src/main/java/com/diamondfire/helpbot/bot/command/impl/other/SamQuotesCommand.java @@ -74,7 +74,7 @@ public void run(CommandEvent event) { try { - BufferedImage samPfp = ImageIO.read(Objects.requireNonNull(IOUtil.getFileFromSite(samProfilePic, "sampfp.png"))); + BufferedImage samPfp = ImageIO.read(IOUtil.getFileFromSite(samProfilePic, "sampfp.png")); String text = " " + messageText.getContentRaw().replaceAll("[^a-zA-Z0-9 ]", ""); @@ -251,7 +251,7 @@ public void run(CommandEvent event) { BufferedImage samPfp = null; try { - samPfp = ImageIO.read(Objects.requireNonNull(IOUtil.getFileFromSite("https://cdn.discordapp.com/avatars/132092551782989824/14368bddad31d5fb5501acc8338a8ab4.png?size=1024", "sampfp.png"))); + samPfp = ImageIO.read(IOUtil.getFileFromSite("https://cdn.discordapp.com/avatars/132092551782989824/14368bddad31d5fb5501acc8338a8ab4.png?size=1024", "sampfp.png")); } catch (IOException e) { e.printStackTrace(); } @@ -334,7 +334,29 @@ public void run(CommandEvent event) { g2d2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); g2d2.setFont(font); - Color nameColor = new Color(45, 102, 212); + + double colorChance = Math.random(); + + + Color nameColor; + + if (colorChance < 0.1) { + + nameColor = new Color(255, 153, 227); + + } else if (colorChance < 0.3) { + + nameColor = new Color(255, 225, 76); + + } else if (colorChance < 0.6) { + + nameColor = new Color(35, 255, 38); + + } else { + + nameColor = new Color(45, 102, 212); + } + g2d2.setColor(nameColor); g2d2.drawString(" SamMan_", 0, fm2.getAscent());