mirror of
https://github.com/Noratrieb/killua-bot.git
synced 2026-01-15 23:55:02 +01:00
trivia things
This commit is contained in:
parent
7ffb771946
commit
a30e1653ca
7 changed files with 80 additions and 14 deletions
|
|
@ -23,7 +23,7 @@ public class TriviaCommand extends Command {
|
|||
4 Greed Island arc
|
||||
5 Chimera Ant arc
|
||||
6 Election arc
|
||||
|
||||
|
||||
Add questions using `""" + Config.PREFIX + "trivia add`");
|
||||
}
|
||||
|
||||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue