Skip to content

Commit

Permalink
[Feature] Create User#getAsTag (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 authored and MinnDevelopment committed Jan 2, 2019
1 parent 15ac863 commit 2f53afb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/main/java/net/dv8tion/jda/core/entities/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ public interface User extends ISnowflake, IMentionable, IFakeable
*/
String getEffectiveAvatarUrl();

/**
* The "tag" for this user
* <p>This is the equivalent of calling {@link java.lang.String#format(String, Object...) String.format}("%#s", {@link net.dv8tion.jda.core.entities.User User})
*
* @return Never-null String containing the tag for this user, for example DV8FromTheWorld#6297
*/
String getAsTag();

/**
* Whether or not the currently logged in user and this user have a currently open
* {@link net.dv8tion.jda.core.entities.PrivateChannel PrivateChannel} or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public String getEffectiveAvatarUrl()
return getAvatarUrl() == null ? getDefaultAvatarUrl() : getAvatarUrl();
}

@Override
public String getAsTag()
{
return getName() + '#' + getDiscriminator();
}

@Override
public boolean hasPrivateChannel()
Expand Down Expand Up @@ -243,9 +248,9 @@ public void formatTo(Formatter formatter, int flags, int width, int precision)
if (!alt)
out = getAsMention();
else if (upper)
out = String.format(formatter.locale(), "%S#%s", getName(), getDiscriminator());
out = getAsTag().toUpperCase();
else
out = String.format(formatter.locale(), "%s#%s", getName(), getDiscriminator());
out = getAsTag();

MiscUtil.appendTo(formatter, width, precision, leftJustified, out);
}
Expand Down

0 comments on commit 2f53afb

Please sign in to comment.