Compare commits

...

8 Commits

Author SHA1 Message Date
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
2 changed files with 57 additions and 3 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,13 +2,20 @@ 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 class Main{
public static void main(String[] args) {
// Insert your bot's token here
String token = args[0];
CheckDeploy check = new CheckDeploy(3000, "/var/www/deployment/Hacky-Quizbot/id.txt");
check.start();
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
// Add a listener which answers with "Pong!" if someone writes "!ping"
@ -20,6 +27,52 @@ public class Main {
// 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() {
File file = new File(this.filename);
Scanner reader;
String id = new String();
try {
reader = new Scanner(file);
while(reader.hasNextLine()) {
id = reader.nextLine();
}
reader.close();
}catch (FileNotFoundException e) {
System.err.println("File not found");
}
return id;
}
public void run() {
this.id = this.grabId(); //replace with correct filename
while(true) {
String new_id = this.grabId();
if(!new_id.equals(this.id)) {
System.exit(0);
}
try {
sleep(this.interval);
}catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
}
}