From f6778e6ee1bb766b815c7eaab6725abf1eab8f80 Mon Sep 17 00:00:00 2001 From: Shwoomple Date: Sun, 20 Feb 2022 12:37:40 +0530 Subject: [PATCH] Deployment checking utlities added --- .idea/.gitignore | 3 + .idea/compiler.xml | 13 ++++ .idea/gradle.xml | 18 +++++ .idea/jarRepositories.xml | 20 ++++++ .idea/misc.xml | 12 ++++ .idea/vcs.xml | 6 ++ .../java/linux/general/hackyquizbot/Main.java | 65 +++++++++++++++++-- 7 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..db12a45 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..32703c5 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d31b37a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/linux/general/hackyquizbot/Main.java b/src/main/java/linux/general/hackyquizbot/Main.java index 0b2eeab..3579aad 100644 --- a/src/main/java/linux/general/hackyquizbot/Main.java +++ b/src/main/java/linux/general/hackyquizbot/Main.java @@ -2,13 +2,24 @@ 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]; - + //String token = args[0]; + + CheckDeploy check = new CheckDeploy(3000, "/home/milan/test.txt"); + check.start(); + + while(true) { + System.out.println("Woo!"); + } + + /* DiscordApi api = new DiscordApiBuilder().setToken(token).login().join(); // Add a listener which answers with "Pong!" if someone writes "!ping" @@ -20,6 +31,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()); + } + } + } } - }