Compare commits

..

No commits in common. "92f66779c1ea7789b7c7f8ec9a10a49ee975a971" and "97f8b2bc7aa13b2b0f283beb8b50f4f198c02326" have entirely different histories.

3 changed files with 67 additions and 96 deletions

View File

@ -6,7 +6,7 @@ $(date "+%Y-%m-%d %I:%M:%S%p UTC%:z")
# build the thing into a big jar with all the dependencies # build the thing into a big jar with all the dependencies
mvn clean compile assembly:single mvn clean compile assembly:single
dd if=/dev/urandom bs=1 count=20 | base64 > id.txt cat /dev/urandom | head -c 10 | base64 > id.txt
# TODO: Somehow tell a service that manages the bot to shut it down and replace it with the updated version? # TODO: Somehow tell a service that manages the bot to shut it down and replace it with the updated version?
echo "================================================================================ echo "================================================================================

View File

@ -6,79 +6,73 @@ 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(3000, "Enter Filename Here");
check.start();
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
CheckDeploy check = new CheckDeploy(7500, "/var/www/deployment/Hacky-Quizbot/id.txt"); // Add a listener which answers with "Pong!" if someone writes "!ping"
check.start(); 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());
//Trivia management
Member member = new Member(api); }
// Add a listener which answers with "Pong!" if someone writes "!ping" public static class CheckDeploy extends Thread{
api.addMessageCreateListener(event -> { private int interval;
if (event.getMessageContent().equalsIgnoreCase("!ping")) { private String id;
event.getChannel().sendMessage("Pong!"); private String filename;
}
}); public CheckDeploy(int interval, String filename) {
this.interval = interval;
// Print the invite url of your bot this.filename = filename;
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite()); }
} public String grabId() {
File file = new File(this.filename);
public static class CheckDeploy extends Thread { Scanner reader;
private int interval; String id = new String();
private String id;
private String filename; try {
reader = new Scanner(file);
public CheckDeploy(int interval, String filename) { while(reader.hasNextLine()) {
this.interval = interval; id = reader.nextLine();
this.filename = filename; }
} reader.close();
}catch (FileNotFoundException e) {
public String grabId() throws FileNotFoundException { System.err.println("File not found");
File file = new File(this.filename); }
Scanner reader;
String id = new String(); return id;
}
reader = new Scanner(file);
while (reader.hasNextLine()) { public void run() {
id = reader.nextLine(); this.id = this.grabId(); //replace with correct filename
} while(true) {
reader.close(); String new_id = this.grabId();
return id;
} if(!new_id.equals(this.id)) {
System.exit(0);
public void run() { }
try {
this.id = this.grabId(); try {
} catch (FileNotFoundException e) { sleep(this.interval);
System.err.println("Failed to grab ID on startup."); }catch (Exception e) {
System.exit(1); System.err.println(e.getMessage());
} }
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

@ -1,23 +0,0 @@
package linux.general.hackyquizbot;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.user.User;
public class Member {
private DiscordApi api;
private User user;
public Member(DiscordApi api) {
this.api = api;
this.api.addMessageCreateListener(event ->{
if(event.getMessageContent().equalsIgnoreCase("!trivia")) {
if(event.getMessageAuthor().asUser().isPresent()) {
this.user = event.getMessageAuthor().asUser().get();
this.user.sendMessage("Welcome to hell");
}
}
});
}
}