Skip to content

Commit 47ac1c4

Browse files
committed
Merge branch 'dev' into prod
2 parents 86e7120 + 106ffff commit 47ac1c4

File tree

18 files changed

+602
-80
lines changed

18 files changed

+602
-80
lines changed

botfest/src/main/kotlin/net/modfest/botfest/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ suspend fun main() {
5151
add(::UserCommands)
5252
add(::EventCommands)
5353
add(::RoleManager)
54+
add(::SubmissionCommands)
5455
}
5556

5657
errorResponse { message, type ->

botfest/src/main/kotlin/net/modfest/botfest/Platform.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import io.ktor.client.request.*
1212
import io.ktor.client.statement.*
1313
import io.ktor.http.*
1414
import io.ktor.serialization.gson.*
15-
import io.ktor.util.logging.*
1615
import net.modfest.platform.gson.GsonCommon
1716
import net.modfest.platform.pojo.CurrentEventData
1817
import net.modfest.platform.pojo.EventData
1918
import net.modfest.platform.pojo.HealthData
2019
import net.modfest.platform.pojo.PlatformErrorResponse
2120
import net.modfest.platform.pojo.SubmissionData
22-
import net.modfest.platform.pojo.SubmitRequest
21+
import net.modfest.platform.pojo.SubmissionPatchData
22+
import net.modfest.platform.pojo.SubmitRequestModrinth
23+
import net.modfest.platform.pojo.SubmitRequestOther
2324
import net.modfest.platform.pojo.UserCreateData
2425
import net.modfest.platform.pojo.UserData
2526
import net.modfest.platform.pojo.UserPatchData
@@ -106,6 +107,10 @@ class Platform(baseUrl: String) {
106107
return getEvents().map { e -> e.id }
107108
}
108109

110+
suspend fun getUserSubmissions(user: Snowflake): List<SubmissionData> {
111+
return client.get("/user/dc:${user.value}/submissions").unwrapErrors().body()
112+
}
113+
109114
/**
110115
* Retrieve a user by their discord id. Will be null if the user does not exist
111116
*/
@@ -165,12 +170,26 @@ class PlatformAuthenticated(var client: HttpClient, var discordUser: Snowflake)
165170
}
166171

167172
suspend fun submitModrinth(eventId: String, mrId: String): SubmissionData {
168-
return client.post("/event/$eventId/submissions") {
173+
return client.post("/event/$eventId/submissions?type=modrinth") {
169174
addAuth()
170-
setBody(SubmitRequest(mrId))
175+
setBody(SubmitRequestModrinth(mrId))
171176
}.unwrapErrors().body()
172177
}
173178

179+
suspend fun submitOther(eventId: String, data: SubmitRequestOther): SubmissionData {
180+
return client.post("/event/$eventId/submissions?type=other") {
181+
addAuth()
182+
setBody(data)
183+
}.unwrapErrors().body()
184+
}
185+
186+
suspend fun editSubmissionData(eventId: String, subId: String, edit: SubmissionPatchData) {
187+
client.patch("/event/$eventId/submission/$subId") {
188+
addAuth()
189+
setBody(edit)
190+
}
191+
}
192+
174193
suspend fun registerMe(event: EventData) {
175194
client.put("/event/"+event.id+"/registrations/dc:"+discordUser.value) {
176195
addAuth()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DebugCommands : Extension(), KordExKoinComponent {
2828
name = Translations.Commands.Group.Debug.name
2929
description = Translations.Commands.Group.Debug.description
3030

31-
guild(MAIN_GUILD_ID) // Otherwise it will take up to an hour to update
31+
guild(MAIN_GUILD_ID) // Otherwise it will take up to an hour to update
3232

3333
// View health of the bot and platform
3434
ephemeralSubCommand {

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

Lines changed: 122 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package net.modfest.botfest.extensions
22

33
import dev.kord.core.behavior.interaction.response.edit
44
import dev.kordex.core.commands.application.slash.ephemeralSubCommand
5+
import dev.kordex.core.commands.application.slash.group
56
import dev.kordex.core.components.forms.ModalForm
67
import dev.kordex.core.extensions.Extension
78
import dev.kordex.core.extensions.ephemeralSlashCommand
@@ -15,6 +16,7 @@ import dev.kordex.modules.dev.unsafe.extensions.unsafeSlashCommand
1516
import net.modfest.botfest.MAIN_GUILD_ID
1617
import net.modfest.botfest.Platform
1718
import net.modfest.botfest.i18n.Translations
19+
import net.modfest.platform.pojo.SubmitRequestOther
1820
import net.modfest.platform.pojo.UserCreateData
1921
import org.koin.core.component.inject
2022
import java.util.*
@@ -31,12 +33,11 @@ class EventCommands : Extension(), KordExKoinComponent {
3133

3234
@OptIn(UnsafeAPI::class)
3335
override suspend fun setup() {
34-
val platform = bot.getKoin().get<Platform>()
35-
3636
// Register command
3737
unsafeSlashCommand {
3838
name = Translations.Commands.Register.name
3939
description = Translations.Commands.Register.description
40+
guild(MAIN_GUILD_ID)
4041

4142
// We're using KordEx's unsafe api here, because our modal is optional and has prefilled fields.
4243
// This means we're responsible for initiating the response
@@ -160,49 +161,94 @@ class EventCommands : Extension(), KordExKoinComponent {
160161
}
161162
}
162163

163-
// command for submitting a mod
164-
ephemeralSubCommand(::SubmitModal) {
165-
name = Translations.Commands.Event.Submit.name
164+
165+
// commands for submitting
166+
group(Translations.Commands.Event.Submit.name) {
166167
description = Translations.Commands.Event.Submit.description
167168

168-
action { modal ->
169-
if (modal == null) return@action
170-
val curEvent = platform.getCurrentEvent().event
169+
// Submitting a modrinth project
170+
ephemeralSubCommand(::SubmitModalModrinth) {
171+
name = Translations.Commands.Event.Submit.Modrinth.name
172+
description = Translations.Commands.Event.Submit.Modrinth.description
173+
174+
action { modal ->
175+
if (modal == null) return@action
176+
val curEvent = platform.getCurrentEvent().event
177+
178+
if (curEvent == null) {
179+
respond {
180+
content = Translations.Commands.Event.Submit.Response.unavailable
181+
.withContext(this@action)
182+
.translateNamed()
183+
}
184+
return@action
185+
}
171186

172-
if (curEvent == null) {
173-
respond {
174-
content = Translations.Commands.Event.Submit.Response.unavailable
175-
.withContext(this@action)
176-
.translateNamed()
187+
val matcher = MODRINTH_REGEX.matcher(modal.modrinthUrl.value!!)
188+
189+
if (!matcher.find()) {
190+
respond {
191+
content = Translations.Commands.Event.Submit.Response.invalid
192+
.withContext(this@action)
193+
.translateNamed(
194+
"url" to modal.modrinthUrl.value
195+
)
196+
}
197+
return@action
177198
}
178-
return@action
179-
}
180199

181-
val matcher = MODRINTH_REGEX.matcher(modal.modrinthUrl.value!!)
200+
val projectSlug = matcher.group(1)
201+
202+
val eventInfo = platform.getEvent(curEvent)
203+
val submission = platform.withAuth(this.user).submitModrinth(curEvent, projectSlug)
182204

183-
if (!matcher.find()) {
184205
respond {
185-
content = Translations.Commands.Event.Submit.Response.invalid
206+
content = Translations.Commands.Event.Submit.Response.success
186207
.withContext(this@action)
187208
.translateNamed(
188-
"url" to modal.modrinthUrl.value
209+
"event" to eventInfo.name,
210+
"mod" to submission.name
189211
)
190212
}
191-
return@action
192213
}
214+
}
193215

194-
val projectSlug = matcher.group(1)
216+
// Submitting a non-modrinth project
217+
ephemeralSubCommand(::SubmitModalOther) {
218+
name = Translations.Commands.Event.Submit.Other.name
219+
description = Translations.Commands.Event.Submit.Other.description
220+
221+
action { modal ->
222+
if (modal == null) return@action
223+
val curEvent = platform.getCurrentEvent().event
224+
225+
if (curEvent == null) {
226+
respond {
227+
content = Translations.Commands.Event.Submit.Response.unavailable
228+
.withContext(this@action)
229+
.translateNamed()
230+
}
231+
return@action
232+
}
195233

196-
val eventInfo = platform.getEvent(curEvent)
197-
val submission = platform.withAuth(this.user).submitModrinth(curEvent, projectSlug)
234+
val submission = platform.withAuth(this.user).submitOther(curEvent, SubmitRequestOther(
235+
modal.name.value!!,
236+
modal.description.value!!,
237+
setOf("dc:"+user.id),
238+
modal.homepage.value.convertBlankToNull(),
239+
modal.sourcecode.value.convertBlankToNull(),
240+
modal.downloadUrl.value.convertBlankToNull()
241+
))
242+
val eventInfo = platform.getEvent(curEvent)
198243

199-
respond {
200-
content = Translations.Commands.Event.Submit.Response.success
201-
.withContext(this@action)
202-
.translateNamed(
203-
"event" to eventInfo.name,
204-
"mod" to submission.name
205-
)
244+
respond {
245+
content = Translations.Commands.Event.Submit.Response.success
246+
.withContext(this@action)
247+
.translateNamed(
248+
"event" to eventInfo.name,
249+
"mod" to submission.name
250+
)
251+
}
206252
}
207253
}
208254
}
@@ -239,7 +285,7 @@ class EventCommands : Extension(), KordExKoinComponent {
239285

240286

241287

242-
class SubmitModal : ModalForm() {
288+
class SubmitModalModrinth : ModalForm() {
243289
override var title: Key = Translations.Modal.Submit.title
244290

245291
val modrinthUrl = lineText {
@@ -250,4 +296,49 @@ class EventCommands : Extension(), KordExKoinComponent {
250296
required = true
251297
}
252298
}
299+
300+
class SubmitModalOther : ModalForm() {
301+
override var title: Key = Translations.Modal.Submit.title
302+
303+
val name = lineText {
304+
label = Translations.Modal.Submission.Name.label
305+
placeholder = Translations.Modal.Submission.Name.placeholder
306+
minLength = 1
307+
maxLength = 128
308+
required = true
309+
}
310+
311+
val description = lineText {
312+
label = Translations.Modal.Submission.Description.label
313+
placeholder = Translations.Modal.Submission.Description.placeholder
314+
minLength = 1
315+
maxLength = 256
316+
required = true
317+
}
318+
319+
val homepage = lineText {
320+
label = Translations.Modal.Submission.Homepage.label
321+
placeholder = Translations.Modal.Submission.Homepage.placeholder
322+
maxLength = 128
323+
required = false
324+
}
325+
326+
val sourcecode = lineText {
327+
label = Translations.Modal.Submission.Source.extendedlabel
328+
placeholder = Translations.Modal.Submission.Source.placeholder
329+
maxLength = 128
330+
required = false
331+
}
332+
333+
val downloadUrl = lineText {
334+
label = Translations.Modal.Submission.Downloadurl.label
335+
placeholder = Translations.Modal.Submission.Downloadurl.placeholder
336+
maxLength = 128
337+
required = false
338+
}
339+
}
340+
}
341+
342+
private fun String?.convertBlankToNull(): String? {
343+
return if (this.isNullOrBlank()) { null } else { this }
253344
}

0 commit comments

Comments
 (0)