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 86d0c570..a262587b 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 @@ -10,7 +10,6 @@ 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; import net.dv8tion.jda.api.EmbedBuilder; import javax.imageio.ImageIO; @@ -18,10 +17,9 @@ import java.awt.geom.Ellipse2D; import java.awt.image.BufferedImage; import java.io.*; -import java.net.URL; import java.util.*; -import static com.diamondfire.helpbot.util.textgen.CacheData.CacheData; //use this if you want to add more data to ai sam +import static com.diamondfire.helpbot.util.textgen.CacheData.CacheData; import static com.diamondfire.helpbot.util.textgen.MarkovManipulation.getNextWord; public class SamQuotesCommand extends Command { @@ -42,9 +40,13 @@ public HelpContext getHelpContext() { new HelpContextArgument() .name("get"), new HelpContextArgument() - .name("submit"), + .name("submit (beginning word)"), new HelpContextArgument() - .name("generate")); + .name("generate"), + new HelpContextArgument() + .name("reload"), + new HelpContextArgument() + .name("count")); } @Override @@ -211,6 +213,8 @@ public void run(CommandEvent event) { ); event.reply(success); + + addSamquote(messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", "")); } catch (IOException e) { @@ -255,8 +259,28 @@ public void run(CommandEvent event) { startingTexts.add(line.split(" ")[0]); } - String word = startingTexts.get((int) Math.rint(Math.random() * startingTexts.size())); + String word; + if (event.getMessage().getContentRaw().split(" ").length == 2) { + + word = startingTexts.get((int) Math.rint(Math.random() * startingTexts.size())); + } else { + + if (startingTexts.contains(event.getMessage().getContentRaw().split(" ")[2])) { + + word = event.getMessage().getContentRaw().split(" ")[2]; + + } else { + + PresetBuilder error = new PresetBuilder(); + + error.withPreset( + new InformativeReply(InformativeReplyType.ERROR, "Sam has never started a message with this word before!") + ); + + return; + } + } String string = ""; for (int i = 0; i < 50; i++) { @@ -418,6 +442,25 @@ public void run(CommandEvent event) { event.getChannel().sendMessage(builder.build()).addFile(samQuote, "quote.png").queue(); + } else if (event.getArgument("action").equals("reload")) { + + try { + CacheData(); + } catch (IOException e) { + e.printStackTrace(); + } + + } else if (event.getArgument("action").equals("count")) { + + String[] strings = ExternalFiles.SAM_DIR.list(); + + EmbedBuilder builder = new EmbedBuilder(); + builder.setTitle("Total Sam Quotes:"); + builder.setDescription("" + strings.length); + builder.setColor(new Color(87, 177, 71)); + + event.getChannel().sendMessage(builder.build()).queue(); + } else { String[] strings = ExternalFiles.SAM_DIR.list(); @@ -437,7 +480,35 @@ public void run(CommandEvent event) { public ArgumentSet compileArguments() { return new ArgumentSet() .addArgument("action", - new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit", "generate", "get")).optional(null)); + new SingleArgumentContainer<>(new DefinedObjectArgument<>("submit", "generate", "get", "reload", "count")).optional(null)); + } + + private void addSamquote(String samquote) { + + try { + + File file = new File("samquotes.txt"); + BufferedReader br = new BufferedReader(new FileReader(file)); + + String line; + String newFile = ""; + + while ((line = br.readLine()) != null) { + + if (line != samquote) { newFile += line + "\n"; } + } + + newFile += samquote; + + FileWriter fileWriter = new FileWriter("samquotes.txt"); + fileWriter.write(newFile); + fileWriter.close(); + + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } } -} \ No newline at end of file +}