Skip to content

Commit a565bc6

Browse files
committed
Merge branch 'prod' of github.com:ModFest/platform into prod
2 parents f361875 + f064167 commit a565bc6

File tree

7 files changed

+67
-73
lines changed

7 files changed

+67
-73
lines changed

botfest/src/main/kotlin/net/modfest/botfest/extensions/SubmissionCommands.kt

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,14 @@ class SubmissionCommands : Extension(), KordExKoinComponent {
271271
modal.source.initialValue = submission.source!!.toKey(Locale.UK)
272272
}
273273

274-
val result = modal.sendAndDeferEphemeral(this)
275-
276-
// Result will be null if the user didn't enter anything
277-
// or if the modal timed out
278-
if (result == null) {
279-
return@action
280-
}
274+
val result = modal.sendAndDeferEphemeral(this) ?: return@action
281275

282276
platform.withAuth(this.user).editSubmissionData(curEvent, subId, SubmissionPatchData(
283277
modal.name.value,
284278
modal.description.value,
285279
modal.source.value,
286-
if (modal is SubmissionEditOtherForm) { modal.homepage.value } else { null }
280+
if (modal is SubmissionEditOtherForm) { modal.homepage.value } else { null },
281+
null
287282
))
288283

289284
result.edit {
@@ -375,28 +370,49 @@ class SubmissionCommands : Extension(), KordExKoinComponent {
375370
return@action
376371
}
377372

378-
if (submission.platform.inner !is Modrinth) {
379-
ackEphemeral {
380-
content = Translations.Commands.Submission.Update.Version.Response.notmodrinth
373+
val subPlatformData = submission.platform.inner
374+
if (subPlatformData is Other) {
375+
val modal = SubmissionUpdateOtherForm()
376+
modal.downloadUrl.initialValue = subPlatformData.downloadUrl!!.toKey(Locale.UK)
377+
378+
val result = modal.sendAndDeferEphemeral(this) ?: return@action
379+
380+
platform.withAuth(this.user).editSubmissionData(curEvent, subId, SubmissionPatchData(
381+
null,
382+
null,
383+
null,
384+
null,
385+
modal.downloadUrl.value
386+
))
387+
388+
result.edit {
389+
content = Translations.Commands.Submission.Edit.Response.success
381390
.withContext(this@action)
382391
.translateNamed(
383392
"subId" to subId
384393
)
385394
}
386-
return@action
387-
}
388-
389-
platform.withAuth(this.user).updateSubmissionVersion(curEvent, subId)
395+
} else if (submission.platform.inner !is Modrinth) {
396+
ackEphemeral {
397+
content = Translations.Commands.Submission.Update.Version.Response.notmodrinth
398+
.withContext(this@action)
399+
.translateNamed(
400+
"subId" to subId
401+
)
402+
}
403+
} else {
404+
platform.withAuth(this.user).updateSubmissionVersion(curEvent, subId)
390405

391-
val updatedSubmission = platform.getUserSubmissions(this.user.id).find { it.id == subId }
406+
val updatedSubmission = platform.getUserSubmissions(this.user.id).find { it.id == subId }
392407

393-
ackEphemeral {
394-
content = Translations.Commands.Submission.Update.Version.Response.success
395-
.withContext(this@action)
396-
.translateNamed(
397-
"subId" to subId,
398-
"versionId" to (updatedSubmission?.platform?.inner as Modrinth).versionId
399-
)
408+
ackEphemeral {
409+
content = Translations.Commands.Submission.Update.Version.Response.success
410+
.withContext(this@action)
411+
.translateNamed(
412+
"subId" to subId,
413+
"versionId" to (updatedSubmission?.platform?.inner as Modrinth).versionId
414+
)
415+
}
400416
}
401417
}
402418
}
@@ -746,6 +762,17 @@ class SubmissionCommands : Extension(), KordExKoinComponent {
746762
}
747763
}
748764

765+
class SubmissionUpdateOtherForm : ModalForm() {
766+
override var title: Key = Translations.Modal.Update.title
767+
768+
val downloadUrl = lineText {
769+
label = Translations.Modal.Submission.Downloadurl.label
770+
placeholder = Translations.Modal.Submission.Downloadurl.placeholder
771+
maxLength = 128
772+
required = false
773+
}
774+
}
775+
749776
class SubmitModalModrinth : ModalForm() {
750777
override var title: Key = Translations.Modal.Submit.title
751778

botfest/src/main/resources/translations/botfest/strings.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ commands.submission.edit.description=Edit your submission's data
8888
commands.submission.edit.response.notfound=Unknown submission {subId}
8989
commands.submission.edit.response.success=Successfully edited the data for {subId}
9090
commands.submission.update.version.name=version
91-
commands.submission.update.version.description=Update modrinth submission to the latest compatible version
91+
commands.submission.update.version.description=Update the in-pack version of a submission
9292
commands.submission.update.version.response.notfound=Unknown submission {subId}
9393
commands.submission.update.version.response.notmodrinth=Can't update a non-modrinth submission!
9494
commands.submission.update.version.response.success=Successfully updated {subId} to version `{versionId}`
@@ -158,6 +158,7 @@ modal.register.pronouns.placeholder=they/them
158158
modal.submit.title=Submit a mod
159159
modal.submit.url.label=Enter your project's Modrinth URL
160160
modal.submit.url.placeholder=https://modrinth.com/project/slug
161+
modal.update.title=Update a non-Modrinth mod
161162
modal.submission.edit.title=Edit your mod's data
162163
modal.submission.name.label=Name
163164
modal.submission.name.placeholder=My mod

common/src/main/java/net/modfest/platform/gson/GsonCommon.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.google.gson.FieldNamingPolicy;
44
import com.google.gson.GsonBuilder;
5-
import net.modfest.platform.pojo.EventData;
65
import net.modfest.platform.pojo.SubmissionData;
76

87
import java.time.Instant;
@@ -16,7 +15,6 @@ public static void configureGson(GsonBuilder builder) {
1615
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
1716
.registerTypeHierarchyAdapter(Enum.class, new EnumToLowerCaseJsonConverter())
1817
.registerTypeAdapter(Instant.class, new InstantSerializer())
19-
.registerTypeAdapter(EventData.DescriptionItem.class, new EventData.DescriptionItem.TypeAdapter())
2018
.registerTypeAdapter(SubmissionData.AssociatedData.class, new SubmissionData.AssociatedData.TypeAdapter())
2119
.setPrettyPrinting()
2220
.serializeNulls()

common/src/main/java/net/modfest/platform/pojo/EventData.java

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package net.modfest.platform.pojo;
22

3-
import com.google.gson.*;
43
import lombok.With;
54
import org.jspecify.annotations.NonNull;
65

@@ -18,8 +17,7 @@ public record EventData(@NonNull String id,
1817
@NonNull DiscordRoles discordRoles,
1918
@NonNull String mod_loader,
2019
@NonNull String minecraft_version,
21-
@NonNull String modpack,
22-
@NonNull List<DescriptionItem<?>> description) implements Data {
20+
@NonNull String modpack) implements Data {
2321
public enum Type {
2422
MODFEST,
2523
BLANKETCON
@@ -64,45 +62,6 @@ public record Colors(String primary, String secondary) {
6462
public record DiscordRoles(String participant, String award) {
6563
}
6664

67-
public record DescriptionItem<T>(T content) {
68-
public static final String CONTENT_KEY = "content";
69-
70-
public record Markdown(String markdown) {
71-
public static final String KEY = "markdown";
72-
}
73-
74-
public static class TypeAdapter implements JsonSerializer<DescriptionItem<?>>, JsonDeserializer<DescriptionItem<?>> {
75-
public static final String TYPE_KEY = "type";
76-
77-
@Override
78-
public DescriptionItem<?> deserialize(JsonElement json,
79-
java.lang.reflect.Type typeOfT,
80-
JsonDeserializationContext context) throws JsonParseException {
81-
JsonObject jsonObject = json.getAsJsonObject();
82-
String type = jsonObject.get(TYPE_KEY).getAsString();
83-
JsonElement content = jsonObject.get(CONTENT_KEY);
84-
85-
return switch (type) {
86-
case Markdown.KEY -> new DescriptionItem<Markdown>(context.deserialize(content, Markdown.class));
87-
default -> throw new JsonParseException("Invalid DescriptionItem type: " + type);
88-
};
89-
}
90-
91-
@Override
92-
public JsonElement serialize(DescriptionItem<?> src,
93-
java.lang.reflect.Type typeOfSrc,
94-
JsonSerializationContext context) {
95-
var json = new JsonObject();
96-
json.add(TYPE_KEY, new JsonPrimitive(switch (src.content) {
97-
case Markdown ignored -> Markdown.KEY;
98-
default -> throw new IllegalStateException("Unexpected value: " + src);
99-
}));
100-
json.add(CONTENT_KEY, context.serialize(src.content));
101-
return json;
102-
}
103-
}
104-
}
105-
10665
public record DateRange(String name, String description, Phase phase, Instant start, Instant end) {
10766
}
10867
}

common/src/main/java/net/modfest/platform/pojo/SubmissionPatchData.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public record SubmissionPatchData(
99
/**
1010
* Should not be included if the submission isn't of type "other"
1111
*/
12-
@Nullable String homepage
12+
@Nullable String homepage,
13+
/**
14+
* Should not be included if the submission isn't of type "other"
15+
*/
16+
@Nullable String downloadUrl
1317
) {
1418
}

platform_api/src/main/java/net/modfest/platform/service/SubmissionService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ public void editSubmission(SubmissionData data, SubmissionPatchData edit) {
5353
throw new IllegalStateException();
5454
}
5555
}
56+
if (edit.downloadUrl() != null) {
57+
if (data.platform().inner() instanceof SubmissionData.AssociatedData.Other o) {
58+
var newInner = o.withDownloadUrl(edit.downloadUrl().isBlank() ? null : edit.downloadUrl());
59+
data = data.withPlatform(new SubmissionData.AssociatedData(newInner));
60+
} else {
61+
throw new IllegalStateException();
62+
}
63+
}
5664
submissionRepository.save(data);
5765
}
5866

platform_api/src/test/java/net/modfest/platform/JsonTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ public static List<Object> testObjects() {
6363
),
6464
"optifine",
6565
"1.34",
66-
"boop",
67-
List.of(
68-
new EventData.DescriptionItem<>(new EventData.DescriptionItem.Markdown("# HELLO"))
69-
)
66+
"boop"
7067
),
7168
new SubmissionData(
7269
"a",

0 commit comments

Comments
 (0)