Compare commits

...
7 Commits
Author SHA1 Message Date
allison 704baa67f5 qol
Build and Deploy Java Project / build-and-deploy (push) Successful in 55s
2026-08-28 16:48:15 -05:00
allison 9e93adde34 qol
Build and Deploy Java Project / build-and-deploy (push) Successful in 51s
2026-08-28 13:33:04 -05:00
allison 5c8b63c7c9 restart service on deploymenet
Build and Deploy Java Project / build-and-deploy (push) Successful in 1m0s
2026-08-28 13:02:15 -05:00
allison ac78a5241b restart service on deploymenet
Build and Deploy Java Project / build-and-deploy (push) Successful in 1m1s
2026-08-28 12:51:23 -05:00
allison bdfb1ae90b restart service on deploymenet
Build and Deploy Java Project / build-and-deploy (push) Failing after 49s
2026-08-28 12:45:09 -05:00
allison bd5409ae5a restart service on deploymenet
Build and Deploy Java Project / build-and-deploy (push) Failing after 57s
2026-08-28 12:42:16 -05:00
allison a48bf9fc8c less loggy 2026-08-28 12:41:05 -05:00
8 changed files with 82 additions and 54 deletions
+9
View File
@@ -38,3 +38,12 @@ jobs:
source: "target/notifier.jar" source: "target/notifier.jar"
target: "/opt/notifier" target: "/opt/notifier"
strip_components: 1 strip_components: 1
- name: Restart Service on Server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USERNAME }}
password: ${{ secrets.SERVER_PASSWORD }}
script: |
sudo systemctl restart notifier
@@ -1,5 +1,8 @@
package tech.allydoes; package tech.allydoes;
import java.util.ArrayList;
import java.util.Arrays;
public class Constants { public class Constants {
public static final boolean PRODUCTION = true; public static final boolean PRODUCTION = true;
public static final String TESTING_GUILD = "926369143186403329"; public static final String TESTING_GUILD = "926369143186403329";
@@ -12,4 +15,5 @@ public class Constants {
public static final String DB_HOST = "localhost"; public static final String DB_HOST = "localhost";
public static final String DB_PORT = "5432"; public static final String DB_PORT = "5432";
public static final ArrayList<String> statusMessages = new ArrayList<>(Arrays.asList("building stuff... ", "robots!", "beep boop", "thinking....", "hiiii!", "*hammer noises*", "*drill noises*", "volunteer at first robotics!", "join robotics!", "join cosplay club!"));
} }
@@ -3,6 +3,7 @@ package tech.allydoes.database;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import tech.allydoes.Constants; import tech.allydoes.Constants;
import tech.allydoes.door.DoorStatus;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
@@ -69,7 +70,6 @@ public class DatabaseManager {
String guildId = resultSet.getString("guild_id"); String guildId = resultSet.getString("guild_id");
String channelId = resultSet.getString("channel_id"); String channelId = resultSet.getString("channel_id");
String messageId = resultSet.getString("message_id"); String messageId = resultSet.getString("message_id");
LOGGER.debug("Notifier for guild {}, channel {}, message {}", guildId, channelId, messageId);
notified.add(new Notified(guildId, channelId, messageId)); notified.add(new Notified(guildId, channelId, messageId));
} }
return notified; return notified;
@@ -91,6 +91,7 @@ public class DatabaseManager {
preparedStatement.setString(3, messageId); preparedStatement.setString(3, messageId);
if (preparedStatement.execute()) { if (preparedStatement.execute()) {
LOGGER.debug("Notifier for guild {}, channel {}, message {} added successfully.", guildId, channelId, messageId); LOGGER.debug("Notifier for guild {}, channel {}, message {} added successfully.", guildId, channelId, messageId);
DoorStatus.setDoorStatus(DoorStatus.getCurrentStatus());
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
@@ -6,7 +6,6 @@ import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
public interface Command { public interface Command {
SlashCommandData getCommandData(); SlashCommandData getCommandData();
boolean isPrivateCommand();
void processSlashCommandInteractionEvent(SlashCommandInteractionEvent event); void processSlashCommandInteractionEvent(SlashCommandInteractionEvent event);
void processButtonInteractionEvent(ButtonInteractionEvent event); void processButtonInteractionEvent(ButtonInteractionEvent event);
} }
@@ -10,13 +10,11 @@ import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import tech.allydoes.Constants; import tech.allydoes.Constants;
import tech.allydoes.Main;
import tech.allydoes.database.DatabaseManager;
import tech.allydoes.discord.commands.SaveChannelCommand; import tech.allydoes.discord.commands.SaveChannelCommand;
import tech.allydoes.discord.listener.SlashCommandInteractionListener; import tech.allydoes.discord.listener.SlashCommandInteractionListener;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Random;
public class DiscordManager { public class DiscordManager {
public final Logger LOGGER; public final Logger LOGGER;
@@ -35,7 +33,8 @@ public class DiscordManager {
.build() .build()
.awaitReady(); .awaitReady();
registerSlashCommands(); registerSlashCommands();
jda.getPresence().setActivity(Activity.competing("in robotics!")); Random random = new Random();
jda.getPresence().setActivity(Activity.customStatus(Constants.statusMessages.get(random.nextInt(Constants.statusMessages.size()))));
LOGGER.info("Logged in as {}", jda.getSelfUser().getName()); LOGGER.info("Logged in as {}", jda.getSelfUser().getName());
} }
@@ -50,7 +49,6 @@ public class DiscordManager {
private void registerSlashCommandsGlobal() { private void registerSlashCommandsGlobal() {
CommandListUpdateAction commandListUpdateAction = jda.updateCommands(); CommandListUpdateAction commandListUpdateAction = jda.updateCommands();
for (Command command : commands.values()) { for (Command command : commands.values()) {
if (command.isPrivateCommand()) continue;
commandListUpdateAction = commandListUpdateAction.addCommands(command.getCommandData()); commandListUpdateAction = commandListUpdateAction.addCommands(command.getCommandData());
LOGGER.debug("Registered global command: {}", command.getCommandData().getName()); LOGGER.debug("Registered global command: {}", command.getCommandData().getName());
} }
@@ -69,31 +67,7 @@ public class DiscordManager {
updateAction.queue(); updateAction.queue();
} }
public void setDoorStatus(Status status) { public Message getMessage(String channelID, String messageID) {
ArrayList<DatabaseManager.Notified> notified = Main.getDatabaseManager().getAllNotifiers();
for (DatabaseManager.Notified notifiedEntry : notified) {
try {
Message message = getMessage(notifiedEntry.channelId(), notifiedEntry.messageId());
switch (status) {
case OPEN:
message.editMessageEmbeds(Embeds.createOpenLabStatus()).queue();
break;
case CLOSED:
message.editMessageEmbeds(Embeds.createClosedLabStatus()).queue();
break;
case UNKNOWN:
message.editMessageEmbeds(Embeds.createUnknownLabStatus()).queue();
break;
}
} catch (Exception e) {
LOGGER.error("setDoorStatus: Failed to edit message: {}", e.getMessage());
Main.getDatabaseManager().deleteNotifier(notifiedEntry.guildId());
}
}
}
private Message getMessage(String channelID, String messageID) {
return jda.getTextChannelById(channelID).retrieveMessageById(messageID).complete(); return jda.getTextChannelById(channelID).retrieveMessageById(messageID).complete();
} }
@@ -104,17 +78,4 @@ public class DiscordManager {
public JDA getJDA() { public JDA getJDA() {
return jda; return jda;
} }
public enum Status {
OPEN(0), CLOSED(1), UNKNOWN(2);
private final int code;
Status(int code) { this.code = code; }
public static Status fromCode(int code) {
for (Status s : Status.values()) {
if (s.code == code) return s;
}
throw new IllegalArgumentException("Invalid code: " + code);
}
}
} }
@@ -9,6 +9,7 @@ import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData;
import tech.allydoes.Main; import tech.allydoes.Main;
import tech.allydoes.discord.Command; import tech.allydoes.discord.Command;
import tech.allydoes.discord.Embeds; import tech.allydoes.discord.Embeds;
import tech.allydoes.door.DoorStatus;
public class SaveChannelCommand implements Command { public class SaveChannelCommand implements Command {
@Override @Override
@@ -17,11 +18,6 @@ public class SaveChannelCommand implements Command {
.setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.BAN_MEMBERS)); .setDefaultPermissions(DefaultMemberPermissions.enabledFor(Permission.BAN_MEMBERS));
} }
@Override
public boolean isPrivateCommand() {
return false;
}
@Override @Override
public void processSlashCommandInteractionEvent(SlashCommandInteractionEvent event) { public void processSlashCommandInteractionEvent(SlashCommandInteractionEvent event) {
event.deferReply(true).queue((interactionHook) -> { event.deferReply(true).queue((interactionHook) -> {
@@ -0,0 +1,57 @@
package tech.allydoes.door;
import net.dv8tion.jda.api.entities.Message;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import tech.allydoes.Main;
import tech.allydoes.database.DatabaseManager;
import tech.allydoes.discord.Embeds;
import java.util.ArrayList;
public class DoorStatus {
public static final Logger LOGGER = LogManager.getLogger(DoorStatus.class);
private static Status currentStatus;
public static void setDoorStatus(DoorStatus.Status status) {
currentStatus = status;
ArrayList<DatabaseManager.Notified> notified = Main.getDatabaseManager().getAllNotifiers();
for (DatabaseManager.Notified notifiedEntry : notified) {
try {
Message message = Main.getDiscordManager().getMessage(notifiedEntry.channelId(), notifiedEntry.messageId());
switch (status) {
case OPEN:
message.editMessageEmbeds(Embeds.createOpenLabStatus()).queue();
break;
case CLOSED:
message.editMessageEmbeds(Embeds.createClosedLabStatus()).queue();
break;
case UNKNOWN:
message.editMessageEmbeds(Embeds.createUnknownLabStatus()).queue();
break;
}
} catch (Exception e) {
LOGGER.error("setDoorStatus: Failed to edit message: {}", e.getMessage());
Main.getDatabaseManager().deleteNotifier(notifiedEntry.guildId());
}
}
}
public static Status getCurrentStatus() {
return currentStatus;
}
public enum Status {
OPEN(0), CLOSED(1), UNKNOWN(2);
private final int code;
Status(int code) { this.code = code; }
public static Status fromCode(int code) {
for (Status s : Status.values()) {
if (s.code == code) return s;
}
throw new IllegalArgumentException("Invalid code: " + code);
}
}
}
@@ -7,20 +7,21 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpResponseStatus;
import tech.allydoes.Main; import tech.allydoes.Main;
import tech.allydoes.discord.DiscordManager; import tech.allydoes.discord.DiscordManager;
import tech.allydoes.door.DoorStatus;
import tech.allydoes.web.RequestHandler; import tech.allydoes.web.RequestHandler;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class PostStatus implements RequestHandler { public class PostStatus implements RequestHandler {
public static String STATUS = "status"; public static final String STATUS = "status";
@Override @Override
public ChannelFuture processRequest(ChannelHandlerContext channelHandlerContext, FullHttpRequest request, Map<String, List<String>> parameters) { public ChannelFuture processRequest(ChannelHandlerContext channelHandlerContext, FullHttpRequest request, Map<String, List<String>> parameters) {
int statusInt = Integer.parseInt(parameters.get(STATUS).getFirst()); int statusInt = Integer.parseInt(parameters.get(STATUS).getFirst());
DiscordManager.Status status = DiscordManager.Status.fromCode(statusInt); DoorStatus.Status status = DoorStatus.Status.fromCode(statusInt);
Main.getDiscordManager().setDoorStatus(status); DoorStatus.setDoorStatus(status);
return channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.OK)); return channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.OK));
} }