trivia things

This commit is contained in:
nora 2021-01-22 22:52:38 +01:00
parent 7ffb771946
commit a30e1653ca
7 changed files with 80 additions and 14 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@ target\*
.idea/*
*.class
Secrets.java
src\main\java\com\github\nilstrieb\cofig/Secrets.java

View file

@ -1 +0,0 @@
[]

17
pom.xml
View file

@ -34,5 +34,22 @@
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.github.nilstrieb.core.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -128,7 +128,14 @@ public class TriviaCommand extends Command {
@Override
public void messageReceived(MessageReceivedEvent event) {
if (!event.getMessage().getContentRaw().startsWith(Config.PREFIX + "help")) {
if (event.getAuthor().getIdLong() == Config.NILS_ID && event.getMessage().getContentRaw().startsWith("debug")) {
answers[0] = "question";
answers[1] = "a;b;c;d";
answers[2] = "0";
answers[3] = "0";
new TriviaApproval(event, new TriviaQuestion(answers));
} else {
System.out.println(ConsoleColors.BLUE_BOLD + "[TriviaCommand.AddSection 121] Received Next Message: "
+ event.getMessage().getContentRaw() + " status: " + status + ConsoleColors.RESET);
answers[status] = event.getMessage().getContentRaw();

View file

@ -13,12 +13,17 @@ import com.github.nilstrieb.listener.ChannelMessageListener;
import com.github.nilstrieb.listener.CommandListener;
import com.github.nilstrieb.listener.ReactionEventListener;
import com.github.nilstrieb.listener.StartUpListener;
import com.github.nilstrieb.util.ConsoleColors;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.utils.Compression;
import javax.security.auth.login.LoginException;
import java.io.File;
import java.util.Scanner;
public class Main {
@ -31,6 +36,37 @@ public class Main {
JDA jda = builder.build();
setupCommands();
/* Thread t = new Thread(() -> {
Scanner scanner = new Scanner(System.in);
String line = scanner.nextLine();
while (!line.equals("exit")) {
if (line.startsWith("send")) {
System.out.println("GuildID");
line = scanner.nextLine();
Guild guild = jda.getGuildById(line);
if (guild != null) {
System.out.println("TextChannelID");
line = scanner.nextLine();
TextChannel textChannel = guild.getTextChannelById(line);
if (textChannel != null) {
System.out.println("Message");
line = scanner.nextLine();
if (!line.equals("")) {
textChannel.sendMessage(line).queue();
}
}
}
} else if(line.startsWith("filetest")){
File f = new File("hallo.eric");
System.out.println(ConsoleColors.BLUE + "[TriviaQuestionData 80] File path " + f.getAbsolutePath() + ConsoleColors.RESET);
}
line = scanner.nextLine();
}
System.exit(0);
});
t.start();*/
}
private static void setupCommands() {

View file

@ -2,7 +2,6 @@ package com.github.nilstrieb.util.trivia;
import com.github.nilstrieb.util.ConsoleColors;
import com.google.gson.Gson;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import java.io.*;
import java.util.ArrayList;
@ -11,9 +10,10 @@ import java.util.Random;
public class TriviaQuestionData {
static List<List<TriviaQuestion>> questions = new ArrayList<>();
private static final List<TriviaQuestion> newQuestions = new ArrayList<>();
private static final Random random = new Random();
private static final String JSON_PATH = "trivia_questions.json";
static {
questions.add(new ArrayList<>());
questions.add(new ArrayList<>());
@ -22,28 +22,34 @@ public class TriviaQuestionData {
questions.add(new ArrayList<>());
questions.add(new ArrayList<>());
questions.add(new ArrayList<>());
System.out.println(ConsoleColors.BLUE + "[TriviaQuestionData 25] JSON File Path: " + new File(JSON_PATH + "hallo").getAbsolutePath() + ConsoleColors.RESET);
loadJSON();
}
private static void loadJSON() {
System.out.println();
StringBuilder json = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(
new FileReader("trivia_questions.json"))) {
new FileReader(JSON_PATH))) {
String line = bufferedReader.readLine();
while (line != null) {
json.append(line);
line = bufferedReader.readLine();
}
Gson gson = new Gson();
TriviaQuestion[] array = gson.fromJson(json.toString(), TriviaQuestion[].class);
for (TriviaQuestion triviaQuestion : array) {
questions.get(triviaQuestion.getArc()).add(triviaQuestion);
}
} catch (IOException e) {
e.printStackTrace();
}
Gson gson = new Gson();
TriviaQuestion[] array = gson.fromJson(json.toString(), TriviaQuestion[].class);
for (TriviaQuestion triviaQuestion : array) {
questions.get(triviaQuestion.getArc()).add(triviaQuestion);
}
}
private static void saveJSON(String path, TriviaQuestion[] array) {
@ -77,7 +83,7 @@ public class TriviaQuestionData {
public static void add(TriviaQuestion triviaQuestion) {
questions.get(triviaQuestion.getArc()).add(triviaQuestion);
saveJSONFromAll("trivia_questions.json");
saveJSONFromAll(JSON_PATH);
}
public static TriviaQuestion getQuestion(int toArc) {

View file

@ -1 +1 @@
[{"question":"What\u0027s the name of Gons aunt?","answers":["Kite","Mito","Ging","Kurapika"],"correctAnswer":1,"arc":0},{"question":"Why does Leorio want money?","answers":["To become a doctor","To send it to e-girls","So that others don\u0027t get it","To buy large quantities of drugs"],"correctAnswer":0,"arc":0},{"question":"What was Gon\u0027s aim after Killua left him alone playing with the Chairman Netero?","answers":["Get the ball","Make Netero use his right hand","Make Netero use his left leg","Let Netero drop the ball"],"correctAnswer":1,"arc":0},{"question":"What did Tonpa mix into the drink?","answers":["Sleeping pills","Headache tabletsschla","Laxative","Rat poison"],"correctAnswer":2,"arc":0},{"question":"How many doors are there at the Testing Gate of the Zoldyck Family?","answers":["7","5","12","8"],"correctAnswer":0,"arc":1},{"question":"How many tons did Killua manage to move when he entered Kukooro Mountain","answers":["14","16","32","64"],"correctAnswer":1,"arc":1},{"question":"What did Kurapika bring to his fight with Uvo?","answers":["Shovel","Bomb","Gon"],"correctAnswer":0,"arc":3},{"question":"What is Bisky\u0027s true form?","answers":["Boy","Big Woman","Little Girl"],"correctAnswer":1,"arc":4},{"question":"How did Gon die on Greed Island?","answers":["He didn\u0027t die on Greed Island","Hisoka killed him with a card to the neck","He lost too muich blood when Genthru blew his arm of","He killed himself after Killuas death"],"correctAnswer":0,"arc":4},{"question":"What is Genthrus ability called?","answers":["Nuke","Massive Explosion","Little Flower"],"correctAnswer":2,"arc":4},{"question":"Where did Meruem die?","answers":["Volcano","In the desert with Netero","In the basement of the palace","In the womb of the queen"],"correctAnswer":2,"arc":5},{"question":"What is Pitou\u0027s full name?","answers":["Pitoue","Youpitou","Neferpitou","Pitorius"],"correctAnswer":2,"arc":5},{"question":"Who is Alluka?","answers":["Gon\u0027s sister","A Zodiac","The \u0027dark\u0027 side of Nanika","Killua\u0027s sister"],"correctAnswer":3,"arc":6},{"question":"Who won the election?","answers":["Gon","Pariston","Morel","Leorio"],"correctAnswer":1,"arc":6},{"question":"haha","answers":["never","immer"],"correctAnswer":1,"arc":6}]
[{"question":"question","answers":["a","b","c","d"],"correctAnswer":0,"arc":0}]