Skip to content

Commit c188758

Browse files
authored
Add support for Components V2 (#233)
- Add unions on components - Add test verifying custom components do implement required JDA unions - Override new `setCustomId` on select menu builders - Fix addActionRow/setActionRow deprecations - Replace `id` deprecations to `customId`/`uniqueId` - When getting action components, use ComponentTree#findAll - Replace LayoutComponent by MessageTopLevelComponent - Add compatibility method for UsedComponentSet#setComponents - Add missing component overrides - Test components override super methods that returns their declaring class - Add ComponentTree extensions - Add DSLs for new components - Update KSP snapshot - 'RangesCompat.kt' changed due to JDA 6 package changes - Add link buttons - Add AbstractComponentFactory#deleteTree
1 parent 91eb5dc commit c188758

File tree

87 files changed

+1721
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1721
-226
lines changed

BotCommands-core/src/examples/kotlin/io/github/freya022/bot/commands/slash/SlashBan.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.freya022.bot.commands.slash
22

3+
import dev.freya02.botcommands.jda.ktx.components.row
34
import dev.freya02.botcommands.jda.ktx.messages.deleteDelayed
45
import io.github.freya022.bot.commands.ban.BanService
56
import io.github.freya022.bot.resolvers.localize
@@ -79,7 +80,7 @@ class SlashBan(private val buttons: Buttons, private val banService: BanService)
7980
}
8081

8182
event.replyLocalizedEphemeral(localizationContext, "outputs.confirmationMessage", "userMention" to target.asMention)
82-
.addActionRow(cancelButton, confirmButton)
83+
.addComponents(row(cancelButton, confirmButton))
8384
.queue()
8485

8586
val componentEvent: ButtonEvent = try {
@@ -91,13 +92,13 @@ class SlashBan(private val buttons: Buttons, private val banService: BanService)
9192
}
9293

9394
when (componentEvent.componentId) {
94-
cancelButton.id -> {
95+
cancelButton.customId -> {
9596
logger.debug { "Ban cancelled for ${target.id}" }
9697
componentEvent.replaceLocalized(localizationContext, "outputs.cancelled").queue()
9798

9899
//Cancel logic
99100
}
100-
confirmButton.id -> {
101+
confirmButton.customId -> {
101102
logger.debug { "Ban confirmed for ${target.id}, $timeframe of messages were deleted, reason: '$reason'" }
102103

103104
componentEvent.replaceLocalized(

BotCommands-core/src/javaDocExamples/java/doc/java/examples/commands/slash/SlashSayAgainEphemeral.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import io.github.freya022.botcommands.api.commands.application.slash.annotations.SlashOption;
99
import io.github.freya022.botcommands.api.components.Buttons;
1010
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents;
11-
import net.dv8tion.jda.api.interactions.components.ActionRow;
12-
import net.dv8tion.jda.api.interactions.components.buttons.Button;
11+
import net.dv8tion.jda.api.components.actionrow.ActionRow;
12+
import net.dv8tion.jda.api.components.buttons.Button;
1313
import net.dv8tion.jda.api.utils.TimeFormat;
1414

1515
import java.time.Duration;
@@ -40,7 +40,7 @@ public void onSlashSayAgain(
4040
temporaryButtonRef.set(temporarySaySentenceButton); // We have to do this to get the button in our timeout handler
4141

4242
event.reply("This button expires " + TimeFormat.RELATIVE.after(Duration.ofSeconds(10)))
43-
.addActionRow(temporarySaySentenceButton)
43+
.addComponents(ActionRow.of(temporarySaySentenceButton))
4444
.queue();
4545
}
4646
}

BotCommands-core/src/javaDocExamples/java/doc/java/examples/commands/slash/SlashSayAgainPersistent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import io.github.freya022.botcommands.api.components.annotations.JDAButtonListener;
1212
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents;
1313
import io.github.freya022.botcommands.api.components.event.ButtonEvent;
14-
import net.dv8tion.jda.api.interactions.components.buttons.Button;
14+
import net.dv8tion.jda.api.components.actionrow.ActionRow;
15+
import net.dv8tion.jda.api.components.buttons.Button;
1516

1617
@Command
1718
@RequiresComponents
@@ -35,7 +36,7 @@ public void onSlashSayAgain(
3536
.build();
3637

3738
event.reply("This button always works")
38-
.addActionRow(persistentSaySentenceButton)
39+
.addComponents(ActionRow.of(persistentSaySentenceButton))
3940
.queue();
4041
}
4142

BotCommands-core/src/javaDocExamples/java/doc/java/examples/commands/slash/SlashSelectRoleEphemeral.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import io.github.freya022.botcommands.api.components.EntitySelectMenu;
88
import io.github.freya022.botcommands.api.components.SelectMenus;
99
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents;
10+
import net.dv8tion.jda.api.components.actionrow.ActionRow;
11+
import net.dv8tion.jda.api.components.selections.EntitySelectMenu.SelectTarget;
1012
import net.dv8tion.jda.api.entities.Role;
11-
import net.dv8tion.jda.api.interactions.components.ActionRow;
12-
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu.SelectTarget;
1313
import net.dv8tion.jda.api.utils.TimeFormat;
1414

1515
import java.time.Duration;
@@ -47,7 +47,7 @@ public void onSlashSelectRole(
4747
temporarySelectMenuRef.set(roleMenu);
4848

4949
event.reply("This select menu expires " + TimeFormat.RELATIVE.after(Duration.ofSeconds(10)))
50-
.addActionRow(roleMenu)
50+
.addComponents(ActionRow.of(roleMenu))
5151
.queue();
5252
}
5353
}

BotCommands-core/src/javaDocExamples/java/doc/java/examples/commands/slash/SlashSelectRolePersistent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
import io.github.freya022.botcommands.api.components.annotations.JDASelectMenuListener;
1111
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents;
1212
import io.github.freya022.botcommands.api.components.event.EntitySelectEvent;
13+
import net.dv8tion.jda.api.components.actionrow.ActionRow;
14+
import net.dv8tion.jda.api.components.selections.EntitySelectMenu.SelectTarget;
1315
import net.dv8tion.jda.api.entities.Role;
14-
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu.SelectTarget;
1516

1617
import java.util.concurrent.ThreadLocalRandom;
1718

@@ -36,7 +37,7 @@ public void onSlashSelectRole(
3637
.build();
3738

3839
event.reply("This select menu always works")
39-
.addActionRow(roleMenu)
40+
.addComponents(ActionRow.of(roleMenu))
4041
.queue();
4142
}
4243

BotCommands-core/src/kotlinDocExamples/kotlin/doc/kotlin/examples/commands/slash/SlashSayAgainEphemeral.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.github.freya022.botcommands.api.commands.application.slash.annotations
1212
import io.github.freya022.botcommands.api.commands.application.slash.annotations.SlashOption
1313
import io.github.freya022.botcommands.api.components.Buttons
1414
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
15-
import net.dv8tion.jda.api.interactions.components.buttons.Button
15+
import net.dv8tion.jda.api.components.buttons.Button
1616
import net.dv8tion.jda.api.utils.TimeFormat
1717
import kotlin.time.Duration.Companion.seconds
1818

@@ -43,7 +43,7 @@ class SlashSayAgainEphemeral : ApplicationCommand() {
4343
}
4444

4545
event.reply("This button expires ${TimeFormat.RELATIVE.after(10.seconds)}")
46-
.addActionRow(temporarySaySentenceButton)
46+
.addComponents(row(temporarySaySentenceButton))
4747
.await()
4848
}
4949
}

BotCommands-core/src/kotlinDocExamples/kotlin/doc/kotlin/examples/commands/slash/SlashSayAgainPersistent.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package doc.kotlin.examples.commands.slash
22

3+
import dev.freya02.botcommands.jda.ktx.components.row
34
import dev.freya02.botcommands.jda.ktx.coroutines.await
45
import dev.freya02.botcommands.jda.ktx.messages.reply_
56
import io.github.freya022.botcommands.api.commands.annotations.Command
@@ -15,7 +16,7 @@ import io.github.freya022.botcommands.api.components.annotations.JDAButtonListen
1516
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
1617
import io.github.freya022.botcommands.api.components.builder.bindWith
1718
import io.github.freya022.botcommands.api.components.event.ButtonEvent
18-
import net.dv8tion.jda.api.interactions.components.buttons.Button
19+
import net.dv8tion.jda.api.components.buttons.Button
1920

2021
@Command
2122
@RequiresComponents
@@ -38,7 +39,7 @@ class SlashSayAgainPersistent : ApplicationCommand() {
3839
}
3940

4041
event.reply("This button always works")
41-
.addActionRow(persistentSaySentenceButton)
42+
.addComponents(row(persistentSaySentenceButton))
4243
.await()
4344
}
4445

BotCommands-core/src/kotlinDocExamples/kotlin/doc/kotlin/examples/commands/slash/SlashSelectRoleEphemeral.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package doc.kotlin.examples.commands.slash
22

3+
import dev.freya02.botcommands.jda.ktx.components.row
34
import dev.freya02.botcommands.jda.ktx.coroutines.await
45
import dev.freya02.botcommands.jda.ktx.durations.after
56
import io.github.freya022.botcommands.api.commands.annotations.Command
@@ -9,9 +10,9 @@ import io.github.freya022.botcommands.api.commands.application.slash.annotations
910
import io.github.freya022.botcommands.api.components.EntitySelectMenu
1011
import io.github.freya022.botcommands.api.components.SelectMenus
1112
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
13+
import net.dv8tion.jda.api.components.actionrow.ActionRow
14+
import net.dv8tion.jda.api.components.selections.EntitySelectMenu.SelectTarget
1215
import net.dv8tion.jda.api.entities.Role
13-
import net.dv8tion.jda.api.interactions.components.ActionRow
14-
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu.SelectTarget
1516
import net.dv8tion.jda.api.utils.TimeFormat
1617
import kotlin.random.Random
1718
import kotlin.time.Duration.Companion.seconds
@@ -45,7 +46,7 @@ class SlashSelectRoleEphemeral : ApplicationCommand() {
4546
temporarySelectMenu = roleMenu
4647

4748
event.reply("This select menu expires ${TimeFormat.RELATIVE.after(10.seconds)}")
48-
.addActionRow(roleMenu)
49+
.addComponents(row(roleMenu))
4950
.await()
5051
}
5152
}

BotCommands-core/src/kotlinDocExamples/kotlin/doc/kotlin/examples/commands/slash/SlashSelectRolePersistent.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package doc.kotlin.examples.commands.slash
22

3+
import dev.freya02.botcommands.jda.ktx.components.row
34
import dev.freya02.botcommands.jda.ktx.coroutines.await
45
import io.github.freya022.botcommands.api.commands.annotations.Command
56
import io.github.freya022.botcommands.api.commands.application.ApplicationCommand
@@ -12,8 +13,8 @@ import io.github.freya022.botcommands.api.components.annotations.JDASelectMenuLi
1213
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
1314
import io.github.freya022.botcommands.api.components.builder.bindWith
1415
import io.github.freya022.botcommands.api.components.event.EntitySelectEvent
16+
import net.dv8tion.jda.api.components.selections.EntitySelectMenu.SelectTarget
1517
import net.dv8tion.jda.api.entities.Role
16-
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu.SelectTarget
1718
import kotlin.random.Random
1819

1920
@Command
@@ -33,7 +34,7 @@ class SlashSelectRolePersistent : ApplicationCommand() {
3334
}
3435

3536
event.reply("This select menu always works")
36-
.addActionRow(roleMenu)
37+
.addComponents(row(roleMenu))
3738
.await()
3839
}
3940

BotCommands-core/src/kotlinDocExamples/kotlin/doc/kotlin/examples/commands/slash/SlashTypeSafeSelectMenus.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import io.github.freya022.botcommands.api.components.annotations.JDASelectMenuLi
1414
import io.github.freya022.botcommands.api.components.annotations.RequiresComponents
1515
import io.github.freya022.botcommands.api.components.builder.bindWith
1616
import io.github.freya022.botcommands.api.components.event.EntitySelectEvent
17-
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu
17+
import net.dv8tion.jda.api.components.selections.EntitySelectMenu
1818

1919
@Command
2020
@RequiresComponents

0 commit comments

Comments
 (0)