Add subcommands

java-rewrite
Hammy 3 years ago
parent 672a6c14f2
commit 418507de4e

@ -1,12 +1,69 @@
package me.goudham.bot.command.info.avatar; package me.goudham.bot.command.info.avatar;
import io.micronaut.context.annotation.Executable;
import jakarta.inject.Inject;
import me.goudham.command.annotation.Option;
import me.goudham.command.annotation.SlashCommand; import me.goudham.command.annotation.SlashCommand;
import me.goudham.command.annotation.SubCommand;
import me.goudham.service.EmbedService;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
import net.dv8tion.jda.api.interactions.InteractionHook;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
@SlashCommand( @SlashCommand(name = "avatar", description = "Display your avatar", isVisible = true, subCommandGroups = { "cool" })
name = "avatar",
description = "Display your avatar",
isVisible = true,
subCommands = { "default", "greyscale" }
)
public class Avatar { public class Avatar {
private final EmbedService embedService;
@Inject
public Avatar(EmbedService embedService) {
this.embedService = embedService;
}
@Executable
@SubCommand(
name = "grayscale",
description = "Display your or another member's avatar with a grayscale filter applied",
options = {
@Option(
optionType = OptionType.USER,
name = "member",
description = "A member within the server",
isRequired = false
)
}
)
public void grayscaleCommand(SlashCommandEvent slashCommandEvent) {
}
@Executable
@SubCommand(
name = "default",
description = "Display your or another member's avatar",
options = {
@Option(
optionType = OptionType.USER,
name = "member",
description = "A member within the server",
isRequired = false
)
}
)
public void defaultCommand(SlashCommandEvent slashCommandEvent) {
slashCommandEvent.deferReply(false).queue();
InteractionHook hook = slashCommandEvent.getHook();
OptionMapping optionalUser = slashCommandEvent.getOption("member");
User user = optionalUser == null ? slashCommandEvent.getUser() : optionalUser.getAsUser();
MessageEmbed avatarEmbed = embedService.getBaseEmbed()
.setAuthor(user.getName() + "'s Avatar")
.setImage(user.getEffectiveAvatarUrl() + "?size=4096")
.build();
hook.sendMessageEmbeds(avatarEmbed).queue();
}
} }

Loading…
Cancel
Save