@@ -2,6 +2,7 @@ package net.modfest.botfest.extensions
22
33import dev.kord.core.behavior.interaction.response.edit
44import dev.kordex.core.commands.application.slash.ephemeralSubCommand
5+ import dev.kordex.core.commands.application.slash.group
56import dev.kordex.core.components.forms.ModalForm
67import dev.kordex.core.extensions.Extension
78import dev.kordex.core.extensions.ephemeralSlashCommand
@@ -15,6 +16,7 @@ import dev.kordex.modules.dev.unsafe.extensions.unsafeSlashCommand
1516import net.modfest.botfest.MAIN_GUILD_ID
1617import net.modfest.botfest.Platform
1718import net.modfest.botfest.i18n.Translations
19+ import net.modfest.platform.pojo.SubmitRequestOther
1820import net.modfest.platform.pojo.UserCreateData
1921import org.koin.core.component.inject
2022import 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