This commit is contained in:
@@ -9,7 +9,8 @@ import wtf.beatrice.hidekobot.objects.MessageResponse;
|
||||
public class ProfileImage
|
||||
{
|
||||
|
||||
private ProfileImage() {
|
||||
private ProfileImage()
|
||||
{
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@@ -20,9 +21,11 @@ public class ProfileImage
|
||||
// method to find closest value to accepted values
|
||||
int distance = Math.abs(acceptedSizes[0] - resolution);
|
||||
int idx = 0;
|
||||
for(int c = 1; c < acceptedSizes.length; c++){
|
||||
for (int c = 1; c < acceptedSizes.length; c++)
|
||||
{
|
||||
int cdistance = Math.abs(acceptedSizes[c] - resolution);
|
||||
if(cdistance < distance){
|
||||
if (cdistance < distance)
|
||||
{
|
||||
idx = c;
|
||||
distance = cdistance;
|
||||
}
|
||||
@@ -40,14 +43,15 @@ public class ProfileImage
|
||||
User.Profile userProfile = user.retrieveProfile().complete();
|
||||
ImageProxy bannerProxy = userProfile.getBanner();
|
||||
|
||||
if(imageType == ImageType.AVATAR)
|
||||
if (imageType == ImageType.AVATAR)
|
||||
{
|
||||
resolutionString = resolution + " × " + resolution;
|
||||
imageLink = user.getEffectiveAvatar().getUrl(resolution);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
int verticalRes = 361 * resolution / 1024;
|
||||
resolutionString = resolution + " × " + verticalRes;
|
||||
if(bannerProxy != null)
|
||||
if (bannerProxy != null)
|
||||
imageLink = bannerProxy.getUrl(resolution);
|
||||
}
|
||||
|
||||
@@ -64,21 +68,22 @@ public class ProfileImage
|
||||
|
||||
// string builder to create a string that links to all available resolutions
|
||||
StringBuilder links = new StringBuilder();
|
||||
for(int pos = 0; pos < acceptedSizes.length; pos++)
|
||||
for (int pos = 0; pos < acceptedSizes.length; pos++)
|
||||
{
|
||||
int currSize = acceptedSizes[pos];
|
||||
|
||||
String currLink;
|
||||
if(imageType == ImageType.AVATAR)
|
||||
if (imageType == ImageType.AVATAR)
|
||||
{
|
||||
currLink = user.getEffectiveAvatar().getUrl(currSize);
|
||||
} else {
|
||||
if(bannerProxy == null) break;
|
||||
} else
|
||||
{
|
||||
if (bannerProxy == null) break;
|
||||
currLink = bannerProxy.getUrl(currSize);
|
||||
}
|
||||
|
||||
links.append("**[").append(currSize).append("px](").append(currLink).append(")**");
|
||||
if(pos + 1 != acceptedSizes.length) // don't add a separator on the last iteration
|
||||
if (pos + 1 != acceptedSizes.length) // don't add a separator on the last iteration
|
||||
{
|
||||
links.append(" | ");
|
||||
}
|
||||
@@ -87,15 +92,16 @@ public class ProfileImage
|
||||
embedBuilder.addField("Available resolutions", links.toString(), false);
|
||||
|
||||
|
||||
|
||||
if(imageLink != null)
|
||||
if (imageLink != null)
|
||||
embedBuilder.setImage(imageLink);
|
||||
|
||||
|
||||
if(imageLink == null) {
|
||||
if (imageLink == null)
|
||||
{
|
||||
String error = "I couldn't find " + user.getAsMention() + "'s " + imageTypeName + "!";
|
||||
return new MessageResponse(error, null);
|
||||
} else {
|
||||
} else
|
||||
{
|
||||
return new MessageResponse(null, embedBuilder.build());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user