Skip to content

Commit

Permalink
Add info about min and max chars to interview message
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlOfDuty committed Jan 20, 2025
1 parent a23ce97 commit 2229996
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Interviews/Interview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public bool TryGetReferencedStep(Dictionary<string, InterviewStep> definitions,
// The entire interview tree is serialized and stored in the database to record responses as they are made.
public class InterviewStep
{
public const int DEFAULT_MAX_FIELD_LENGTH = 1024;
public const int DEFAULT_MIN_FIELD_LENGTH = 0;

// Title of the message embed.
[JsonProperty("heading")]
public string heading;
Expand Down
15 changes: 12 additions & 3 deletions Interviews/Interviewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public static async Task ProcessResponseMessage(DiscordMessage answerMessage)
}

// The length requirement is less than 1024 characters, and must be less than the configurable limit if it is set.
int maxLength = Math.Min(currentStep.maxLength ?? 1024, 1024);
int maxLength = Math.Min(currentStep.maxLength ?? InterviewStep.DEFAULT_MAX_FIELD_LENGTH, InterviewStep.DEFAULT_MAX_FIELD_LENGTH);

if (answerMessage.Content.Length > maxLength)
{
Expand All @@ -303,7 +303,7 @@ public static async Task ProcessResponseMessage(DiscordMessage answerMessage)
return;
}

if (answerMessage.Content.Length < (currentStep.minLength ?? 0))
if (answerMessage.Content.Length < (currentStep.minLength ?? InterviewStep.DEFAULT_MIN_FIELD_LENGTH))
{
DiscordMessage lengthMessage = await answerMessage.RespondAsync(new DiscordEmbedBuilder
{
Expand Down Expand Up @@ -597,7 +597,16 @@ private static async Task SendNextMessage(Interview interview, DiscordChannel ch
string.IsNullOrWhiteSpace(step.selectorPlaceholder) ? "Select a user or role..." : step.selectorPlaceholder));
break;
case StepType.TEXT_INPUT:
embed.WithFooter("Reply to this message with your answer. You cannot include images or files.");
string lengthInfo;
if (step.minLength != null)
{
lengthInfo = " (" + step.minLength + "-" + (step.maxLength ?? InterviewStep.DEFAULT_MAX_FIELD_LENGTH) + " characters)";
}
else
{
lengthInfo = " (Maximum " + (step?.maxLength ?? InterviewStep.DEFAULT_MAX_FIELD_LENGTH) + " characters)";
}
embed.WithFooter("Reply to this message with your answer" + lengthInfo + ". You cannot include images or files.");
break;
case StepType.INTERVIEW_END:
case StepType.ERROR:
Expand Down

0 comments on commit 2229996

Please sign in to comment.