-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
351 additions
and
1 deletion.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/test/kotlin/io/github/freya022/botcommands/test/commands/message/MessageContextTest.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,41 @@ | ||
package io.github.freya022.botcommands.test.commands.message | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
import dev.minn.jda.ktx.messages.reply_ | ||
import io.github.freya022.botcommands.api.commands.annotations.Command | ||
import io.github.freya022.botcommands.api.commands.application.ApplicationCommand | ||
import io.github.freya022.botcommands.api.commands.application.context.annotations.JDAMessageCommand | ||
import io.github.freya022.botcommands.api.commands.application.context.message.GlobalMessageEvent | ||
import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandManager | ||
import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandProvider | ||
import net.dv8tion.jda.api.entities.Message | ||
import net.dv8tion.jda.api.interactions.IntegrationType | ||
import net.dv8tion.jda.api.interactions.IntegrationType.GUILD_INSTALL | ||
import net.dv8tion.jda.api.interactions.IntegrationType.USER_INSTALL | ||
import net.dv8tion.jda.api.interactions.InteractionContextType | ||
import net.dv8tion.jda.api.interactions.InteractionContextType.* | ||
|
||
@Command | ||
class MessageContextTest : ApplicationCommand(), GlobalApplicationCommandProvider { | ||
@JDAMessageCommand( | ||
name = "test message (annotated)", | ||
contexts = [GUILD, BOT_DM, PRIVATE_CHANNEL], | ||
integrationTypes = [GUILD_INSTALL, USER_INSTALL] | ||
) | ||
suspend fun onMessageContextTest(event: GlobalMessageEvent) { | ||
event.reply_("Reply", ephemeral = true).await() | ||
|
||
println() | ||
|
||
event.hook.editOriginal("test") | ||
.flatMap(Message::delete) | ||
.await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.messageCommand("test message", ::onMessageContextTest) { | ||
contexts = InteractionContextType.ALL | ||
integrationTypes = IntegrationType.ALL | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...est/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashDetachedPermissions.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,51 @@ | ||
package io.github.freya022.botcommands.test.commands.slash | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
import io.github.freya022.botcommands.api.commands.annotations.Command | ||
import io.github.freya022.botcommands.api.commands.application.ApplicationCommand | ||
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.GuildSlashEvent | ||
import io.github.freya022.botcommands.api.commands.application.slash.annotations.JDASlashCommand | ||
import io.github.freya022.botcommands.api.commands.application.slash.annotations.SlashOption | ||
import io.github.freya022.botcommands.api.commands.application.slash.annotations.TopLevelSlashCommandData | ||
import io.github.freya022.botcommands.api.core.utils.enumSetOf | ||
import net.dv8tion.jda.api.entities.Member | ||
import net.dv8tion.jda.api.entities.Role | ||
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel | ||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel | ||
import net.dv8tion.jda.api.interactions.IntegrationType.* | ||
import net.dv8tion.jda.api.interactions.InteractionContextType.GUILD | ||
|
||
@Command | ||
class SlashDetachedPermissions : ApplicationCommand(), GlobalApplicationCommandProvider { | ||
@JDASlashCommand("detached_permissions_annotated") | ||
@TopLevelSlashCommandData( | ||
contexts = [GUILD], | ||
integrationTypes = [GUILD_INSTALL, USER_INSTALL] | ||
) | ||
suspend fun onSlashDetachedPermissions(event: GuildSlashEvent, @SlashOption member: Member, @SlashOption role: Role, @SlashOption channel: TextChannel, @SlashOption channel2: TextChannel, @SlashOption thread: ThreadChannel?) { | ||
event.deferReply(true).await() | ||
|
||
event.hook.sendMessage(""" | ||
$member | ||
$role | ||
$channel | ||
$channel2 | ||
$thread | ||
""".trimIndent()).await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.slashCommand("detached_permissions", ::onSlashDetachedPermissions) { | ||
contexts = enumSetOf(GUILD) | ||
integrationTypes = ALL | ||
|
||
option("member") | ||
option("role") | ||
option("channel") | ||
option("channel2") | ||
option("thread") | ||
} | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashEntity.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,131 @@ | ||
package io.github.freya022.botcommands.test.commands.slash | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
import dev.minn.jda.ktx.messages.MessageCreate | ||
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.components.Buttons | ||
import io.github.freya022.botcommands.api.components.SelectMenus | ||
import io.github.freya022.botcommands.api.modals.Modals | ||
import net.dv8tion.jda.api.entities.Member | ||
import net.dv8tion.jda.api.entities.Role | ||
import net.dv8tion.jda.api.entities.User | ||
import net.dv8tion.jda.api.entities.channel.concrete.* | ||
import net.dv8tion.jda.api.interactions.IntegrationType | ||
import net.dv8tion.jda.api.interactions.InteractionContextType | ||
import net.dv8tion.jda.api.interactions.components.selections.EntitySelectMenu | ||
|
||
// Uses breakpoints to see stuff about the interaction | ||
@Command | ||
class SlashEntity(private val buttons: Buttons, private val modals: Modals, private val selectMenus: SelectMenus) : GlobalApplicationCommandProvider { | ||
data class AllEntities( | ||
val user: User, | ||
val member: Member, | ||
val role: Role, | ||
val textChannel: TextChannel, | ||
val newsChannel: NewsChannel, | ||
val stageChannel: StageChannel, | ||
val voiceChannel: VoiceChannel, | ||
val category: Category, | ||
val forumChannel: ForumChannel, | ||
val threadChannel: ThreadChannel | ||
// val mediaChannel: MediaChannel | ||
) | ||
|
||
suspend fun onSlashEntityNothing(event: GlobalSlashEvent) { | ||
reply(event, null) | ||
} | ||
|
||
suspend fun onSlashEntityMember(event: GlobalSlashEvent, member: Member) { | ||
reply(event, member) | ||
} | ||
|
||
suspend fun onSlashEntityRole(event: GlobalSlashEvent, role: Role) { | ||
reply(event, role) | ||
} | ||
|
||
suspend fun onSlashEntityTextChannel(event: GlobalSlashEvent, textChannel: TextChannel) { | ||
reply(event, textChannel) | ||
} | ||
|
||
suspend fun onSlashEntityAll(event: GlobalSlashEvent, allEntities: AllEntities) { | ||
reply(event, allEntities) | ||
} | ||
|
||
private suspend fun reply(event: GlobalSlashEvent, arg: Any?) { | ||
event.deferReply(false).await() | ||
|
||
println(arg) | ||
|
||
val message = MessageCreate { | ||
content = "It works! <@222046562543468545>" | ||
|
||
components += buttons.primary("Click me").ephemeral { | ||
bindTo { | ||
it.editMessage("Boo").await() | ||
it.hook.sendMessage("ye").await() | ||
// it.reply_("Ye", ephemeral = true).await() | ||
} | ||
}.into() | ||
|
||
components += selectMenus.entitySelectMenu(EntitySelectMenu.SelectTarget.CHANNEL).ephemeral { | ||
bindTo { | ||
it.editMessage("Foo ${it.values}").await() | ||
it.hook.sendMessage("bar").await() | ||
} | ||
}.into() | ||
|
||
components += selectMenus.entitySelectMenu(EntitySelectMenu.SelectTarget.USER).ephemeral { | ||
bindTo { | ||
it.editMessage("Foo ${it.values}").await() | ||
it.hook.sendMessage("bar").await() | ||
} | ||
}.into() | ||
|
||
components += selectMenus.entitySelectMenu(EntitySelectMenu.SelectTarget.ROLE).ephemeral { | ||
bindTo { | ||
it.editMessage("Foo ${it.values}").await() | ||
it.hook.sendMessage("bar").await() | ||
} | ||
}.into() | ||
} | ||
|
||
event.hook.sendMessage(message).await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.slashCommand("entities", function = null) { | ||
contexts = InteractionContextType.ALL | ||
integrationTypes = IntegrationType.ALL | ||
|
||
subcommand("nothing", ::onSlashEntityNothing) | ||
subcommand("all", ::onSlashEntityAll) { | ||
aggregate("allEntities", SlashEntity::AllEntities) { | ||
option("user") | ||
option("member") | ||
option("role") | ||
option("textChannel") | ||
option("newsChannel") | ||
option("stageChannel") | ||
option("voiceChannel") | ||
option("category") | ||
option("forumChannel") | ||
option("threadChannel") | ||
// option("mediaChannel") | ||
} | ||
} | ||
subcommand("member", ::onSlashEntityMember) { | ||
option("member") | ||
} | ||
subcommand("role", ::onSlashEntityRole) { | ||
option("role") | ||
} | ||
subcommand("text_channel", ::onSlashEntityTextChannel) { | ||
option("textChannel") | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...est/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationContexts.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 io.github.freya022.botcommands.test.commands.slash | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
import dev.minn.jda.ktx.messages.reply_ | ||
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.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.core.utils.enumSetOf | ||
import net.dv8tion.jda.api.interactions.IntegrationType | ||
import net.dv8tion.jda.api.interactions.InteractionContextType | ||
|
||
// Uses breakpoints to see stuff about the interaction | ||
@Command | ||
class SlashIntegrationContexts : GlobalApplicationCommandProvider, GuildApplicationCommandProvider { | ||
suspend fun onIntegrationContextsTestGuildCommand(event: GuildSlashEvent) { | ||
event.reply_("ok", ephemeral = true).await() | ||
} | ||
|
||
suspend fun onIntegrationContextsTestGlobalGuildCommand(event: GlobalSlashEvent) { | ||
event.reply_("ok", ephemeral = true).await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.slashCommand("global_integration_contexts", ::onIntegrationContextsTestGlobalGuildCommand) { | ||
contexts = enumSetOf(InteractionContextType.GUILD, InteractionContextType.BOT_DM) | ||
integrationTypes = enumSetOf(IntegrationType.GUILD_INSTALL) | ||
} | ||
} | ||
|
||
override fun declareGuildApplicationCommands(manager: GuildApplicationCommandManager) { | ||
manager.slashCommand("guild_integration_contexts", ::onIntegrationContextsTestGuildCommand) { | ||
|
||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/kotlin/io/github/freya022/botcommands/test/commands/slash/SlashIntegrationOwners.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,47 @@ | ||
package io.github.freya022.botcommands.test.commands.slash | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
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.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.components.Buttons | ||
import io.github.freya022.botcommands.api.core.utils.enumSetOf | ||
import net.dv8tion.jda.api.interactions.IntegrationType | ||
import net.dv8tion.jda.api.interactions.InteractionContextType | ||
|
||
@Command | ||
class SlashIntegrationOwners(private val buttons: Buttons) : GlobalApplicationCommandProvider, GuildApplicationCommandProvider { | ||
suspend fun run(event: GlobalSlashEvent) { | ||
val button = buttons.primary("click me").ephemeral { | ||
bindTo { it.deferEdit().await() } | ||
} | ||
event.replyComponents(button.into()).setEphemeral(true).await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.slashCommand("global_owners", ::run) { | ||
integrationTypes = IntegrationType.ALL | ||
contexts = InteractionContextType.ALL | ||
} | ||
|
||
manager.slashCommand("global_owners_only_user", ::run) { | ||
integrationTypes = enumSetOf(IntegrationType.USER_INSTALL) | ||
contexts = InteractionContextType.ALL | ||
} | ||
|
||
manager.slashCommand("global_owners_only_guild", ::run) { | ||
integrationTypes = enumSetOf(IntegrationType.GUILD_INSTALL) | ||
contexts = InteractionContextType.ALL | ||
} | ||
} | ||
|
||
override fun declareGuildApplicationCommands(manager: GuildApplicationCommandManager) { | ||
manager.slashCommand("guild_owners", ::run) { | ||
|
||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
src/test/kotlin/io/github/freya022/botcommands/test/commands/user/UserContextTest.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,41 @@ | ||
package io.github.freya022.botcommands.test.commands.user | ||
|
||
import dev.minn.jda.ktx.coroutines.await | ||
import dev.minn.jda.ktx.messages.reply_ | ||
import io.github.freya022.botcommands.api.commands.annotations.Command | ||
import io.github.freya022.botcommands.api.commands.application.ApplicationCommand | ||
import io.github.freya022.botcommands.api.commands.application.context.annotations.JDAUserCommand | ||
import io.github.freya022.botcommands.api.commands.application.context.user.GlobalUserEvent | ||
import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandManager | ||
import io.github.freya022.botcommands.api.commands.application.provider.GlobalApplicationCommandProvider | ||
import net.dv8tion.jda.api.entities.Message | ||
import net.dv8tion.jda.api.interactions.IntegrationType | ||
import net.dv8tion.jda.api.interactions.IntegrationType.GUILD_INSTALL | ||
import net.dv8tion.jda.api.interactions.IntegrationType.USER_INSTALL | ||
import net.dv8tion.jda.api.interactions.InteractionContextType | ||
import net.dv8tion.jda.api.interactions.InteractionContextType.* | ||
|
||
@Command | ||
class UserContextTest : ApplicationCommand(), GlobalApplicationCommandProvider { | ||
@JDAUserCommand( | ||
name = "test user (annotated)", | ||
contexts = [GUILD, BOT_DM, PRIVATE_CHANNEL], | ||
integrationTypes = [GUILD_INSTALL, USER_INSTALL] | ||
) | ||
suspend fun onUserContextTest(event: GlobalUserEvent) { | ||
event.reply_("Reply", ephemeral = true).await() | ||
|
||
println() | ||
|
||
event.hook.editOriginal("test") | ||
.flatMap(Message::delete) | ||
.await() | ||
} | ||
|
||
override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) { | ||
manager.userCommand("test user", ::onUserContextTest) { | ||
contexts = InteractionContextType.ALL | ||
integrationTypes = IntegrationType.ALL | ||
} | ||
} | ||
} |