Skip to content

Commit 1ba58bd

Browse files
committed
Add ability to specify event duration when setting the start
This now means the event end command is no longer required, eliminating a step for some users
1 parent f1b82e2 commit 1ba58bd

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

client/src/main/kotlin/org/dreamexposure/discal/client/commands/global/EventCommand.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ class EventCommand(
251251
.map(Long::toInt)
252252
.map { it.coerceAtLeast(0).coerceAtMost(59) }
253253
.orElse(0)
254+
val duration = event.options[0].getOption("duration")
255+
.flatMap(ApplicationCommandInteractionOption::getValue)
256+
.map(ApplicationCommandInteractionOptionValue::asLong)
257+
.getOrNull()
254258
val keepDuration = event.options[0].getOption("keep-duration")
255259
.flatMap(ApplicationCommandInteractionOption::getValue)
256260
.map(ApplicationCommandInteractionOptionValue::asBoolean)
@@ -280,7 +284,7 @@ class EventCommand(
280284
).toInstant()
281285

282286
if (existingWizard.entity.end == null) {
283-
val modifiedWizard = existingWizard.copy(entity = existingWizard.entity.copy(start = start, end = start.plus(1, ChronoUnit.HOURS)))
287+
val modifiedWizard = existingWizard.copy(entity = existingWizard.entity.copy(start = start, end = start.plus(duration ?: 1, ChronoUnit.HOURS)))
284288
calendarService.putEventWizard(modifiedWizard)
285289

286290
// Handle special messaging if event is scheduled for the past
@@ -299,7 +303,7 @@ class EventCommand(
299303
val shouldChangeDuration = keepDuration && originalDuration != null
300304

301305
if (existingWizard.entity.end!!.isAfter(start) || shouldChangeDuration) {
302-
val modifiedEnd = if (shouldChangeDuration) start.plus(originalDuration) else existingWizard.entity.end
306+
val modifiedEnd = if (duration != null) start.plus(duration, ChronoUnit.HOURS) else if (shouldChangeDuration) start.plus(originalDuration) else existingWizard.entity.end
303307
val modifiedWizard = existingWizard.copy(entity = existingWizard.entity.copy(start = start, end = modifiedEnd))
304308
calendarService.putEventWizard(modifiedWizard)
305309

core/src/main/resources/commands/global/event.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@
252252
"min_value": 0,
253253
"max_value": 59
254254
},
255+
{
256+
"name": "duration",
257+
"type": 4,
258+
"description": "The length of the event, in hours",
259+
"required": false,
260+
"min_value": 0
261+
},
255262
{
256263
"name": "keep-duration",
257264
"type": 5,

web/src/main/html/templates/various/commands.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ <h2 class="text-center text-discal-blue">/event commands</h2>
423423
<tr class="flex-table" role="rowgroup">
424424
<td class="tb-flex-row tb-command" role="cell">start</td>
425425
<td class="tb-flex-row" role="cell">Sets the event's start</td>
426-
<td class="tb-flex-row tb-usage" role="cell">/event start [yyyy] [MM] [dd] (hh) (mm)</td>
426+
<td class="tb-flex-row tb-usage" role="cell">/event start [yyyy] [MM] [dd] (hh) (mm) (duration) (keep-duration)</td>
427427
<td class="tb-flex-row tb-access" role="cell">privileged</td>
428428
</tr>
429429

0 commit comments

Comments
 (0)