2022-11-20 18:56:57 +01:00
|
|
|
package wtf.beatrice.hidekobot.commands.slash;
|
2022-11-20 17:19:40 +01:00
|
|
|
|
2022-11-20 18:06:07 +01:00
|
|
|
import net.dv8tion.jda.api.EmbedBuilder;
|
2022-12-18 23:47:54 +01:00
|
|
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
2022-11-20 17:19:40 +01:00
|
|
|
import net.dv8tion.jda.api.entities.User;
|
|
|
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
|
|
|
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
2022-11-22 16:39:31 +01:00
|
|
|
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;
|
2022-11-20 17:19:40 +01:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-11-21 20:20:11 +01:00
|
|
|
import wtf.beatrice.hidekobot.Cache;
|
2022-12-18 23:47:54 +01:00
|
|
|
import wtf.beatrice.hidekobot.commands.base.Avatar;
|
2022-11-22 16:41:08 +01:00
|
|
|
import wtf.beatrice.hidekobot.objects.commands.SlashCommandImpl;
|
2022-11-20 17:19:40 +01:00
|
|
|
|
2022-11-22 16:39:31 +01:00
|
|
|
public class AvatarCommand extends SlashCommandImpl
|
2022-11-20 17:19:40 +01:00
|
|
|
{
|
2022-11-22 14:32:22 +01:00
|
|
|
@Override
|
2022-11-22 16:39:31 +01:00
|
|
|
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);
|
2022-11-22 14:32:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-11-20 22:09:58 +01:00
|
|
|
public void runSlashCommand(@NotNull SlashCommandInteractionEvent event)
|
2022-11-20 17:19:40 +01:00
|
|
|
{
|
2022-11-21 12:19:35 +01:00
|
|
|
// defer reply because this might take a moment
|
2022-11-20 17:19:40 +01:00
|
|
|
event.deferReply().queue();
|
|
|
|
|
|
|
|
User user;
|
2022-11-20 18:06:07 +01:00
|
|
|
int resolution;
|
2022-11-20 17:19:40 +01:00
|
|
|
|
|
|
|
OptionMapping userArg = event.getOption("user");
|
|
|
|
if(userArg != null)
|
|
|
|
{
|
|
|
|
user = userArg.getAsUser();
|
|
|
|
} else {
|
|
|
|
user = event.getUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionMapping sizeArg = event.getOption("size");
|
|
|
|
if(sizeArg != null)
|
|
|
|
{
|
2022-12-18 23:47:54 +01:00
|
|
|
resolution = Avatar.parseResolution(sizeArg.getAsInt());
|
2022-11-20 17:19:40 +01:00
|
|
|
} else {
|
2022-12-18 23:47:54 +01:00
|
|
|
resolution = Avatar.parseResolution(512);
|
2022-11-20 17:19:40 +01:00
|
|
|
}
|
|
|
|
|
2022-12-18 23:47:54 +01:00
|
|
|
MessageEmbed embed = Avatar.buildEmbed(resolution, user);
|
|
|
|
event.getHook().editOriginalEmbeds(embed).queue();
|
2022-11-20 17:19:40 +01:00
|
|
|
}
|
|
|
|
}
|