-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is locked to devs only for right now until I finish the full flow that is planned in #113 I also cleaned up some code in a few places while I was messing with some stuff
- Loading branch information
1 parent
66a4f7f
commit b9bac2f
Showing
9 changed files
with
139 additions
and
72 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
client/src/main/kotlin/org/dreamexposure/discal/client/commands/AddCalCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.dreamexposure.discal.client.commands | ||
|
||
import discord4j.core.`object`.entity.Guild | ||
import discord4j.core.`object`.entity.Member | ||
import discord4j.core.event.domain.interaction.SlashCommandEvent | ||
import org.dreamexposure.discal.client.message.Responder | ||
import org.dreamexposure.discal.core.`object`.BotSettings | ||
import org.dreamexposure.discal.core.`object`.GuildSettings | ||
import org.dreamexposure.discal.core.extensions.discord4j.canAddCalendar | ||
import org.dreamexposure.discal.core.extensions.discord4j.hasElevatedPermissions | ||
import org.dreamexposure.discal.core.utils.getCommonMsg | ||
import org.springframework.stereotype.Component | ||
import reactor.core.publisher.Mono | ||
|
||
@Component | ||
class AddCalCommand : SlashCommand { | ||
override val name = "addcal" | ||
override val ephemeral = true | ||
|
||
override fun handle(event: SlashCommandEvent, settings: GuildSettings): Mono<Void> { | ||
//TODO: Remove dev-only and switch to patron-only once this is completed | ||
return if (settings.devGuild) { | ||
Mono.justOrEmpty(event.interaction.member) | ||
.filterWhen(Member::hasElevatedPermissions).flatMap { | ||
//Check if a calendar can be added since non-premium only allows 1 calendar. | ||
event.interaction.guild.filterWhen(Guild::canAddCalendar).flatMap { | ||
Responder.followupEphemeral(event, getMessage("response.start", settings, getLink(settings))) | ||
}.switchIfEmpty(Responder.followupEphemeral(event, getCommonMsg("error.calendar.max", settings))) | ||
}.switchIfEmpty(Responder.followupEphemeral(event, getCommonMsg("error.perms.elevated", settings))) | ||
.then() | ||
} else { | ||
Responder.followupEphemeral(event, getCommonMsg("error.disabled", settings)).then() | ||
} | ||
} | ||
|
||
private fun getLink(settings: GuildSettings): String { | ||
return "${BotSettings.BASE_URL.get()}/dashboard/${settings.guildID.asString()}/calendar/new?type=1&step=0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,4 +173,6 @@ interface Event { | |
.put("rrule", recurrence.toRRule()) | ||
.put("image", eventData.imageLink) | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "addcal", | ||
"description": "Used to add an external (already existing) calendar to DisCal", | ||
"default_permissions": true | ||
} |
8 changes: 2 additions & 6 deletions
8
core/src/main/resources/i18n/command/addcal/addcal.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
meta.description=Used to add an external calendar | ||
meta.example=/addcal (calendar-id) | ||
response.started=Instructions on how to authorize DisCal and add your calendar have been DMed to you | ||
success=Successfully linked your calendar! you can start creating events, announcements, and more! | ||
failure.notStarted=Please start the process with `/addcal` before selecting a calendar to connect. | ||
failure.invalid=The supplied ID was not recognized, are you sure it is correct? | ||
failure.badArgs=Invalid arguments were supplied. See command info with `/help addcal` | ||
error.hasCalendar=A calendar already exists. View it with `/linkcal` | ||
|
||
response.start=To add an external calendar, please visit this link and follow the provided instructions: {0} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters