Skip to content

Commit 9b44875

Browse files
added 🗑️ Delete Button to Submission Messages, added Error handling in Config.java & WelcomeSystem.java
1 parent be6aab0 commit 9b44875

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

‎src/main/java/com/javadiscord/javabot/commands/configuation/config/Config.java‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.javadiscord.javabot.commands.configuation.config;
22

33
import com.javadiscord.javabot.commands.DelegatingCommandHandler;
4+
import com.javadiscord.javabot.commands.Responses;
45
import com.javadiscord.javabot.commands.configuation.config.subcommands.*;
6+
import com.javadiscord.javabot.commands.moderation.Embed;
57
import com.javadiscord.javabot.other.Constants;
68
import com.javadiscord.javabot.other.Embeds;
9+
import net.dv8tion.jda.api.EmbedBuilder;
710
import net.dv8tion.jda.api.Permission;
811
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
912
import net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction;
1013

14+
import java.util.Date;
15+
1116
// TODO: Replace with file-based config or at least something much less convoluted.
1217
@Deprecated(forRemoval = true)
1318
public class Config extends DelegatingCommandHandler {
@@ -37,7 +42,8 @@ public ReplyAction handle(SlashCommandEvent event) {
3742
return event.replyEmbeds(Embeds.permissionError("ADMINISTRATOR", event)).setEphemeral(Constants.ERR_EPHEMERAL);
3843
}
3944

40-
return super.handle(event);
45+
try { return super.handle(event);
46+
} catch (Exception e) { return Responses.error(event, "```" + e.getMessage() + "```"); }
4147
}
4248
}
4349

‎src/main/java/com/javadiscord/javabot/commands/configuation/welcome_system/WelcomeSystem.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.javadiscord.javabot.commands.configuation.welcome_system;
22

33
import com.javadiscord.javabot.commands.DelegatingCommandHandler;
4+
import com.javadiscord.javabot.commands.Responses;
45
import com.javadiscord.javabot.commands.configuation.welcome_system.subcommands.*;
56
import com.javadiscord.javabot.other.Constants;
67
import com.javadiscord.javabot.other.Embeds;
@@ -33,7 +34,8 @@ public ReplyAction handle(SlashCommandEvent event) {
3334
if (!event.getMember().hasPermission(Permission.ADMINISTRATOR)) {
3435
return event.replyEmbeds(Embeds.permissionError("ADMINISTRATOR", event)).setEphemeral(Constants.ERR_EPHEMERAL);
3536
}
36-
return super.handle(event);
37+
try { return super.handle(event);
38+
} catch (Exception e) { return Responses.error(event, "```" + e.getMessage() + "```"); }
3739
}
3840
}
3941

‎src/main/java/com/javadiscord/javabot/events/ButtonClickListener.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private void handleSubmission(MongoDatabase database, Guild guild, ButtonClickEv
5555
switch (id[1]) {
5656
case "approve" -> new SubmissionListener().submissionApprove(event, userID);
5757
case "decline" -> new SubmissionListener().submissionDecline(event);
58+
case "delete" -> new SubmissionListener().submissionDelete(event);
5859
}
5960
submissionMessages.deleteOne(document);
6061
}

‎src/main/java/com/javadiscord/javabot/events/SubmissionListener.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.mongodb.client.MongoCollection;
99
import com.mongodb.client.MongoDatabase;
1010
import net.dv8tion.jda.api.EmbedBuilder;
11+
import net.dv8tion.jda.api.entities.Emoji;
1112
import net.dv8tion.jda.api.entities.Guild;
1213
import net.dv8tion.jda.api.entities.Message;
1314
import net.dv8tion.jda.api.events.interaction.ButtonClickEvent;
@@ -41,7 +42,8 @@ public void dmSubmissionSend (ButtonClickEvent event, String text) {
4142

4243
Bot.config.get(guild).getQotw().getSubmissionChannel().sendMessageEmbeds(eb).setActionRows(ActionRow.of(
4344
Button.success("submission:approve:" + event.getUser().getId(), "Approve"),
44-
Button.danger("submission:decline:" + event.getUser().getId(), "Decline")))
45+
Button.danger("submission:decline:" + event.getUser().getId(), "Decline"),
46+
Button.secondary("submission:delete:" + event.getUser().getId(), "🗑️")))
4547
.queue(m -> {
4648

4749
MongoCollection<Document> submission_messages = database.getCollection("submission_messages");
@@ -88,6 +90,11 @@ public void submissionDecline (ButtonClickEvent event) {
8890
.queue();
8991
}
9092

93+
public void submissionDelete (ButtonClickEvent event) {
94+
95+
event.getHook().deleteOriginal().queue();
96+
}
97+
9198
@Override
9299
public void onPrivateMessageReceived(PrivateMessageReceivedEvent event) {
93100
if (event.getAuthor().isBot()) return;

0 commit comments

Comments
 (0)