diff --git a/.gitignore b/.gitignore index 19f55917..281d47b4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ src/main/java/org.jointheleague.Launcher.java .travis.yml run.sh appspec.yml +/.gradle/ diff --git a/DiscordBot_v2 b/DiscordBot_v2 new file mode 160000 index 00000000..a89f5d40 --- /dev/null +++ b/DiscordBot_v2 @@ -0,0 +1 @@ +Subproject commit a89f5d4095c34d84f8fc3ced91c77404e900bd0d diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 00000000..7eed456b --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,2 @@ +/main/ +/test/ diff --git a/build/tmp/compileJava/previous-compilation-data.bin b/build/tmp/compileJava/previous-compilation-data.bin new file mode 100644 index 00000000..e236787e Binary files /dev/null and b/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/src/main/java/org/jointheleague/discord_bot/DiscordBot.java b/src/main/java/org/jointheleague/discord_bot/DiscordBot.java index ae863505..b06e52d4 100644 --- a/src/main/java/org/jointheleague/discord_bot/DiscordBot.java +++ b/src/main/java/org/jointheleague/discord_bot/DiscordBot.java @@ -11,6 +11,7 @@ import org.jointheleague.features.examples.first_features.RandomNumber; import org.jointheleague.features.help_embed.HelpListener; import org.jointheleague.features.student.first_feature.FeatureOne; +import org.jointheleague.features.student.first_feature.Trivia; public class DiscordBot { @@ -30,8 +31,11 @@ public DiscordBot(String token, String channelName) { public void connect(boolean printInvite) { + //System.out.println("hello"+ token); api = new DiscordApiBuilder().setToken(token).addIntents(Intent.MESSAGE_CONTENT).login().join(); + //api = new DiscordApiBuilder().setToken(token).setAllIntents().login().join(); + //System.out.println("hello"); //Print the URL to invite the bot if (printInvite) { System.out.println("To authorize your bot, send your teacher this link: " + api.createBotInvite() @@ -50,6 +54,7 @@ public void connect(boolean printInvite) { addFeature(new HighLowGame(channelName)); addFeature(new NewsApi(channelName)); addFeature(new CatFactsApi(channelName)); + addFeature(new Trivia(channelName)); } private void addFeature(Feature feature){ diff --git a/src/main/java/org/jointheleague/features/student/first_feature/Trivia.java b/src/main/java/org/jointheleague/features/student/first_feature/Trivia.java new file mode 100644 index 00000000..c3ea6596 --- /dev/null +++ b/src/main/java/org/jointheleague/features/student/first_feature/Trivia.java @@ -0,0 +1,60 @@ +package org.jointheleague.features.student.first_feature; + +import org.javacord.api.event.message.MessageCreateEvent; +import org.jointheleague.features.abstract_classes.Feature; +import org.jointheleague.features.help_embed.plain_old_java_objects.help_embed.HelpEmbed; + +import java.util.Random; + +public class Trivia extends Feature { + + public final String COMMAND = "!trivia"; + public boolean gameStarted = false; + int questionNumber; + String answer; + Random ran = new Random(); + public Trivia(String channelName) { + super(channelName); + + //Create a help embed to describe feature when !help command is sent + helpEmbed = new HelpEmbed( + COMMAND, + "Trivia questions for the user to answer. Start the game with !trivia and enter a guess using !trivia guess. E.g. !trivia b" + ); + } + + @Override + public void handle(MessageCreateEvent event) { + String messageContent = event.getMessageContent(); + + System.out.println(messageContent); + if (messageContent.equals(COMMAND)) { + questionNumber = ran.nextInt(1); + switch(questionNumber) { + case 0: + event.getChannel().sendMessage("Trivia:What is the main ingredient in guacamole?\na) Tomatoes\nb) Avocados\nc) Lemons\nd) Tortilla chips"); + answer = "b"; + } + } + //check a guess + else if (messageContent.contains(COMMAND) + && !messageContent.contains("Trivia:")) + { + + String guessMessage = messageContent.replaceAll(" ", "").replace(COMMAND, ""); + + if (guessMessage.equalsIgnoreCase(answer)) { + //tell them it's too low + event.getChannel().sendMessage(answer + " is correct!"); + } + else { + + event.getChannel().sendMessage("Wrong, the correct answer is " + answer); + //set numberToGuess back to 0 + gameStarted = false; + } + + } + } + +}