Skip to content

Commit

Permalink
Fix test warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed May 18, 2024
1 parent cb09a2a commit 6cebb95
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,56 @@ 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
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() }
}
event.replyComponents(button.into()).setEphemeral(true).await()
}

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) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -48,6 +49,8 @@ class UserContextInfo : ApplicationCommand(), GlobalApplicationCommandProvider {

override fun declareGlobalApplicationCommands(manager: GlobalApplicationCommandManager) {
manager.userCommand("User info", ::onUserContextInfo) {
contexts = ALL

option("user")

generatedOption("userTag") {
Expand Down

0 comments on commit 6cebb95

Please sign in to comment.