Skip to content

Commit b521474

Browse files
committed
Disable submit button if conditions are not met
1 parent 91e1b0b commit b521474

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
alias(libs.plugins.kotlin.serialization) apply false
66
}
77
allprojects {
8-
version = "5.5.0"
8+
version = "5.5.1"
99
group = "space.votebot"
1010

1111
repositories {

plugin/src/main/kotlin/space/votebot/commands/vote/create/CreateCommand.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import com.kotlindiscord.kord.extensions.parsers.DurationParserException
1515
import com.kotlindiscord.kord.extensions.utils.getJumpUrl
1616
import dev.kord.common.asJavaLocale
1717
import dev.kord.common.entity.ButtonStyle
18-
import dev.kord.core.behavior.channel.asChannelOf
1918
import dev.kord.core.entity.channel.Channel
2019
import dev.kord.x.emoji.DiscordEmoji
2120
import dev.kord.x.emoji.Emojis
@@ -124,6 +123,7 @@ suspend fun VoteBotModule.createCommand() = ephemeralSlashCommand(::CreateArgume
124123

125124
lateinit var addOptionButton: InteractionButtonWithAction<*, *>
126125
lateinit var removeOptionButton: InteractionButtonWithAction<*, *>
126+
lateinit var submitButton: InteractionButtonWithAction<*, *>
127127

128128
addOptionButton = ephemeralButton(::AddOptionModal, row = 1) {
129129
label = translate("commands.create.interactive.add_option.label")
@@ -143,6 +143,9 @@ suspend fun VoteBotModule.createCommand() = ephemeralSlashCommand(::CreateArgume
143143
disable()
144144
}
145145
removeOptionButton.enable()
146+
if (poll.options.size >= 2) {
147+
submitButton.enable()
148+
}
146149
update()
147150
}
148151
}
@@ -176,6 +179,9 @@ suspend fun VoteBotModule.createCommand() = ephemeralSlashCommand(::CreateArgume
176179
if (poll.options.isEmpty()) {
177180
disable()
178181
}
182+
if (poll.options.size < 2) {
183+
submitButton.disable()
184+
}
179185
addOptionButton.enable()
180186
update()
181187
edit {
@@ -194,6 +200,7 @@ suspend fun VoteBotModule.createCommand() = ephemeralSlashCommand(::CreateArgume
194200
emoji(Emojis.heavyCheckMark.toString())
195201
label = translate("commands.create.interactive.submit")
196202
bundle = this@createCommand.bundle
203+
disabled = true
197204

198205
action {
199206
val settings = object : CreateSettings {

0 commit comments

Comments
 (0)