Compare commits
5 Commits
97f8b2bc7a
...
92f66779c1
Author | SHA1 | Date |
---|---|---|
Shwoomple | 92f66779c1 | |
BodgeMaster | 22e0139466 | |
BodgeMaster | 4b075d63ed | |
BodgeMaster | ce026ac1d3 | |
BodgeMaster | 7ed5d26a75 |
|
@ -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
|
||||
mvn clean compile assembly:single
|
||||
cat /dev/urandom | head -c 10 | base64 > id.txt
|
||||
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 "================================================================================
|
||||
|
|
|
@ -6,18 +6,20 @@ 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, "Enter Filename Here");
|
||||
CheckDeploy check = new CheckDeploy(7500, "/var/www/deployment/Hacky-Quizbot/id.txt");
|
||||
check.start();
|
||||
|
||||
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
|
||||
//Trivia management
|
||||
Member member = new Member(api);
|
||||
|
||||
// Add a listener which answers with "Pong!" if someone writes "!ping"
|
||||
api.addMessageCreateListener(event -> {
|
||||
if (event.getMessageContent().equalsIgnoreCase("!ping")) {
|
||||
|
@ -30,7 +32,7 @@ public class Main{
|
|||
|
||||
}
|
||||
|
||||
public static class CheckDeploy extends Thread{
|
||||
public static class CheckDeploy extends Thread {
|
||||
private int interval;
|
||||
private String id;
|
||||
private String filename;
|
||||
|
@ -40,36 +42,40 @@ public class Main{
|
|||
this.filename = filename;
|
||||
}
|
||||
|
||||
public String grabId() {
|
||||
public String grabId() throws FileNotFoundException {
|
||||
File file = new File(this.filename);
|
||||
Scanner reader;
|
||||
String id = new String();
|
||||
|
||||
try {
|
||||
reader = new Scanner(file);
|
||||
while(reader.hasNextLine()) {
|
||||
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)) {
|
||||
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) {
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
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");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue