293 lines
11 KiB
Java
293 lines
11 KiB
Java
|
package com.discord.utilities.user;
|
||
|
|
||
|
import android.text.SpannableString;
|
||
|
import android.text.style.ForegroundColorSpan;
|
||
|
import android.text.style.RelativeSizeSpan;
|
||
|
import androidx.annotation.ColorInt;
|
||
|
import c.d.b.a.a;
|
||
|
import com.adjust.sdk.Constants;
|
||
|
import com.discord.api.premium.PremiumTier;
|
||
|
import com.discord.api.utcdatetime.UtcDateTime;
|
||
|
import com.discord.models.user.CoreUser;
|
||
|
import com.discord.models.user.MeUser;
|
||
|
import com.discord.models.user.User;
|
||
|
import com.discord.nullserializable.NullSerializable;
|
||
|
import com.discord.utilities.SnowflakeUtils;
|
||
|
import com.discord.utilities.time.Clock;
|
||
|
import com.discord.utilities.time.ClockFactory;
|
||
|
import d0.g0.c;
|
||
|
import d0.g0.t;
|
||
|
import d0.z.d.m;
|
||
|
import java.nio.charset.Charset;
|
||
|
import java.security.MessageDigest;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Objects;
|
||
|
/* compiled from: UserUtils.kt */
|
||
|
public final class UserUtils {
|
||
|
public static final long CLYDE_BOT_USER_ID = -1;
|
||
|
private static final User EMPTY_USER = new CoreUser(0, "Empty User", null, null, false, false, 1, PremiumTier.PREMIUM_GUILD_SUBSCRIPTION_ONLY, 0, 0, null, null, 3900, null);
|
||
|
private static final int GUILD_VERIFICATION_ACCOUNT_AGE_THRESHOLD = 300000;
|
||
|
public static final UserUtils INSTANCE = new UserUtils();
|
||
|
private static final int NEW_USER_THRESHOLD = 604800000;
|
||
|
public static final long SYSTEM_USER_ID = 643945264868098049L;
|
||
|
|
||
|
private UserUtils() {
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ long getAgeMs$default(UserUtils userUtils, User user, Clock clock, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
clock = ClockFactory.get();
|
||
|
}
|
||
|
return userUtils.getAgeMs(user, clock);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ CharSequence getUserNameWithDiscriminator$default(UserUtils userUtils, User user, Integer num, Float f, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
num = null;
|
||
|
}
|
||
|
if ((i & 2) != 0) {
|
||
|
f = null;
|
||
|
}
|
||
|
return userUtils.getUserNameWithDiscriminator(user, num, f);
|
||
|
}
|
||
|
|
||
|
private final boolean hasFlag(User user, int i) {
|
||
|
return ((user.getPublicFlags() | user.getFlags()) & i) == i;
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ boolean isAccountOldEnough$default(UserUtils userUtils, User user, Clock clock, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
clock = ClockFactory.get();
|
||
|
}
|
||
|
return userUtils.isAccountOldEnough(user, clock);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ boolean isNewUser$default(UserUtils userUtils, User user, Clock clock, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
clock = ClockFactory.get();
|
||
|
}
|
||
|
return userUtils.isNewUser(user, clock);
|
||
|
}
|
||
|
|
||
|
public static /* synthetic */ boolean since$default(UserUtils userUtils, User user, Clock clock, UtcDateTime utcDateTime, int i, Object obj) {
|
||
|
if ((i & 1) != 0) {
|
||
|
clock = ClockFactory.get();
|
||
|
}
|
||
|
return userUtils.since(user, clock, utcDateTime);
|
||
|
}
|
||
|
|
||
|
public final int compareUserNames(User user, User user2) {
|
||
|
return compareUserNames(user, user2, null, null);
|
||
|
}
|
||
|
|
||
|
public final int compareUserNames(User user, User user2, String str, String str2) {
|
||
|
String str3 = null;
|
||
|
String username = user != null ? user.getUsername() : null;
|
||
|
if (user2 != null) {
|
||
|
str3 = user2.getUsername();
|
||
|
}
|
||
|
return compareUserNames(username, str3, str, str2, user != null ? user.getId() : 0, user2 != null ? user2.getId() : 0);
|
||
|
}
|
||
|
|
||
|
public final int compareUserNames(String str, String str2, String str3, String str4, long j, long j2) {
|
||
|
boolean z2 = false;
|
||
|
if (str == null) {
|
||
|
return str2 == null ? 0 : -1;
|
||
|
}
|
||
|
if (str2 == null) {
|
||
|
return 1;
|
||
|
}
|
||
|
if (!(str3 == null || t.isBlank(str3))) {
|
||
|
str = str3;
|
||
|
}
|
||
|
if (str4 == null || t.isBlank(str4)) {
|
||
|
z2 = true;
|
||
|
}
|
||
|
if (!z2) {
|
||
|
str2 = str4;
|
||
|
}
|
||
|
int compareTo = t.compareTo(str, str2, true);
|
||
|
return compareTo != 0 ? compareTo : (j > j2 ? 1 : (j == j2 ? 0 : -1));
|
||
|
}
|
||
|
|
||
|
public final long getAgeMs(User user, Clock clock) {
|
||
|
m.checkNotNullParameter(user, "$this$getAgeMs");
|
||
|
m.checkNotNullParameter(clock, "clock");
|
||
|
return clock.currentTimeMillis() - ((user.getId() >>> 22) + SnowflakeUtils.DISCORD_EPOCH);
|
||
|
}
|
||
|
|
||
|
public final String getDiscriminatorWithPadding(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$discriminatorWithPadding");
|
||
|
return padDiscriminator(user.getDiscriminator());
|
||
|
}
|
||
|
|
||
|
public final User getEMPTY_USER() {
|
||
|
return EMPTY_USER;
|
||
|
}
|
||
|
|
||
|
public final boolean getHasPhone(MeUser meUser) {
|
||
|
m.checkNotNullParameter(meUser, "$this$hasPhone");
|
||
|
return meUser.getPhoneNumber() != null;
|
||
|
}
|
||
|
|
||
|
public final boolean getHasSubscription(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$hasSubscription");
|
||
|
return user.getPremiumTier() != PremiumTier.NONE;
|
||
|
}
|
||
|
|
||
|
public final boolean getHasUnreadUrgentMessages(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$hasUnreadUrgentMessages");
|
||
|
return hasFlag(user, 8192);
|
||
|
}
|
||
|
|
||
|
public final String getObfuscatedUserId(Long l) {
|
||
|
if (l == null) {
|
||
|
return null;
|
||
|
}
|
||
|
MessageDigest instance = MessageDigest.getInstance(Constants.SHA256);
|
||
|
String valueOf = String.valueOf(l.longValue());
|
||
|
Charset charset = c.a;
|
||
|
Objects.requireNonNull(valueOf, "null cannot be cast to non-null type java.lang.String");
|
||
|
byte[] bytes = valueOf.getBytes(charset);
|
||
|
m.checkNotNullExpressionValue(bytes, "(this as java.lang.String).getBytes(charset)");
|
||
|
byte[] digest = instance.digest(bytes);
|
||
|
m.checkNotNullExpressionValue(digest, "MessageDigest\n .g…toString().toByteArray())");
|
||
|
String str = "";
|
||
|
for (byte b : digest) {
|
||
|
StringBuilder K = a.K(str);
|
||
|
String format = String.format("%02x", Arrays.copyOf(new Object[]{Byte.valueOf(b)}, 1));
|
||
|
m.checkNotNullExpressionValue(format, "java.lang.String.format(this, *args)");
|
||
|
K.append(format);
|
||
|
str = K.toString();
|
||
|
}
|
||
|
return str;
|
||
|
}
|
||
|
|
||
|
public final CharSequence getUserNameWithDiscriminator(User user, @ColorInt Integer num, Float f) {
|
||
|
m.checkNotNullParameter(user, "$this$getUserNameWithDiscriminator");
|
||
|
String str = user.getUsername() + getDiscriminatorWithPadding(user);
|
||
|
if (num == null && f == null) {
|
||
|
return str;
|
||
|
}
|
||
|
SpannableString spannableString = new SpannableString(str);
|
||
|
if (num != null) {
|
||
|
spannableString.setSpan(new ForegroundColorSpan(num.intValue()), user.getUsername().length(), spannableString.length(), 17);
|
||
|
}
|
||
|
if (f != null) {
|
||
|
spannableString.setSpan(new RelativeSizeSpan(f.floatValue()), user.getUsername().length(), spannableString.length(), 17);
|
||
|
}
|
||
|
return spannableString;
|
||
|
}
|
||
|
|
||
|
public final boolean isAccountOldEnough(User user, Clock clock) {
|
||
|
m.checkNotNullParameter(user, "$this$isAccountOldEnough");
|
||
|
m.checkNotNullParameter(clock, "clock");
|
||
|
return getAgeMs(user, clock) > ((long) GUILD_VERIFICATION_ACCOUNT_AGE_THRESHOLD);
|
||
|
}
|
||
|
|
||
|
public final boolean isBugHunterLevel1(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isBugHunterLevel1");
|
||
|
return hasFlag(user, 8);
|
||
|
}
|
||
|
|
||
|
public final boolean isBugHunterLevel2(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isBugHunterLevel2");
|
||
|
return hasFlag(user, 16384);
|
||
|
}
|
||
|
|
||
|
public final boolean isCertifiedModerator(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isCertifiedModerator");
|
||
|
return hasFlag(user, 262144);
|
||
|
}
|
||
|
|
||
|
public final boolean isHypeSquad(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isHypeSquad");
|
||
|
return hasFlag(user, 4);
|
||
|
}
|
||
|
|
||
|
public final boolean isHypesquadHouse1(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isHypesquadHouse1");
|
||
|
return hasFlag(user, 64);
|
||
|
}
|
||
|
|
||
|
public final boolean isHypesquadHouse2(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isHypesquadHouse2");
|
||
|
return hasFlag(user, 128);
|
||
|
}
|
||
|
|
||
|
public final boolean isHypesquadHouse3(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isHypesquadHouse3");
|
||
|
return hasFlag(user, 256);
|
||
|
}
|
||
|
|
||
|
public final boolean isInHypesquadHouse(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isInHypesquadHouse");
|
||
|
return isHypesquadHouse1(user) || isHypesquadHouse2(user) || isHypesquadHouse3(user);
|
||
|
}
|
||
|
|
||
|
public final boolean isMfaSMSEnabled(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isMfaSMSEnabled");
|
||
|
return hasFlag(user, 16);
|
||
|
}
|
||
|
|
||
|
public final boolean isNewUser(User user, Clock clock) {
|
||
|
m.checkNotNullParameter(user, "$this$isNewUser");
|
||
|
m.checkNotNullParameter(clock, "clock");
|
||
|
return (user.getId() >>> 22) + SnowflakeUtils.DISCORD_EPOCH >= clock.currentTimeMillis() - ((long) NEW_USER_THRESHOLD);
|
||
|
}
|
||
|
|
||
|
public final boolean isPartner(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isPartner");
|
||
|
return hasFlag(user, 2);
|
||
|
}
|
||
|
|
||
|
public final boolean isPremium(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isPremium");
|
||
|
return (user.getPremiumTier() == PremiumTier.PREMIUM_GUILD_SUBSCRIPTION_ONLY || user.getPremiumTier() == PremiumTier.NONE) ? false : true;
|
||
|
}
|
||
|
|
||
|
public final boolean isPremiumEarlySupporter(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isPremiumEarlySupporter");
|
||
|
return hasFlag(user, 512);
|
||
|
}
|
||
|
|
||
|
public final boolean isPremiumTier2(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isPremiumTier2");
|
||
|
return user.getPremiumTier() == PremiumTier.TIER_2;
|
||
|
}
|
||
|
|
||
|
public final boolean isStaff(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isStaff");
|
||
|
return hasFlag(user, 1);
|
||
|
}
|
||
|
|
||
|
public final boolean isVerifiedBot(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isVerifiedBot");
|
||
|
return hasFlag(user, 65536) || user.isSystemUser() || user.getId() == -1;
|
||
|
}
|
||
|
|
||
|
public final boolean isVerifiedDeveloper(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$isVerifiedDeveloper");
|
||
|
return hasFlag(user, 131072);
|
||
|
}
|
||
|
|
||
|
public final String padDiscriminator(int i) {
|
||
|
return a.G(new Object[]{Integer.valueOf(i)}, 1, "#%04d", "java.lang.String.format(format, *args)");
|
||
|
}
|
||
|
|
||
|
public final boolean since(User user, Clock clock, UtcDateTime utcDateTime) {
|
||
|
m.checkNotNullParameter(user, "$this$since");
|
||
|
m.checkNotNullParameter(clock, "clock");
|
||
|
m.checkNotNullParameter(utcDateTime, "date");
|
||
|
return new UtcDateTime((user.getId() >>> 22) + SnowflakeUtils.DISCORD_EPOCH).compareTo(utcDateTime) <= 0;
|
||
|
}
|
||
|
|
||
|
public final com.discord.api.user.User synthesizeApiUser(User user) {
|
||
|
m.checkNotNullParameter(user, "$this$synthesizeApiUser");
|
||
|
long id2 = user.getId();
|
||
|
String username = user.getUsername();
|
||
|
String avatar = user.getAvatar();
|
||
|
return new com.discord.api.user.User(id2, username, avatar != null ? new NullSerializable.b(avatar) : new NullSerializable.a(null, 1), null, String.valueOf(user.getDiscriminator()), Integer.valueOf(user.getPublicFlags()), Integer.valueOf(user.getFlags()), Boolean.valueOf(user.isBot()), Boolean.valueOf(user.isSystemUser()), null, null, null, null, null, null, null, null, null, null, null, null, null, 3145736);
|
||
|
}
|
||
|
}
|