HidekoBot/src/main/java/wtf/beatrice/hidekobot/commands/slash/AvatarCommand.java
Lorenzo DellacĂ  1447f8c177
All checks were successful
continuous-integration/drone/push Build is passing
Make avatar support both slash and message commands
2022-12-18 23:47:54 +01:00

56 lines
1.9 KiB
Java

package wtf.beatrice.hidekobot.commands.slash;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.Cache;
import wtf.beatrice.hidekobot.commands.base.Avatar;
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
public class AvatarCommand extends SlashCommandImpl
{
@Override
public CommandData getSlashCommandData() {
return Commands.slash("avatar", "Get someone's profile picture.")
.addOption(OptionType.USER, "user", "User you want to grab the avatar of.")
.addOption(OptionType.INTEGER, "size", "The size of the returned image.",
false,
true);
}
@Override
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
{
// defer reply because this might take a moment
event.deferReply().queue();
User user;
int resolution;
OptionMapping userArg = event.getOption("user");
if(userArg != null)
{
user = userArg.getAsUser();
} else {
user = event.getUser();
}
OptionMapping sizeArg = event.getOption("size");
if(sizeArg != null)
{
resolution = Avatar.parseResolution(sizeArg.getAsInt());
} else {
resolution = Avatar.parseResolution(512);
}
MessageEmbed embed = Avatar.buildEmbed(resolution, user);
event.getHook().editOriginalEmbeds(embed).queue();
}
}