fixed a minor bug where the bot would exit immediately when deploying instead of waiting for the build to finish
parent
4b075d63ed
commit
22e0139466
|
@ -6,73 +6,76 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main{
|
public class Main {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Insert your bot's token here
|
// Insert your bot's token here
|
||||||
String token = args[0];
|
String token = args[0];
|
||||||
|
|
||||||
CheckDeploy check = new CheckDeploy(7500, "/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"
|
CheckDeploy check = new CheckDeploy(7500, "/var/www/deployment/Hacky-Quizbot/id.txt");
|
||||||
api.addMessageCreateListener(event -> {
|
check.start();
|
||||||
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
|
|
||||||
event.getChannel().sendMessage("Pong!");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Print the invite url of your bot
|
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||||
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")) {
|
||||||
public static class CheckDeploy extends Thread{
|
event.getChannel().sendMessage("Pong!");
|
||||||
private int interval;
|
}
|
||||||
private String id;
|
});
|
||||||
private String filename;
|
|
||||||
|
// Print the invite url of your bot
|
||||||
public CheckDeploy(int interval, String filename) {
|
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());
|
||||||
this.interval = interval;
|
|
||||||
this.filename = filename;
|
}
|
||||||
}
|
|
||||||
|
public static class CheckDeploy extends Thread {
|
||||||
public String grabId() {
|
private int interval;
|
||||||
File file = new File(this.filename);
|
private String id;
|
||||||
Scanner reader;
|
private String filename;
|
||||||
String id = new String();
|
|
||||||
|
public CheckDeploy(int interval, String filename) {
|
||||||
try {
|
this.interval = interval;
|
||||||
reader = new Scanner(file);
|
this.filename = filename;
|
||||||
while(reader.hasNextLine()) {
|
}
|
||||||
id = reader.nextLine();
|
|
||||||
}
|
public String grabId() throws FileNotFoundException {
|
||||||
reader.close();
|
File file = new File(this.filename);
|
||||||
}catch (FileNotFoundException e) {
|
Scanner reader;
|
||||||
System.err.println("File not found");
|
String id = new String();
|
||||||
}
|
|
||||||
|
reader = new Scanner(file);
|
||||||
return id;
|
while (reader.hasNextLine()) {
|
||||||
}
|
id = reader.nextLine();
|
||||||
|
}
|
||||||
public void run() {
|
reader.close();
|
||||||
this.id = this.grabId(); //replace with correct filename
|
return id;
|
||||||
while(true) {
|
}
|
||||||
String new_id = this.grabId();
|
|
||||||
|
public void run() {
|
||||||
if(!new_id.equals(this.id)) {
|
try {
|
||||||
System.exit(0);
|
this.id = this.grabId();
|
||||||
}
|
} catch (FileNotFoundException e) {
|
||||||
|
System.err.println("Failed to grab ID on startup.");
|
||||||
try {
|
System.exit(1);
|
||||||
sleep(this.interval);
|
}
|
||||||
}catch (Exception e) {
|
while (true) {
|
||||||
System.err.println(e.getMessage());
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue