discord-jadx/app/src/main/java/com/discord/stores/StoreApplicationCommandsKt....

172 lines
9.7 KiB
Java

package com.discord.stores;
import android.content.res.Resources;
import androidx.annotation.VisibleForTesting;
import com.discord.api.commands.ApplicationCommandPermission;
import com.discord.api.commands.ApplicationCommandType;
import com.discord.api.commands.CommandChoice;
import com.discord.models.commands.Application;
import com.discord.models.commands.ApplicationCommand;
import com.discord.models.commands.ApplicationCommandOption;
import com.discord.models.commands.ApplicationSubCommand;
import com.discord.models.commands.RemoteApplicationCommand;
import d0.g0.t;
import d0.t.n;
import d0.t.o;
import d0.z.d.m;
import java.util.ArrayList;
import java.util.List;
/* compiled from: StoreApplicationCommands.kt */
public final class StoreApplicationCommandsKt {
private static final ApplicationSubCommand expandSubCommand(ApplicationCommand applicationCommand, ApplicationCommandOption applicationCommandOption) {
String name = applicationCommandOption.getName();
long applicationId = applicationCommand.getApplicationId();
String str = applicationCommand.getName() + " " + applicationCommandOption.getName();
String description = applicationCommandOption.getDescription();
List<ApplicationCommandOption> options = applicationCommandOption.getOptions();
if (options == null) {
options = n.emptyList();
}
return new ApplicationSubCommand(applicationCommand, name, null, applicationId, str, description, null, options, applicationCommand.getGuildId(), null, null, applicationCommand.getVersion(), 1604, null);
}
private static final List<ApplicationCommand> expandSubCommandGroup(ApplicationCommand applicationCommand, ApplicationCommandOption applicationCommandOption) {
ArrayList arrayList = new ArrayList();
List<ApplicationCommandOption> options = applicationCommandOption.getOptions();
if (options != null) {
for (ApplicationCommandOption applicationCommandOption2 : options) {
if (applicationCommandOption2.getType() == ApplicationCommandType.SUBCOMMAND) {
String name = applicationCommandOption2.getName();
String name2 = applicationCommandOption.getName();
long applicationId = applicationCommand.getApplicationId();
String str = applicationCommand.getName() + " " + applicationCommandOption.getName() + " " + applicationCommandOption2.getName();
String description = applicationCommandOption2.getDescription();
List<ApplicationCommandOption> options2 = applicationCommandOption2.getOptions();
if (options2 == null) {
options2 = n.emptyList();
}
arrayList.add(new ApplicationSubCommand(applicationCommand, name, name2, applicationId, str, description, null, options2, applicationCommand.getGuildId(), null, null, applicationCommand.getVersion(), 1600, null));
}
}
}
return arrayList;
}
private static final List<ApplicationCommand> expandSubCommands(ApplicationCommand applicationCommand) {
ArrayList arrayList = new ArrayList();
boolean z2 = false;
for (ApplicationCommandOption applicationCommandOption : applicationCommand.getOptions()) {
if (applicationCommandOption.getType() == ApplicationCommandType.SUBCOMMAND) {
arrayList.add(expandSubCommand(applicationCommand, applicationCommandOption));
} else if (applicationCommandOption.getType() == ApplicationCommandType.SUBCOMMAND_GROUP) {
arrayList.addAll(expandSubCommandGroup(applicationCommand, applicationCommandOption));
}
z2 = true;
}
if (!z2) {
arrayList.add(applicationCommand);
}
return arrayList;
}
@VisibleForTesting
public static final List<ApplicationCommand> flattenSubCommands(List<? extends ApplicationCommand> list) {
m.checkNotNullParameter(list, "$this$flattenSubCommands");
ArrayList arrayList = new ArrayList();
for (ApplicationCommand applicationCommand : list) {
if (applicationCommand instanceof RemoteApplicationCommand) {
arrayList.addAll(expandSubCommands(applicationCommand));
} else {
arrayList.add(applicationCommand);
}
}
return arrayList;
}
public static final String getDescriptionText(ApplicationCommand applicationCommand, Resources resources) {
m.checkNotNullParameter(applicationCommand, "$this$getDescriptionText");
m.checkNotNullParameter(resources, "resources");
Integer descriptionRes = applicationCommand.getDescriptionRes();
if (descriptionRes != null) {
String string = resources.getString(descriptionRes.intValue());
m.checkNotNullExpressionValue(string, "resources.getString(it)");
String replace$default = t.replace$default(string, "¯_(ツ)_/¯", "¯\\_(ツ)_/¯", false, 4, (Object) null);
if (replace$default != null) {
return replace$default;
}
}
return applicationCommand.getDescription();
}
public static final String getDescriptionText(ApplicationCommandOption applicationCommandOption, Resources resources) {
String string;
m.checkNotNullParameter(applicationCommandOption, "$this$getDescriptionText");
m.checkNotNullParameter(resources, "resources");
Integer descriptionRes = applicationCommandOption.getDescriptionRes();
return (descriptionRes == null || (string = resources.getString(descriptionRes.intValue())) == null) ? applicationCommandOption.getDescription() : string;
}
public static final String getErrorText(ApplicationCommandOption applicationCommandOption, Resources resources) {
m.checkNotNullParameter(applicationCommandOption, "$this$getErrorText");
m.checkNotNullParameter(resources, "resources");
if (applicationCommandOption.getType() == ApplicationCommandType.STRING) {
List<CommandChoice> choices = applicationCommandOption.getChoices();
if (!(choices == null || choices.isEmpty())) {
return resources.getString(2131887453);
}
}
return applicationCommandOption.getType() == ApplicationCommandType.INTEGER ? resources.getString(2131887455) : applicationCommandOption.getType() == ApplicationCommandType.BOOLEAN ? resources.getString(2131887451) : applicationCommandOption.getType() == ApplicationCommandType.USER ? resources.getString(2131887459) : applicationCommandOption.getType() == ApplicationCommandType.CHANNEL ? resources.getString(2131887452) : applicationCommandOption.getType() == ApplicationCommandType.ROLE ? resources.getString(2131887458) : applicationCommandOption.getType() == ApplicationCommandType.MENTIONABLE ? resources.getString(2131887456) : resources.getString(2131887457);
}
public static final Application toDomainApplication(com.discord.api.commands.Application application) {
m.checkNotNullParameter(application, "$this$toDomainApplication");
return new Application(application.c(), application.d(), application.b(), null, application.a(), null, false, 104, null);
}
public static final ApplicationCommand toSlashCommand(com.discord.api.commands.ApplicationCommand applicationCommand) {
ArrayList arrayList;
m.checkNotNullParameter(applicationCommand, "$this$toSlashCommand");
String valueOf = String.valueOf(applicationCommand.e());
long a = applicationCommand.a();
String f = applicationCommand.f();
String c2 = applicationCommand.c();
List<com.discord.api.commands.ApplicationCommandOption> g = applicationCommand.g();
if (g != null) {
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(g, 10));
for (com.discord.api.commands.ApplicationCommandOption applicationCommandOption : g) {
arrayList2.add(toSlashCommandOption(applicationCommandOption));
}
arrayList = arrayList2;
} else {
arrayList = n.emptyList();
}
String i = applicationCommand.i();
List<ApplicationCommandPermission> h = applicationCommand.h();
Boolean b = applicationCommand.b();
String d = applicationCommand.d();
return new RemoteApplicationCommand(valueOf, a, f, c2, arrayList, d != null ? Long.valueOf(Long.parseLong(d)) : null, i, b, h, null, 512, null);
}
public static final ApplicationCommandOption toSlashCommandOption(com.discord.api.commands.ApplicationCommandOption applicationCommandOption) {
ArrayList arrayList;
m.checkNotNullParameter(applicationCommandOption, "$this$toSlashCommandOption");
ApplicationCommandType g = applicationCommandOption.g();
String d = applicationCommandOption.d();
String c2 = applicationCommandOption.c();
boolean f = applicationCommandOption.f();
boolean b = applicationCommandOption.b();
List<CommandChoice> a = applicationCommandOption.a();
List<com.discord.api.commands.ApplicationCommandOption> e = applicationCommandOption.e();
if (e != null) {
ArrayList arrayList2 = new ArrayList(o.collectionSizeOrDefault(e, 10));
for (com.discord.api.commands.ApplicationCommandOption applicationCommandOption2 : e) {
arrayList2.add(toSlashCommandOption(applicationCommandOption2));
}
arrayList = arrayList2;
} else {
arrayList = null;
}
return new ApplicationCommandOption(g, d, c2, null, f, b, a, arrayList, 8, null);
}
}