-
Notifications
You must be signed in to change notification settings - Fork 23
Feature1/aarit jayaswal #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ src/main/java/org.jointheleague.Launcher.java | |
| .travis.yml | ||
| run.sh | ||
| appspec.yml | ||
| /.gradle/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| /main/ | ||
| /test/ |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -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"); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| //Print the URL to invite the bot | ||||
| if (printInvite) { | ||||
| System.out.println("To authorize your bot, send your teacher this link: " + api.createBotInvite() | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
|
|
@@ -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){ | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -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; | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| 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); | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| 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; | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| } | ||||
|
|
||||
| } | ||||
| } | ||||
|
|
||||
| } | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.