reworked how users are handled

master
BodgeMaster 2022-02-22 18:09:37 +01:00
parent d5201044ec
commit 113323da00
2 changed files with 12 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
@ -25,14 +26,17 @@ public class Main {
DiscordApi api = new DiscordApiBuilder().setToken(commandLineArguments[0]).login().join();
//Trivia management
Member member = new Member(api);
//user management
ArrayList<QuizHandler> QuizHandlers = new ArrayList<QuizHandler>();
// small status command
// commands
api.addMessageCreateListener(event -> {
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
event.getChannel().sendMessage("Pong!\nHacky the quiz bot has been running since "+startupTime);
}
if (event.getMessageContent().equalsIgnoreCase("!trivia")) {
QuizHandlers.add(new QuizHandler(api, event.getMessageAuthor().asUser().get()));
}
});
}

View File

@ -5,21 +5,14 @@ import org.javacord.api.entity.user.User;
import org.javacord.api.entity.message.embed.EmbedBuilder;
//TODO: find a better name for this class
public class Member {
public class QuizHandler {
private DiscordApi api;
private User user;
public Member(DiscordApi api) {
public QuizHandler(DiscordApi api, User user) {
this.api = api;
this.api.addMessageCreateListener(event ->{
if(event.getMessageContent().equalsIgnoreCase("!trivia")) {
if(event.getMessageAuthor().asUser().isPresent()) {
this.user = event.getMessageAuthor().asUser().get();
this.user.sendMessage("Hi! I'm Hacky! **Fuck you**! :D");
}
}
});
this.user = user;
user.sendMessage("Hi! Im Hacky.\nThis is a test.");
}
public void sendMessage(String question, String[] options) {