Implement profile banner grabber command
This commit is contained in:
@@ -2,14 +2,14 @@ package wtf.beatrice.hidekobot.commands.message;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Mentions;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import wtf.beatrice.hidekobot.Cache;
|
||||
import wtf.beatrice.hidekobot.HidekoBot;
|
||||
import wtf.beatrice.hidekobot.commands.base.Avatar;
|
||||
import wtf.beatrice.hidekobot.commands.base.ProfileImage;
|
||||
import wtf.beatrice.hidekobot.objects.MessageResponse;
|
||||
import wtf.beatrice.hidekobot.objects.commands.CommandCategory;
|
||||
import wtf.beatrice.hidekobot.objects.commands.MessageCommand;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class AvatarCommand implements MessageCommand
|
||||
for (String arg : args) {
|
||||
try {
|
||||
int givenRes = Integer.parseInt(arg);
|
||||
resolution = Avatar.parseResolution(givenRes);
|
||||
resolution = ProfileImage.parseResolution(givenRes);
|
||||
resFound = true;
|
||||
break;
|
||||
} catch (NumberFormatException ignored) {
|
||||
@@ -77,7 +77,7 @@ public class AvatarCommand implements MessageCommand
|
||||
}
|
||||
|
||||
// fallback in case we didn't find any specified resolution
|
||||
if(!resFound) resolution = Avatar.parseResolution(512);
|
||||
if(!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
|
||||
// check if someone is mentioned
|
||||
Mentions mentions = event.getMessage().getMentions();
|
||||
@@ -94,7 +94,13 @@ public class AvatarCommand implements MessageCommand
|
||||
if(user == null) user = event.getAuthor();
|
||||
|
||||
// send a response
|
||||
MessageEmbed embed = Avatar.buildEmbed(resolution, user);
|
||||
event.getMessage().replyEmbeds(embed).queue();
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.AVATAR);
|
||||
if(response.content() != null)
|
||||
{
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
{
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,103 @@
|
||||
package wtf.beatrice.hidekobot.commands.message;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Mentions;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import wtf.beatrice.hidekobot.HidekoBot;
|
||||
import wtf.beatrice.hidekobot.commands.base.ProfileImage;
|
||||
import wtf.beatrice.hidekobot.objects.MessageResponse;
|
||||
import wtf.beatrice.hidekobot.objects.commands.CommandCategory;
|
||||
import wtf.beatrice.hidekobot.objects.commands.MessageCommand;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class BannerCommand implements MessageCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getCommandLabels() {
|
||||
return new LinkedList<>(Collections.singletonList("banner"));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<Permission> getPermissions() {
|
||||
return null; // anyone can use it
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean passRawArgs() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Get someone's profile banner, or your own.";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "[mentioned user] [resolution]";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CommandCategory getCategory() {
|
||||
return CommandCategory.TOOLS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
User user;
|
||||
int resolution = -1;
|
||||
|
||||
// we have no specific order for user and resolution, so let's try parsing any arg as resolution
|
||||
// (mentions are handled differently by a specific method)
|
||||
boolean resFound = false;
|
||||
|
||||
for (String arg : args) {
|
||||
try {
|
||||
int givenRes = Integer.parseInt(arg);
|
||||
resolution = ProfileImage.parseResolution(givenRes);
|
||||
resFound = true;
|
||||
break;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// fallback in case we didn't find any specified resolution
|
||||
if(!resFound) resolution = ProfileImage.parseResolution(512);
|
||||
|
||||
// check if someone is mentioned
|
||||
Mentions mentions = event.getMessage().getMentions();
|
||||
if(mentions.getMentions().isEmpty())
|
||||
{
|
||||
user = event.getAuthor();
|
||||
} else
|
||||
{
|
||||
String mentionedId = mentions.getMentions().get(0).getId();
|
||||
user = HidekoBot.getAPI().retrieveUserById(mentionedId).complete();
|
||||
}
|
||||
|
||||
// in case of issues, fallback to the sender
|
||||
if(user == null) user = event.getAuthor();
|
||||
|
||||
// send a response
|
||||
MessageResponse response = ProfileImage.buildResponse(resolution, user, ProfileImage.ImageType.BANNER);
|
||||
if(response.content() != null)
|
||||
{
|
||||
event.getMessage().reply(response.content()).queue();
|
||||
} else if(response.embed() != null)
|
||||
{
|
||||
event.getMessage().replyEmbeds(response.embed()).queue();
|
||||
}
|
||||
}
|
||||
}
|
@@ -48,8 +48,8 @@ public class HelloCommand implements MessageCommand
|
||||
@Override
|
||||
public void runCommand(MessageReceivedEvent event, String label, String[] args)
|
||||
{
|
||||
String senderId = event.getMessage().getAuthor().getId();
|
||||
event.getMessage().reply("Hi, <@" + senderId + ">! :sparkles:").queue();
|
||||
String sender = event.getMessage().getAuthor().getAsMention();
|
||||
event.getMessage().reply("Hi, " + sender + "! :sparkles:").queue();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user