2020
2121import io .codemc .api .jenkins .JenkinsAPI ;
2222import io .codemc .bot .CodeMCBot ;
23+ import io .codemc .bot .commands .CmdApplication ;
2324import io .codemc .bot .utils .CommandUtil ;
2425import net .dv8tion .jda .api .entities .Guild ;
2526import net .dv8tion .jda .api .entities .Message ;
2627import net .dv8tion .jda .api .entities .MessageEmbed ;
2728import net .dv8tion .jda .api .entities .channel .concrete .TextChannel ;
2829import net .dv8tion .jda .api .entities .emoji .Emoji ;
2930import net .dv8tion .jda .api .events .interaction .ModalInteractionEvent ;
30- import net .dv8tion .jda .api .exceptions .ContextException ;
3131import net .dv8tion .jda .api .hooks .ListenerAdapter ;
3232import net .dv8tion .jda .api .interactions .InteractionHook ;
3333import net .dv8tion .jda .api .interactions .components .buttons .Button ;
@@ -67,6 +67,11 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event){
6767 case "submit" -> event .deferReply (true ).queue (hook -> {
6868 String user = value (event , "user" );
6969
70+ if (user == null || user .isEmpty ()){
71+ CommandUtil .EmbedReply .from (hook ).error ("The provided user was invalid." ).send ();
72+ return ;
73+ }
74+
7075 if (!JenkinsAPI .getJenkinsUser (user ).isEmpty ()) {
7176 CommandUtil .EmbedReply .from (hook )
7277 .error ("A Jenkins User named '" + user + "' already exists!" )
@@ -77,7 +82,7 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event){
7782 String repo = value (event , "repo" );
7883 String description = value (event , "description" );
7984
80- if (user == null || user . isEmpty () || repo == null || repo .isEmpty () || description == null || description .isEmpty ()){
85+ if (repo == null || repo .isEmpty () || description == null || description .isEmpty ()){
8186 CommandUtil .EmbedReply .from (hook ).error (
8287 "The option User, Repo and/or Description was not set properly!" )
8388 .send ();
@@ -225,6 +230,32 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event){
225230 }
226231 });
227232
233+ case "deny_application" -> event .deferReply (true ).queue (hook -> {
234+ if (args .length == 1 ){
235+ CommandUtil .EmbedReply .from (hook ).error ("Received invalid Deny Application modal!" ).send ();
236+ return ;
237+ }
238+
239+ long messageId ;
240+ try {
241+ messageId = Long .parseLong (args [1 ]);
242+ }catch (NumberFormatException ex ){
243+ messageId = -1L ;
244+ }
245+
246+ if (messageId == -1L ){
247+ CommandUtil .EmbedReply .from (hook ).error ("Received invalid message ID: " + args [1 ]).send ();
248+ return ;
249+ }
250+
251+ String reason = value (event , "reason" );
252+
253+ if (reason == null || reason .isEmpty ())
254+ reason = "*No reason provided*" ;
255+
256+ CmdApplication .handle (this .bot , hook , guild , messageId , reason , false );
257+ });
258+
228259 default -> CommandUtil .EmbedReply .from (event )
229260 .error ("Received Modal with unknown ID `" + event .getModalId () + "`." )
230261 .send ();
0 commit comments