Compare commits

...

11 Commits

Author SHA1 Message Date
BodgeMaster 81ffecec6a Added a basic backend with stub functions to work against. 2022-02-20 18:42:25 +01:00
BodgeMaster 22e0139466 fixed a minor bug where the bot would exit immediately when deploying instead of waiting for the build to finish 2022-02-20 08:53:04 +01:00
BodgeMaster 4b075d63ed poll slower 2022-02-20 08:45:55 +01:00
BodgeMaster ce026ac1d3 hard-code file path for deployment check 2022-02-20 08:41:52 +01:00
BodgeMaster 7ed5d26a75 fix a potential hang before it occurs 2022-02-20 08:40:57 +01:00
Shwoomple 97f8b2bc7a added random id generation to deployement-script.sh 2022-02-20 13:06:47 +05:30
Shwoomple 66d7594744 Removed comment block 2022-02-20 12:40:04 +05:30
Shwoomple c9ee99fd8b Deployment checking utlities added 2022-02-20 12:37:55 +05:30
Shwoomple f6778e6ee1 Deployment checking utlities added 2022-02-20 12:37:40 +05:30
Shwoomple e451ea04ff got our saviour bodge's changes 2022-02-20 08:38:02 +05:30
Shwoomple 7c610972fd got our saviour bodge's changes 2022-02-20 08:36:02 +05:30
3 changed files with 128 additions and 13 deletions

View File

@ -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 "================================================================================

View File

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

View File

@ -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 users 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;
}
}
}