|
10 | 10 | import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
11 | 11 | import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
|
12 | 12 | import net.dv8tion.jda.api.interactions.modals.ModalMapping;
|
| 13 | +import org.slf4j.Logger; |
| 14 | +import org.slf4j.LoggerFactory; |
13 | 15 |
|
14 | 16 | import org.togetherjava.tjbot.config.RoleApplicationSystemConfig;
|
15 | 17 |
|
|
29 | 31 | * users to prevent spamming.
|
30 | 32 | */
|
31 | 33 | public class RoleApplicationHandler {
|
32 |
| - private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5; |
| 34 | + private static final Logger logger = LoggerFactory.getLogger(RoleApplicationHandler.class); |
33 | 35 |
|
| 36 | + private static final int APPLICATION_SUBMIT_COOLDOWN_MINUTES = 5; |
34 | 37 | private final Cache<Member, OffsetDateTime> applicationSubmitCooldown;
|
35 | 38 | private final Predicate<String> applicationChannelPattern;
|
36 | 39 | private final RoleApplicationSystemConfig roleApplicationSystemConfig;
|
@@ -65,17 +68,26 @@ public RoleApplicationHandler(RoleApplicationSystemConfig roleApplicationSystemC
|
65 | 68 | * @param answer the answer provided by the applicant to the default question
|
66 | 69 | */
|
67 | 70 | protected void sendApplicationResult(final ModalInteractionEvent event, List<String> args,
|
68 |
| - String answer) { |
| 71 | + String answer) throws IllegalArgumentException { |
69 | 72 | Guild guild = event.getGuild();
|
70 |
| - if (args.size() != 2 || guild == null) { |
71 |
| - return; |
| 73 | + |
| 74 | + if (guild == null) { |
| 75 | + throw new IllegalArgumentException( |
| 76 | + "sendApplicationResult() got fired in a non-guild environment."); |
| 77 | + } |
| 78 | + |
| 79 | + if (args.size() != 2) { |
| 80 | + throw new IllegalArgumentException( |
| 81 | + "Received application result after user submitted one, and did not receive 2 arguments. Args: " |
| 82 | + + args); |
72 | 83 | }
|
73 | 84 |
|
74 | 85 | String roleString = args.get(1);
|
75 | 86 |
|
76 | 87 | Optional<TextChannel> applicationChannel = getApplicationChannel(guild);
|
77 | 88 | if (applicationChannel.isEmpty()) {
|
78 |
| - return; |
| 89 | + throw new IllegalArgumentException("Application channel %s could not be found." |
| 90 | + .formatted(roleApplicationSystemConfig.submissionsChannelPattern())); |
79 | 91 | }
|
80 | 92 |
|
81 | 93 | User applicant = event.getUser();
|
@@ -125,10 +137,17 @@ protected void submitApplicationFromModalInteraction(ModalInteractionEvent event
|
125 | 137 |
|
126 | 138 | ModalMapping modalAnswer = event.getValues().getFirst();
|
127 | 139 |
|
128 |
| - sendApplicationResult(event, args, modalAnswer.getAsString()); |
129 |
| - event.reply("Your application has been submitted. Thank you for applying! 😎") |
130 |
| - .setEphemeral(true) |
131 |
| - .queue(); |
| 140 | + try { |
| 141 | + sendApplicationResult(event, args, modalAnswer.getAsString()); |
| 142 | + event.reply("Your application has been submitted. Thank you for applying! 😎") |
| 143 | + .setEphemeral(true) |
| 144 | + .queue(); |
| 145 | + } catch (IllegalArgumentException e) { |
| 146 | + logger.error("A role application could not be submitted. ", e); |
| 147 | + event.reply("Your application could not be submitted. Please contact the staff team.") |
| 148 | + .setEphemeral(true) |
| 149 | + .queue(); |
| 150 | + } |
132 | 151 |
|
133 | 152 | applicationSubmitCooldown.put(event.getMember(), OffsetDateTime.now());
|
134 | 153 | }
|
|
0 commit comments