Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ src/main/java/org.jointheleague.Launcher.java
.travis.yml
run.sh
appspec.yml
/.gradle/
1 change: 1 addition & 0 deletions DiscordBot_v2
Submodule DiscordBot_v2 added at a89f5d
2 changes: 2 additions & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/main/
/test/
Binary file not shown.
5 changes: 5 additions & 0 deletions src/main/java/org/jointheleague/discord_bot/DiscordBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//api = new DiscordApiBuilder().setToken(token).setAllIntents().login().join();


//System.out.println("hello");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
System.out.println("To authorize your bot, send your teacher this link: " + api.createBotInvite()

Expand All @@ -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){
Expand Down
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
gameStarted = false;

}

}
}

}