diff --git a/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashEntity.kt b/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashEntity.kt index 74fa2ba3b..f1d55ef25 100644 --- a/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashEntity.kt +++ b/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashEntity.kt @@ -6,9 +6,10 @@ import dev.minn.jda.ktx.messages.into import io.github.freya022.botcommands.api.commands.annotations.Command import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandManager import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandProvider -import io.github.freya022.botcommands.api.commands.application.slash.GlobalSlashEvent +import io.github.freya022.botcommands.api.commands.application.slash.GuildSlashEvent import io.github.freya022.botcommands.api.components.Buttons import io.github.freya022.botcommands.api.components.SelectMenus +import io.github.freya022.botcommands.api.core.utils.enumSetOf import io.github.freya022.botcommands.api.modals.Modals import net.dv8tion.jda.api.entities.Member import net.dv8tion.jda.api.entities.Role @@ -35,27 +36,27 @@ class SlashEntity(private val buttons: Buttons, private val modals: Modals, priv // val mediaChannel: MediaChannel ) - suspend fun onSlashEntityNothing(event: GlobalSlashEvent) { + suspend fun onSlashEntityNothing(event: GuildSlashEvent) { reply(event, null) } - suspend fun onSlashEntityMember(event: GlobalSlashEvent, member: Member) { + suspend fun onSlashEntityMember(event: GuildSlashEvent, member: Member) { reply(event, member) } - suspend fun onSlashEntityRole(event: GlobalSlashEvent, role: Role) { + suspend fun onSlashEntityRole(event: GuildSlashEvent, role: Role) { reply(event, role) } - suspend fun onSlashEntityTextChannel(event: GlobalSlashEvent, textChannel: TextChannel) { + suspend fun onSlashEntityTextChannel(event: GuildSlashEvent, textChannel: TextChannel) { reply(event, textChannel) } - suspend fun onSlashEntityAll(event: GlobalSlashEvent, allEntities: AllEntities) { + suspend fun onSlashEntityAll(event: GuildSlashEvent, allEntities: AllEntities) { reply(event, allEntities) } - private suspend fun reply(event: GlobalSlashEvent, arg: Any?) { + private suspend fun reply(event: GuildSlashEvent, arg: Any?) { event.deferReply(false).await() println(arg) @@ -98,7 +99,7 @@ class SlashEntity(private val buttons: Buttons, private val modals: Modals, priv override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { manager.slashCommand("entities", function = null) { - contexts = InteractionContextType.ALL + contexts = enumSetOf(InteractionContextType.GUILD) integrationTypes = IntegrationType.ALL subcommand("nothing", ::onSlashEntityNothing) diff --git a/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationOwners.kt b/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationOwners.kt index 56c7b3337..a7a244752 100644 --- a/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationOwners.kt +++ b/src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationOwners.kt @@ -8,6 +8,7 @@ import io.github.freya022.botcommands.api.commands.application.provider.GlobalAp import io.github.freya022.botcommands.api.commands.application.provider.GuildApplicationCommandManager import io.github.freya022.botcommands.api.commands.application.provider.GuildApplicationCommandProvider import io.github.freya022.botcommands.api.commands.application.slash.GlobalSlashEvent +import io.github.freya022.botcommands.api.commands.application.slash.GuildSlashEvent import io.github.freya022.botcommands.api.components.Buttons import io.github.freya022.botcommands.api.core.utils.enumSetOf import net.dv8tion.jda.api.interactions.IntegrationType @@ -15,7 +16,23 @@ import net.dv8tion.jda.api.interactions.InteractionContextType @Command class SlashIntegrationOwners(private val buttons: Buttons) : GlobalApplicationCommandProvider, GuildApplicationCommandProvider { - suspend fun run(event: GlobalSlashEvent) { + suspend fun onSlashGlobalOwners(event: GlobalSlashEvent) { + run(event) + } + + suspend fun onSlashGlobalOwnersOnlyUser(event: GlobalSlashEvent) { + run(event) + } + + suspend fun onSlashGlobalOwnersOnlyGuild(event: GlobalSlashEvent) { + run(event) + } + + suspend fun onSlashGuildOwners(event: GuildSlashEvent) { + run(event) + } + + private suspend fun run(event: GlobalSlashEvent) { val button = buttons.primary("click me").ephemeral { bindTo { it.deferEdit().await() } } @@ -23,24 +40,24 @@ class SlashIntegrationOwners(private val buttons: Buttons) : GlobalApplicationCo } override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { - manager.slashCommand("global_owners", ::run) { + manager.slashCommand("global_owners", ::onSlashGlobalOwners) { integrationTypes = IntegrationType.ALL contexts = InteractionContextType.ALL } - manager.slashCommand("global_owners_only_user", ::run) { + manager.slashCommand("global_owners_only_user", ::onSlashGlobalOwnersOnlyUser) { integrationTypes = enumSetOf(IntegrationType.USER_INSTALL) contexts = InteractionContextType.ALL } - manager.slashCommand("global_owners_only_guild", ::run) { + manager.slashCommand("global_owners_only_guild", ::onSlashGlobalOwnersOnlyGuild) { integrationTypes = enumSetOf(IntegrationType.GUILD_INSTALL) contexts = InteractionContextType.ALL } } override fun declareGuildApplicationCommands(manager: GuildApplicationCommandManager) { - manager.slashCommand("guild_owners", ::run) { + manager.slashCommand("guild_owners", ::onSlashGuildOwners) { } } diff --git a/src/test/kotlin/io/github/freya022/botcommands/test/commands/user/UserContextInfo.kt b/src/test/kotlin/io/github/freya022/botcommands/test/commands/user/UserContextInfo.kt index 54cb1eb01..e22d8beaa 100644 --- a/src/test/kotlin/io/github/freya022/botcommands/test/commands/user/UserContextInfo.kt +++ b/src/test/kotlin/io/github/freya022/botcommands/test/commands/user/UserContextInfo.kt @@ -16,6 +16,7 @@ import io.github.freya022.botcommands.api.core.entities.InputUser import io.github.freya022.botcommands.api.core.reflect.ParameterType import net.dv8tion.jda.api.entities.Guild import net.dv8tion.jda.api.events.interaction.command.UserContextInteractionEvent +import net.dv8tion.jda.api.interactions.InteractionContextType.* @Command class UserContextInfo : ApplicationCommand(), GlobalApplicationCommandProvider { @@ -37,7 +38,7 @@ class UserContextInfo : ApplicationCommand(), GlobalApplicationCommandProvider { return super.getGeneratedValueSupplier(guild, commandId, commandPath, optionName, parameterType) } - @JDAUserCommand(scope = CommandScope.GLOBAL, name = "User info (annotated)") + @JDAUserCommand(scope = CommandScope.GLOBAL, contexts = [GUILD, BOT_DM, PRIVATE_CHANNEL], name = "User info (annotated)") fun onUserContextInfo( event: GlobalUserEvent, @ContextOption user: InputUser, @@ -48,6 +49,8 @@ class UserContextInfo : ApplicationCommand(), GlobalApplicationCommandProvider { override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { manager.userCommand("User info", ::onUserContextInfo) { + contexts = ALL + option("user") generatedOption("userTag") {