Skip to content
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@
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;
import java.awt.*;
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 {
Expand All @@ -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
Expand Down Expand Up @@ -211,6 +213,8 @@ public void run(CommandEvent event) {
);

event.reply(success);

addSamquote(messageText.getContentRaw().replaceAll("[^a-zA-Z0-9]", ""));

} catch (IOException e) {

Expand Down Expand Up @@ -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++) {

Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
}

}
}