3131import club .devcord .devmarkt .responses .failure .application .AnswerTooShortApplicationErrorData ;
3232import club .devcord .devmarkt .responses .failure .application .ErrorCode ;
3333import club .devcord .devmarkt .responses .failure .application .NumberApplicationErrorData ;
34+ import club .devcord .devmarkt .responses .failure .application .TooLargeErrorData ;
3435import jakarta .inject .Singleton ;
3536import java .util .ArrayList ;
3637import java .util .Collection ;
@@ -110,8 +111,9 @@ public Application createApplication(String templateName, ArrayList<Answer> answ
110111 throw new FailureException (ErrorCode .TEMPLATE_NOT_FOUND );
111112 }
112113
113- var errors = new ArrayList <Error <Application >>();
114114 var template = templateOpt .get ();
115+ var errors = new ArrayList <Error <Application >>();
116+ validateSize (template , answers , errors );
115117 validateAndPrepareAnswers (answers , template , answer -> null , null , errors , true );
116118
117119 if (!errors .isEmpty ()) {
@@ -125,6 +127,21 @@ public Application createApplication(String templateName, ArrayList<Answer> answ
125127 return saved ;
126128 }
127129
130+ // according to the discord embed limits -> https://discordjs.guide/popular-topics/embeds.html#embed-limits
131+ private void validateSize (Template template , List <Answer > answers , ArrayList <Error <Application >> errors ) {
132+ var size = template .name ().length ();
133+ for (var question : template .questions ()) {
134+ size += question .question ().length ();
135+ }
136+ for (var answer : answers ) {
137+ size += answer .answer ().length ();
138+ }
139+
140+ if (size > 5800 ) { // leave 200 chars for extra text
141+ errors .add (new Error <>(ErrorCode .TOO_LARGE , new TooLargeErrorData (size )));
142+ }
143+ }
144+
128145 private void validateAndPrepareAnswers (ArrayList <Answer > answers ,
129146 Template template , Function <Answer , Integer > numberFunc , Application application ,
130147 Collection <Error <Application >> errors , boolean checkUnansweredQuestions ) {
0 commit comments