Search in sources :

Example 1 with ScSubmission

use of com.faendir.zachtronics.bot.sc.model.ScSubmission in project zachtronics-leaderboard-bot by F43nd1r.

the class ScSubmitCommand method parseSubmissions.

@NotNull
@Override
public Collection<ValidationResult<ScSubmission>> parseSubmissions(@NotNull ScSubmitCommand.SubmitData parameters) {
    if (parameters.getExport().equals(parameters.video))
        throw new IllegalArgumentException("Export link and video link cannot be the same link");
    boolean bypassValidation = parameters.bypassValidation != null && parameters.bypassValidation;
    Collection<ValidationResult<ScSubmission>> results = ScSubmission.fromExportLink(parameters.export, bypassValidation, parameters.author);
    if (parameters.video != null) {
        if (results.size() != 1)
            throw new IllegalArgumentException("Only one solution can be paired with a video");
        ValidationResult<ScSubmission> result = results.iterator().next();
        if (result instanceof ValidationResult.Valid<ScSubmission>) {
            ScSubmission submission = result.getSubmission();
            ScSubmission videoSubmission = submission.withDisplayLink(parameters.video);
            return Collections.singleton(new ValidationResult.Valid<>(videoSubmission));
        } else {
            throw new IllegalArgumentException(result.getMessage());
        }
    } else
        return results;
}
Also used : ValidationResult(com.faendir.zachtronics.bot.validation.ValidationResult) ScSubmission(com.faendir.zachtronics.bot.sc.model.ScSubmission) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ScSubmission (com.faendir.zachtronics.bot.sc.model.ScSubmission)1 ValidationResult (com.faendir.zachtronics.bot.validation.ValidationResult)1 NotNull (org.jetbrains.annotations.NotNull)1