Compare commits
11 Commits
0d9de0c289
...
81ffecec6a
Author | SHA1 | Date |
---|---|---|
![]() |
81ffecec6a | |
![]() |
22e0139466 | |
![]() |
4b075d63ed | |
![]() |
ce026ac1d3 | |
![]() |
7ed5d26a75 | |
![]() |
97f8b2bc7a | |
![]() |
66d7594744 | |
![]() |
c9ee99fd8b | |
![]() |
f6778e6ee1 | |
![]() |
e451ea04ff | |
![]() |
7c610972fd |
|
@ -6,6 +6,7 @@ $(date "+%Y-%m-%d %I:%M:%S%p UTC%:z")
|
|||
|
||||
# build the thing into a big jar with all the dependencies
|
||||
mvn clean compile assembly:single
|
||||
dd if=/dev/urandom bs=1 count=20 | base64 > id.txt
|
||||
# TODO: Somehow tell a service that manages the bot to shut it down and replace it with the updated version?
|
||||
|
||||
echo "================================================================================
|
||||
|
|
|
@ -2,24 +2,80 @@ package linux.general.hackyquizbot;
|
|||
|
||||
import org.javacord.api.DiscordApi;
|
||||
import org.javacord.api.DiscordApiBuilder;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Insert your bot's token here
|
||||
String token = args[0];
|
||||
public static void main(String[] args) {
|
||||
// Insert your bot's token here
|
||||
String token = args[0];
|
||||
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
CheckDeploy check = new CheckDeploy(7500, "/var/www/deployment/Hacky-Quizbot/id.txt");
|
||||
check.start();
|
||||
|
||||
// Add a listener which answers with "Pong!" if someone writes "!ping"
|
||||
api.addMessageCreateListener(event -> {
|
||||
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
|
||||
event.getChannel().sendMessage("Pong!");
|
||||
}
|
||||
});
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
|
||||
// Print the invite url of your bot
|
||||
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
|
||||
}
|
||||
// Add a listener which answers with "Pong!" if someone writes "!ping"
|
||||
api.addMessageCreateListener(event -> {
|
||||
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
|
||||
event.getChannel().sendMessage("Pong!");
|
||||
}
|
||||
});
|
||||
|
||||
// Print the invite url of your bot
|
||||
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
|
||||
|
||||
}
|
||||
|
||||
public static class CheckDeploy extends Thread {
|
||||
private int interval;
|
||||
private String id;
|
||||
private String filename;
|
||||
|
||||
public CheckDeploy(int interval, String filename) {
|
||||
this.interval = interval;
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String grabId() throws FileNotFoundException {
|
||||
File file = new File(this.filename);
|
||||
Scanner reader;
|
||||
String id = new String();
|
||||
|
||||
reader = new Scanner(file);
|
||||
while (reader.hasNextLine()) {
|
||||
id = reader.nextLine();
|
||||
}
|
||||
reader.close();
|
||||
return id;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
this.id = this.grabId();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Failed to grab ID on startup.");
|
||||
System.exit(1);
|
||||
}
|
||||
while (true) {
|
||||
String new_id = this.id;
|
||||
try {
|
||||
new_id = this.grabId();
|
||||
} catch (FileNotFoundException e) {
|
||||
System.err.println("Failed to check ID.");
|
||||
}
|
||||
if (!new_id.equals(this.id)) {
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
try {
|
||||
sleep(this.interval);
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package linux.general.hackyquizbot;
|
||||
|
||||
public class QuizBackend {
|
||||
|
||||
public static String[] getCategories() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Question getRandomQuestionForCategory(String category) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getScoreForUser(String discordUserID) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static class Question {
|
||||
public Question(String question, String[] answers) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the full question text including multiple choice options
|
||||
*/
|
||||
public String getQuestionTextWithOptions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a character array containing all the valid answers
|
||||
*/
|
||||
public char[] getValidResponses() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is used to send the user’s reply back to the backend. Can be called
|
||||
* multiple times to add answers for questions with multiple possible answers.
|
||||
*
|
||||
* @param discordUserID
|
||||
* @param answer
|
||||
*/
|
||||
public void addAnswer(String discordUserID, char answer) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to balance easy and difficult questions. Difficult questions will have a
|
||||
* higher value so if someone gets a bunch of them they will get less questions
|
||||
* overall.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int getQuestionScoreValue() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue