853 lines
42 KiB
Java
853 lines
42 KiB
Java
package com.discord.widgets.chat.input.autocomplete.commands;
|
|
|
|
import androidx.annotation.MainThread;
|
|
import androidx.annotation.VisibleForTesting;
|
|
import c.d.b.a.a;
|
|
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.ApplicationCommandKt;
|
|
import com.discord.models.commands.ApplicationCommandOption;
|
|
import com.discord.stores.StoreApplicationCommandsKt;
|
|
import com.discord.utilities.SnowflakeUtils;
|
|
import com.discord.widgets.chat.input.MentionUtilsKt;
|
|
import com.discord.widgets.chat.input.autocomplete.Autocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.AutocompleteModelUtils;
|
|
import com.discord.widgets.chat.input.autocomplete.ChannelAutocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.InputEditTextAction;
|
|
import com.discord.widgets.chat.input.autocomplete.LeadingIdentifier;
|
|
import com.discord.widgets.chat.input.autocomplete.RoleAutocompletable;
|
|
import com.discord.widgets.chat.input.autocomplete.UserAutocompletable;
|
|
import com.discord.widgets.chat.input.models.AutocompleteApplicationCommands;
|
|
import com.discord.widgets.chat.input.models.BooleanOptionValue;
|
|
import com.discord.widgets.chat.input.models.ChannelOptionValue;
|
|
import com.discord.widgets.chat.input.models.ChatInputMentionsMap;
|
|
import com.discord.widgets.chat.input.models.CommandOptionValue;
|
|
import com.discord.widgets.chat.input.models.InputCommandContext;
|
|
import com.discord.widgets.chat.input.models.IntegerOptionValue;
|
|
import com.discord.widgets.chat.input.models.MentionInputModel;
|
|
import com.discord.widgets.chat.input.models.NumberOptionValue;
|
|
import com.discord.widgets.chat.input.models.OptionRange;
|
|
import com.discord.widgets.chat.input.models.RawOptionValue;
|
|
import com.discord.widgets.chat.input.models.RoleOptionValue;
|
|
import com.discord.widgets.chat.input.models.SnowflakeOptionValue;
|
|
import com.discord.widgets.chat.input.models.StringOptionValue;
|
|
import com.discord.widgets.chat.input.models.UserOptionValue;
|
|
import d0.g0.e;
|
|
import d0.g0.s;
|
|
import d0.g0.t;
|
|
import d0.g0.w;
|
|
import d0.t.n0;
|
|
import d0.t.u;
|
|
import d0.z.d.m;
|
|
import java.text.NumberFormat;
|
|
import java.text.ParseException;
|
|
import java.text.ParsePosition;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Set;
|
|
import kotlin.NoWhenBranchMatchedException;
|
|
import kotlin.ranges.IntRange;
|
|
import kotlin.text.MatchResult;
|
|
import kotlin.text.Regex;
|
|
/* compiled from: AutocompleteCommandUtils.kt */
|
|
public final class AutocompleteCommandUtils {
|
|
public static final AutocompleteCommandUtils INSTANCE = new AutocompleteCommandUtils();
|
|
|
|
public final /* synthetic */ class WhenMappings {
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$0;
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$1;
|
|
public static final /* synthetic */ int[] $EnumSwitchMapping$2;
|
|
|
|
static {
|
|
ApplicationCommandType.values();
|
|
int[] iArr = new int[11];
|
|
$EnumSwitchMapping$0 = iArr;
|
|
ApplicationCommandType applicationCommandType = ApplicationCommandType.USER;
|
|
iArr[applicationCommandType.ordinal()] = 1;
|
|
ApplicationCommandType applicationCommandType2 = ApplicationCommandType.CHANNEL;
|
|
iArr[applicationCommandType2.ordinal()] = 2;
|
|
ApplicationCommandType applicationCommandType3 = ApplicationCommandType.ROLE;
|
|
iArr[applicationCommandType3.ordinal()] = 3;
|
|
ApplicationCommandType applicationCommandType4 = ApplicationCommandType.MENTIONABLE;
|
|
iArr[applicationCommandType4.ordinal()] = 4;
|
|
ApplicationCommandType.values();
|
|
int[] iArr2 = new int[11];
|
|
$EnumSwitchMapping$1 = iArr2;
|
|
iArr2[ApplicationCommandType.SUBCOMMAND.ordinal()] = 1;
|
|
iArr2[ApplicationCommandType.SUBCOMMAND_GROUP.ordinal()] = 2;
|
|
ApplicationCommandType applicationCommandType5 = ApplicationCommandType.STRING;
|
|
iArr2[applicationCommandType5.ordinal()] = 3;
|
|
ApplicationCommandType applicationCommandType6 = ApplicationCommandType.INTEGER;
|
|
iArr2[applicationCommandType6.ordinal()] = 4;
|
|
ApplicationCommandType applicationCommandType7 = ApplicationCommandType.NUMBER;
|
|
iArr2[applicationCommandType7.ordinal()] = 5;
|
|
ApplicationCommandType applicationCommandType8 = ApplicationCommandType.BOOLEAN;
|
|
iArr2[applicationCommandType8.ordinal()] = 6;
|
|
iArr2[applicationCommandType.ordinal()] = 7;
|
|
iArr2[applicationCommandType2.ordinal()] = 8;
|
|
iArr2[applicationCommandType3.ordinal()] = 9;
|
|
iArr2[applicationCommandType4.ordinal()] = 10;
|
|
iArr2[ApplicationCommandType.UNKNOWN.ordinal()] = 11;
|
|
ApplicationCommandType.values();
|
|
int[] iArr3 = new int[11];
|
|
$EnumSwitchMapping$2 = iArr3;
|
|
iArr3[applicationCommandType5.ordinal()] = 1;
|
|
iArr3[applicationCommandType6.ordinal()] = 2;
|
|
iArr3[applicationCommandType7.ordinal()] = 3;
|
|
iArr3[applicationCommandType8.ordinal()] = 4;
|
|
iArr3[applicationCommandType.ordinal()] = 5;
|
|
iArr3[applicationCommandType2.ordinal()] = 6;
|
|
iArr3[applicationCommandType3.ordinal()] = 7;
|
|
iArr3[applicationCommandType4.ordinal()] = 8;
|
|
}
|
|
}
|
|
|
|
private AutocompleteCommandUtils() {
|
|
}
|
|
|
|
public static /* synthetic */ InputEditTextAction.InsertText appendParam$default(AutocompleteCommandUtils autocompleteCommandUtils, CharSequence charSequence, ApplicationCommandOption applicationCommandOption, Integer num, int i, Object obj) {
|
|
if ((i & 4) != 0) {
|
|
num = null;
|
|
}
|
|
return autocompleteCommandUtils.appendParam(charSequence, applicationCommandOption, num);
|
|
}
|
|
|
|
private final Integer asSafeNumberOrNull(Integer num) {
|
|
if (num == null) {
|
|
return null;
|
|
}
|
|
int intValue = num.intValue();
|
|
if (INSTANCE.isSafeNumber(Integer.valueOf(intValue))) {
|
|
return Integer.valueOf(intValue);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private final Long asSafeNumberOrNull(Long l) {
|
|
if (l == null) {
|
|
return null;
|
|
}
|
|
long longValue = l.longValue();
|
|
if (INSTANCE.isSafeNumber(Long.valueOf(longValue))) {
|
|
return Long.valueOf(longValue);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private final Number asSafeNumberOrNull(Number number) {
|
|
if (number == null) {
|
|
return null;
|
|
}
|
|
if (INSTANCE.isSafeNumber(number)) {
|
|
return number;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static /* synthetic */ InputCommandContext getInputCommandContext$default(AutocompleteCommandUtils autocompleteCommandUtils, CharSequence charSequence, long j, List list, AutocompleteApplicationCommands autocompleteApplicationCommands, ApplicationCommand applicationCommand, int i, Object obj) {
|
|
if ((i & 16) != 0) {
|
|
applicationCommand = null;
|
|
}
|
|
return autocompleteCommandUtils.getInputCommandContext(charSequence, j, list, autocompleteApplicationCommands, applicationCommand);
|
|
}
|
|
|
|
private final boolean isSafeNumber(Number number) {
|
|
double doubleValue = number.doubleValue();
|
|
return doubleValue >= ((double) -9007199254740991L) && doubleValue <= ((double) 9007199254740991L);
|
|
}
|
|
|
|
private final Number parseNumber(String str) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
ParsePosition parsePosition = new ParsePosition(0);
|
|
Number parse = NumberFormat.getInstance().parse(str, parsePosition);
|
|
if (parsePosition.getIndex() == str.length() && parsePosition.getIndex() != 0) {
|
|
return parse;
|
|
}
|
|
throw new ParseException("Invalid input", parsePosition.getIndex());
|
|
} catch (ParseException unused) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:12:0x0049, code lost:
|
|
if (r6 != 8) goto L_0x0050;
|
|
*/
|
|
/* JADX WARNING: Removed duplicated region for block: B:17:0x0056 */
|
|
/* JADX WARNING: Removed duplicated region for block: B:18:0x005b */
|
|
@MainThread
|
|
public final InputEditTextAction.InsertText appendParam(CharSequence charSequence, ApplicationCommandOption applicationCommandOption, Integer num) {
|
|
m.checkNotNullParameter(charSequence, "input");
|
|
m.checkNotNullParameter(applicationCommandOption, "applicationCommandsOption");
|
|
charSequence.length();
|
|
String str = "";
|
|
StringBuilder P = a.P((w.endsWith$default(charSequence, ' ', false, 2, null) || num != null) ? str : " ");
|
|
P.append(applicationCommandOption.getName());
|
|
P.append(MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR);
|
|
String sb = P.toString();
|
|
int ordinal = applicationCommandOption.getType().ordinal();
|
|
if (ordinal != 5) {
|
|
if (ordinal == 6) {
|
|
str = "#";
|
|
} else if (ordinal != 7) {
|
|
}
|
|
String u = a.u(sb, str);
|
|
int intValue = num == null ? num.intValue() : charSequence.length();
|
|
return new InputEditTextAction.InsertText(charSequence, u, new IntRange(intValue, intValue), u.length() + charSequence.length());
|
|
}
|
|
str = "@";
|
|
String u = a.u(sb, str);
|
|
if (num == null) {
|
|
}
|
|
return new InputEditTextAction.InsertText(charSequence, u, new IntRange(intValue, intValue), u.length() + charSequence.length());
|
|
}
|
|
|
|
@MainThread
|
|
public final InputEditTextAction appendTextForCommandForInput(MentionInputModel.VerifiedCommandInputModel verifiedCommandInputModel) {
|
|
m.checkNotNullParameter(verifiedCommandInputModel, "model");
|
|
ApplicationCommand selectedCommand = verifiedCommandInputModel.getInputCommandContext().getSelectedCommand();
|
|
if (selectedCommand != null && selectedCommand.getOptions().size() == 1) {
|
|
ApplicationCommandOption applicationCommandOption = (ApplicationCommandOption) u.first((List<? extends Object>) selectedCommand.getOptions());
|
|
StringBuilder N = a.N(MentionUtilsKt.SLASH_CHAR);
|
|
N.append(selectedCommand.getName());
|
|
N.append(' ');
|
|
String sb = N.toString();
|
|
if (!verifiedCommandInputModel.getInputCommandOptionsRanges().containsKey(applicationCommandOption) && verifiedCommandInputModel.getInput().length() > sb.length()) {
|
|
return appendParam(verifiedCommandInputModel.getInput(), applicationCommandOption, Integer.valueOf(sb.length()));
|
|
}
|
|
}
|
|
return new InputEditTextAction.None(verifiedCommandInputModel.getInput());
|
|
}
|
|
|
|
public final Map<ApplicationCommandOption, OptionRange> findOptionRanges(CharSequence charSequence, ApplicationCommand applicationCommand) {
|
|
List<ApplicationCommandOption> options;
|
|
IntRange findValueRange;
|
|
m.checkNotNullParameter(charSequence, "$this$findOptionRanges");
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
if (!(applicationCommand == null || (options = applicationCommand.getOptions()) == null)) {
|
|
for (ApplicationCommandOption applicationCommandOption : options) {
|
|
AutocompleteCommandUtils autocompleteCommandUtils = INSTANCE;
|
|
Integer findStartOfParam = autocompleteCommandUtils.findStartOfParam(charSequence, applicationCommandOption.getName());
|
|
if (!(findStartOfParam == null || (findValueRange = autocompleteCommandUtils.findValueRange(charSequence, applicationCommand, applicationCommandOption.getName())) == null)) {
|
|
OptionRange optionRange = (OptionRange) linkedHashMap.put(applicationCommandOption, new OptionRange(new IntRange(findStartOfParam.intValue(), findValueRange.getFirst()), findValueRange));
|
|
}
|
|
}
|
|
}
|
|
return linkedHashMap;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final Integer findStartOfParam(CharSequence charSequence, String str) {
|
|
IntRange range;
|
|
m.checkNotNullParameter(charSequence, "$this$findStartOfParam");
|
|
m.checkNotNullParameter(str, "paramName");
|
|
MatchResult find$default = Regex.find$default(new Regex("[\\s|\\n]" + str + MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR), charSequence, 0, 2, null);
|
|
int first = (find$default == null || (range = find$default.getRange()) == null) ? -1 : range.getFirst();
|
|
if (first == -1) {
|
|
return null;
|
|
}
|
|
return Integer.valueOf(first + 1);
|
|
}
|
|
|
|
@VisibleForTesting
|
|
public final Integer findStartOfValue(CharSequence charSequence, String str) {
|
|
m.checkNotNullParameter(charSequence, "$this$findStartOfValue");
|
|
m.checkNotNullParameter(str, "paramName");
|
|
Integer findStartOfParam = findStartOfParam(charSequence, str);
|
|
int intValue = findStartOfParam != null ? findStartOfParam.intValue() : -1;
|
|
if (intValue != -1) {
|
|
return Integer.valueOf(str.length() + intValue + 1);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public final IntRange findValueRange(CharSequence charSequence, ApplicationCommand applicationCommand, String str) {
|
|
int i;
|
|
e eVar;
|
|
IntRange range;
|
|
ApplicationCommandOption applicationCommandOption;
|
|
boolean z2;
|
|
List<ApplicationCommandOption> options;
|
|
Object obj;
|
|
m.checkNotNullParameter(charSequence, "$this$findValueRange");
|
|
m.checkNotNullParameter(str, "paramName");
|
|
Integer findStartOfValue = findStartOfValue(charSequence, str);
|
|
if (findStartOfValue == null) {
|
|
return null;
|
|
}
|
|
int intValue = findStartOfValue.intValue();
|
|
Iterator it = Regex.findAll$default(new Regex(" ([\\p{L}0-9-_]*):"), charSequence.subSequence(intValue, charSequence.length()).toString(), 0, 2, null).iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
i = -1;
|
|
break;
|
|
}
|
|
Iterator<e> it2 = ((MatchResult) it.next()).getGroups().iterator();
|
|
while (true) {
|
|
if (!it2.hasNext()) {
|
|
eVar = null;
|
|
break;
|
|
}
|
|
eVar = it2.next();
|
|
e eVar2 = eVar;
|
|
if (applicationCommand == null || (options = applicationCommand.getOptions()) == null) {
|
|
applicationCommandOption = null;
|
|
} else {
|
|
Iterator<T> it3 = options.iterator();
|
|
while (true) {
|
|
if (!it3.hasNext()) {
|
|
obj = null;
|
|
break;
|
|
}
|
|
obj = it3.next();
|
|
if (m.areEqual(eVar2 != null ? eVar2.getValue() : null, ((ApplicationCommandOption) obj).getName())) {
|
|
break;
|
|
}
|
|
}
|
|
applicationCommandOption = (ApplicationCommandOption) obj;
|
|
}
|
|
if (applicationCommandOption != null) {
|
|
z2 = true;
|
|
continue;
|
|
} else {
|
|
z2 = false;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
break;
|
|
}
|
|
}
|
|
e eVar3 = eVar;
|
|
if (eVar3 == null || (range = eVar3.getRange()) == null) {
|
|
i = -1;
|
|
continue;
|
|
} else {
|
|
i = range.getFirst();
|
|
continue;
|
|
}
|
|
if (i != -1) {
|
|
break;
|
|
}
|
|
}
|
|
return i == -1 ? new IntRange(intValue, charSequence.length()) : new IntRange(intValue, i + intValue);
|
|
}
|
|
|
|
public final String getCommandPrefix(CharSequence charSequence) {
|
|
List<String> groupValues;
|
|
String str;
|
|
m.checkNotNullParameter(charSequence, "$this$getCommandPrefix");
|
|
MatchResult find$default = Regex.find$default(new Regex("^(/([\\p{L}0-9-]+\\s*){0,3})"), charSequence, 0, 2, null);
|
|
if (find$default == null || (groupValues = find$default.getGroupValues()) == null || (str = (String) u.getOrNull(groupValues, 1)) == null) {
|
|
return null;
|
|
}
|
|
return w.trim(str).toString();
|
|
}
|
|
|
|
public final Set<ApplicationCommandOption> getErrorsToShowForCommandParameters(ApplicationCommand applicationCommand, ApplicationCommandOption applicationCommandOption, ApplicationCommandOption applicationCommandOption2, Map<ApplicationCommandOption, Boolean> map, Map<ApplicationCommandOption, ? extends CommandOptionValue> map2) {
|
|
m.checkNotNullParameter(map, "validMap");
|
|
m.checkNotNullParameter(map2, "parsedCommandOptions");
|
|
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
|
if (applicationCommand == null) {
|
|
return n0.emptySet();
|
|
}
|
|
for (ApplicationCommandOption applicationCommandOption3 : applicationCommand.getOptions()) {
|
|
if (map2.containsKey(applicationCommandOption3)) {
|
|
CommandOptionValue commandOptionValue = (CommandOptionValue) map2.get(applicationCommandOption3);
|
|
String valueOf = String.valueOf(commandOptionValue != null ? commandOptionValue.getValue() : null);
|
|
boolean z2 = false;
|
|
boolean z3 = t.isBlank(valueOf) || (valueOf.length() == 1 && MentionUtilsKt.getDEFAULT_LEADING_IDENTIFIERS().contains(Character.valueOf(valueOf.charAt(0))));
|
|
boolean areEqual = m.areEqual(applicationCommandOption, applicationCommandOption3);
|
|
boolean z4 = applicationCommandOption2 != null && m.areEqual(applicationCommandOption2, applicationCommandOption3);
|
|
boolean containsKey = map2.containsKey(applicationCommandOption3);
|
|
boolean z5 = (areEqual && z4) || (areEqual && z3);
|
|
if (m.areEqual(map.get(applicationCommandOption3), Boolean.FALSE) && !z5 && containsKey) {
|
|
z2 = true;
|
|
}
|
|
if (z2) {
|
|
linkedHashSet.add(applicationCommandOption3);
|
|
}
|
|
}
|
|
}
|
|
return linkedHashSet;
|
|
}
|
|
|
|
/* JADX DEBUG: Multi-variable search result rejected for r2v5, resolved type: java.lang.Object */
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX ERROR: IF instruction can be used only in fallback mode
|
|
jadx.core.utils.exceptions.CodegenException: IF instruction can be used only in fallback mode
|
|
at jadx.core.codegen.InsnGen.fallbackOnlyInsn(InsnGen.java:631)
|
|
at jadx.core.codegen.InsnGen.makeInsnBody(InsnGen.java:513)
|
|
at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:275)
|
|
at jadx.core.codegen.InsnGen.makeInsn(InsnGen.java:245)
|
|
at jadx.core.codegen.RegionGen.makeSimpleBlock(RegionGen.java:104)
|
|
at jadx.core.dex.nodes.IBlock.generate(IBlock.java:15)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.dex.regions.Region.generate(Region.java:35)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:93)
|
|
at jadx.core.codegen.RegionGen.makeLoop(RegionGen.java:188)
|
|
at jadx.core.dex.regions.loops.LoopRegion.generate(LoopRegion.java:173)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.dex.regions.Region.generate(Region.java:35)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.codegen.RegionGen.makeRegionIndent(RegionGen.java:93)
|
|
at jadx.core.codegen.RegionGen.makeIf(RegionGen.java:136)
|
|
at jadx.core.dex.regions.conditions.IfRegion.generate(IfRegion.java:137)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.dex.regions.Region.generate(Region.java:35)
|
|
at jadx.core.codegen.RegionGen.makeRegion(RegionGen.java:64)
|
|
at jadx.core.codegen.MethodGen.addRegionInsns(MethodGen.java:261)
|
|
at jadx.core.codegen.MethodGen.addInstructions(MethodGen.java:254)
|
|
at jadx.core.codegen.ClassGen.addMethodCode(ClassGen.java:345)
|
|
at jadx.core.codegen.ClassGen.addMethod(ClassGen.java:298)
|
|
at jadx.core.codegen.ClassGen.lambda$addInnerClsAndMethods$3(ClassGen.java:267)
|
|
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
|
|
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
|
|
at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
|
|
at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:8:0x0036, code lost:
|
|
if (d0.g0.t.startsWith$default(r8, r9, false, 2, null) == false) goto L_0x0038;
|
|
*/
|
|
/* JADX WARNING: Removed duplicated region for block: B:31:0x00bc */
|
|
/* JADX WARNING: Removed duplicated region for block: B:44:0x00a8 A[EDGE_INSN: B:44:0x00a8->B:26:0x00a8 ?: BREAK , SYNTHETIC] */
|
|
/* JADX WARNING: Removed duplicated region for block: B:48:0x00d7 A[EDGE_INSN: B:48:0x00d7->B:39:0x00d7 ?: BREAK , SYNTHETIC] */
|
|
public final com.discord.widgets.chat.input.models.InputCommandContext getInputCommandContext(java.lang.CharSequence charSequence, long j, java.util.List<java.lang.Long> list, com.discord.widgets.chat.input.models.AutocompleteApplicationCommands autocompleteApplicationCommands, com.discord.models.commands.ApplicationCommand applicationCommand) {
|
|
/*
|
|
r14 = this;
|
|
r0 = r15
|
|
r1 = r18
|
|
java.lang.String r2 = "input"
|
|
d0.z.d.m.checkNotNullParameter(r15, r2)
|
|
java.lang.String r2 = "userRoles"
|
|
d0.z.d.m.checkNotNullParameter(r1, r2)
|
|
java.lang.String r2 = "applicationCommands"
|
|
r3 = r19
|
|
d0.z.d.m.checkNotNullParameter(r3, r2)
|
|
java.lang.String r2 = r14.getCommandPrefix(r15)
|
|
r4 = 0
|
|
if (r2 == 0) goto L_0x00da
|
|
r5 = 2
|
|
r6 = 1
|
|
r7 = 0
|
|
if (r20 == 0) goto L_0x0038
|
|
java.lang.String r8 = r2.substring(r6)
|
|
java.lang.String r9 = "(this as java.lang.String).substring(startIndex)"
|
|
d0.z.d.m.checkNotNullExpressionValue(r8, r9)
|
|
java.lang.String r9 = r20.getName()
|
|
if (r9 == 0) goto L_0x0030
|
|
goto L_0x0032
|
|
L_0x0030:
|
|
java.lang.String r9 = ""
|
|
L_0x0032:
|
|
boolean r8 = d0.g0.t.startsWith$default(r8, r9, r7, r5, r4)
|
|
if (r8 != 0) goto L_0x00ac
|
|
L_0x0038:
|
|
int r2 = r2.length()
|
|
if (r2 <= 0) goto L_0x0040
|
|
r2 = 1
|
|
goto L_0x0041
|
|
L_0x0040:
|
|
r2 = 0
|
|
L_0x0041:
|
|
if (r2 == 0) goto L_0x00ac
|
|
java.util.List r2 = r19.getQueryCommands()
|
|
java.util.List r2 = com.discord.stores.StoreApplicationCommandsKt.flattenSubCommands(r2)
|
|
java.util.Iterator r2 = r2.iterator()
|
|
L_0x004f:
|
|
boolean r8 = r2.hasNext()
|
|
if (r8 == 0) goto L_0x00a7
|
|
java.lang.Object r8 = r2.next()
|
|
r9 = r8
|
|
com.discord.models.commands.ApplicationCommand r9 = (com.discord.models.commands.ApplicationCommand) r9
|
|
java.lang.StringBuilder r10 = new java.lang.StringBuilder
|
|
r10.<init>()
|
|
com.discord.widgets.chat.input.autocomplete.LeadingIdentifier r11 = com.discord.widgets.chat.input.autocomplete.LeadingIdentifier.APP_COMMAND
|
|
java.lang.Character r11 = r11.getIdentifier()
|
|
d0.z.d.m.checkNotNull(r11)
|
|
char r11 = r11.charValue()
|
|
java.lang.String r12 = r9.getName()
|
|
java.lang.StringBuilder r13 = new java.lang.StringBuilder
|
|
r13.<init>()
|
|
java.lang.String r11 = java.lang.String.valueOf(r11)
|
|
r13.append(r11)
|
|
r13.append(r12)
|
|
java.lang.String r11 = r13.toString()
|
|
r10.append(r11)
|
|
r11 = 32
|
|
r10.append(r11)
|
|
java.lang.String r10 = r10.toString()
|
|
boolean r10 = d0.g0.w.startsWith$default(r15, r10, r7, r5, r4)
|
|
if (r10 == 0) goto L_0x00a1
|
|
r10 = r16
|
|
boolean r9 = com.discord.models.commands.ApplicationCommandKt.hasPermission(r9, r10, r1)
|
|
if (r9 == 0) goto L_0x00a3
|
|
r9 = 1
|
|
goto L_0x00a4
|
|
L_0x00a1:
|
|
r10 = r16
|
|
L_0x00a3:
|
|
r9 = 0
|
|
L_0x00a4:
|
|
if (r9 == 0) goto L_0x004f
|
|
goto L_0x00a8
|
|
L_0x00a7:
|
|
r8 = r4
|
|
L_0x00a8:
|
|
r0 = r8
|
|
com.discord.models.commands.ApplicationCommand r0 = (com.discord.models.commands.ApplicationCommand) r0
|
|
goto L_0x00ae
|
|
L_0x00ac:
|
|
r0 = r20
|
|
L_0x00ae:
|
|
java.util.List r1 = r19.getApplications()
|
|
java.util.Iterator r1 = r1.iterator()
|
|
L_0x00b6:
|
|
boolean r2 = r1.hasNext()
|
|
if (r2 == 0) goto L_0x00d7
|
|
java.lang.Object r2 = r1.next()
|
|
r3 = r2
|
|
com.discord.models.commands.Application r3 = (com.discord.models.commands.Application) r3
|
|
long r8 = r3.getId()
|
|
if (r0 == 0) goto L_0x00d3
|
|
long r10 = r0.getApplicationId()
|
|
int r3 = (r8 > r10 ? 1 : (r8 == r10 ? 0 : -1))
|
|
if (r3 != 0) goto L_0x00d3
|
|
r3 = 1
|
|
goto L_0x00d4
|
|
L_0x00d3:
|
|
r3 = 0
|
|
L_0x00d4:
|
|
if (r3 == 0) goto L_0x00b6
|
|
r4 = r2
|
|
L_0x00d7:
|
|
com.discord.models.commands.Application r4 = (com.discord.models.commands.Application) r4
|
|
goto L_0x00db
|
|
L_0x00da:
|
|
r0 = r4
|
|
L_0x00db:
|
|
com.discord.widgets.chat.input.models.InputCommandContext r1 = new com.discord.widgets.chat.input.models.InputCommandContext
|
|
r1.<init>(r4, r0)
|
|
return r1
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: com.discord.widgets.chat.input.autocomplete.commands.AutocompleteCommandUtils.getInputCommandContext(java.lang.CharSequence, long, java.util.List, com.discord.widgets.chat.input.models.AutocompleteApplicationCommands, com.discord.models.commands.ApplicationCommand):com.discord.widgets.chat.input.models.InputCommandContext");
|
|
}
|
|
|
|
/* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
|
|
/* JADX WARNING: Code restructure failed: missing block: B:28:0x008b, code lost:
|
|
if ((r2 instanceof com.discord.widgets.chat.input.models.SnowflakeOptionValue) == false) goto L_0x00f1;
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:32:0x0094, code lost:
|
|
if ((r2 instanceof com.discord.widgets.chat.input.models.SnowflakeOptionValue) == false) goto L_0x00f1;
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:43:0x00c4, code lost:
|
|
if (r1.getChannelTypes().contains(java.lang.Integer.valueOf(((com.discord.widgets.chat.input.models.ChannelOptionValue) r2).getChannel().A())) == false) goto L_0x00c6;
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:45:0x00c8, code lost:
|
|
if ((r2 instanceof com.discord.widgets.chat.input.models.SnowflakeOptionValue) != false) goto L_0x007e;
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:49:0x00d1, code lost:
|
|
if ((r2 instanceof com.discord.widgets.chat.input.models.SnowflakeOptionValue) == false) goto L_0x00f1;
|
|
*/
|
|
/* JADX WARNING: Code restructure failed: missing block: B:56:0x00ee, code lost:
|
|
if ((!d0.g0.t.isBlank(r2.getValue().toString())) != false) goto L_0x007e;
|
|
*/
|
|
public final Map<ApplicationCommandOption, Boolean> getInputValidity(ApplicationCommand applicationCommand, Map<ApplicationCommandOption, ? extends CommandOptionValue> map) {
|
|
m.checkNotNullParameter(applicationCommand, "selectedCommand");
|
|
m.checkNotNullParameter(map, "parsedCommandOptions");
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (ApplicationCommandOption applicationCommandOption : applicationCommand.getOptions()) {
|
|
CommandOptionValue commandOptionValue = (CommandOptionValue) map.get(applicationCommandOption);
|
|
if (commandOptionValue != null) {
|
|
List<CommandChoice> choices = applicationCommandOption.getChoices();
|
|
boolean z2 = false;
|
|
if (choices == null || !(!choices.isEmpty())) {
|
|
switch (applicationCommandOption.getType().ordinal()) {
|
|
case 0:
|
|
case 1:
|
|
break;
|
|
case 2:
|
|
if (commandOptionValue instanceof StringOptionValue) {
|
|
break;
|
|
}
|
|
break;
|
|
case 3:
|
|
z2 = commandOptionValue instanceof IntegerOptionValue;
|
|
break;
|
|
case 4:
|
|
z2 = commandOptionValue instanceof BooleanOptionValue;
|
|
break;
|
|
case 5:
|
|
if (!(commandOptionValue instanceof UserOptionValue)) {
|
|
break;
|
|
}
|
|
break;
|
|
case 6:
|
|
if (commandOptionValue instanceof ChannelOptionValue) {
|
|
List<Integer> channelTypes = applicationCommandOption.getChannelTypes();
|
|
if (!(channelTypes == null || channelTypes.isEmpty())) {
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case 7:
|
|
if (!(commandOptionValue instanceof RoleOptionValue)) {
|
|
break;
|
|
}
|
|
break;
|
|
case 8:
|
|
if (!(commandOptionValue instanceof UserOptionValue)) {
|
|
if (!(commandOptionValue instanceof RoleOptionValue)) {
|
|
break;
|
|
}
|
|
}
|
|
break;
|
|
case 9:
|
|
z2 = commandOptionValue instanceof NumberOptionValue;
|
|
break;
|
|
case 10:
|
|
break;
|
|
default:
|
|
throw new NoWhenBranchMatchedException();
|
|
}
|
|
linkedHashMap.put(applicationCommandOption, Boolean.valueOf(z2));
|
|
} else {
|
|
List<CommandChoice> choices2 = applicationCommandOption.getChoices();
|
|
if (!(choices2 instanceof Collection) || !choices2.isEmpty()) {
|
|
Iterator<T> it = choices2.iterator();
|
|
while (true) {
|
|
if (it.hasNext()) {
|
|
if (m.areEqual(((CommandChoice) it.next()).b(), commandOptionValue.getValue().toString())) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
linkedHashMap.put(applicationCommandOption, Boolean.valueOf(z2));
|
|
}
|
|
z2 = true;
|
|
linkedHashMap.put(applicationCommandOption, Boolean.valueOf(z2));
|
|
} else if (applicationCommandOption.getRequired()) {
|
|
linkedHashMap.put(applicationCommandOption, Boolean.FALSE);
|
|
}
|
|
}
|
|
return linkedHashMap;
|
|
}
|
|
|
|
public final ApplicationCommand getSelectedCommand(List<? extends ApplicationCommand> list, String str, String str2, long j, List<Long> list2) {
|
|
boolean z2;
|
|
m.checkNotNullParameter(list, "commands");
|
|
m.checkNotNullParameter(str, "prefix");
|
|
m.checkNotNullParameter(str2, "input");
|
|
m.checkNotNullParameter(list2, "roles");
|
|
Object obj = null;
|
|
if (!(str.length() > 0)) {
|
|
return null;
|
|
}
|
|
Iterator<T> it = list.iterator();
|
|
while (true) {
|
|
if (!it.hasNext()) {
|
|
break;
|
|
}
|
|
Object next = it.next();
|
|
ApplicationCommand applicationCommand = (ApplicationCommand) next;
|
|
StringBuilder sb = new StringBuilder();
|
|
String name = applicationCommand.getName();
|
|
sb.append(String.valueOf((char) MentionUtilsKt.SLASH_CHAR) + name);
|
|
sb.append(' ');
|
|
if (!t.startsWith$default(str2, sb.toString(), false, 2, null) || !ApplicationCommandKt.hasPermission(applicationCommand, j, list2)) {
|
|
z2 = false;
|
|
continue;
|
|
} else {
|
|
z2 = true;
|
|
continue;
|
|
}
|
|
if (z2) {
|
|
obj = next;
|
|
break;
|
|
}
|
|
}
|
|
return (ApplicationCommand) obj;
|
|
}
|
|
|
|
public final ApplicationCommandOption getSelectedCommandOption(int i, Map<ApplicationCommandOption, OptionRange> map) {
|
|
Set<ApplicationCommandOption> keySet;
|
|
if (map == null || (keySet = map.keySet()) == null) {
|
|
return null;
|
|
}
|
|
for (ApplicationCommandOption applicationCommandOption : keySet) {
|
|
OptionRange optionRange = map.get(applicationCommandOption);
|
|
if (optionRange != null && optionRange.getParam().getFirst() < i && optionRange.getValue().getLast() >= i) {
|
|
return applicationCommandOption;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/* JADX WARNING: Code restructure failed: missing block: B:20:0x00b7, code lost:
|
|
if (r3 != null) goto L_0x00bb;
|
|
*/
|
|
public final Map<ApplicationCommandOption, CommandOptionValue> parseCommandOptions(CharSequence charSequence, ApplicationCommand applicationCommand, ChatInputMentionsMap chatInputMentionsMap) {
|
|
CommandOptionValue commandOptionValue;
|
|
Object obj;
|
|
String str;
|
|
CommandOptionValue integerOptionValue;
|
|
Object obj2;
|
|
m.checkNotNullParameter(charSequence, "input");
|
|
m.checkNotNullParameter(applicationCommand, "command");
|
|
m.checkNotNullParameter(chatInputMentionsMap, "mentionMap");
|
|
Map<ApplicationCommandOption, OptionRange> findOptionRanges = findOptionRanges(charSequence, applicationCommand);
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
for (Map.Entry<ApplicationCommandOption, OptionRange> entry : findOptionRanges.entrySet()) {
|
|
ApplicationCommandOption key = entry.getKey();
|
|
OptionRange value = entry.getValue();
|
|
String obj3 = charSequence.subSequence(value.getValue().getFirst(), value.getValue().getLast()).toString();
|
|
Objects.requireNonNull(obj3, "null cannot be cast to non-null type kotlin.CharSequence");
|
|
String obj4 = w.trim(obj3).toString();
|
|
Iterator<T> it = chatInputMentionsMap.getMentions().values().iterator();
|
|
while (true) {
|
|
commandOptionValue = null;
|
|
if (it.hasNext()) {
|
|
obj = it.next();
|
|
if (((Autocompletable) obj).matchesText(obj4)) {
|
|
}
|
|
} else {
|
|
obj = null;
|
|
}
|
|
}
|
|
Autocompletable autocompletable = (Autocompletable) obj;
|
|
List<CommandChoice> choices = key.getChoices();
|
|
if (choices != null) {
|
|
Iterator<T> it2 = choices.iterator();
|
|
while (true) {
|
|
if (it2.hasNext()) {
|
|
obj2 = it2.next();
|
|
String a = ((CommandChoice) obj2).a();
|
|
Objects.requireNonNull(a, "null cannot be cast to non-null type kotlin.CharSequence");
|
|
if (m.areEqual(w.trim(a).toString(), obj4)) {
|
|
}
|
|
} else {
|
|
obj2 = null;
|
|
}
|
|
}
|
|
CommandChoice commandChoice = (CommandChoice) obj2;
|
|
if (commandChoice != null) {
|
|
str = commandChoice.b();
|
|
}
|
|
}
|
|
str = obj4;
|
|
switch (key.getType().ordinal()) {
|
|
case 2:
|
|
commandOptionValue = new StringOptionValue(str);
|
|
break;
|
|
case 3:
|
|
Long asSafeNumberOrNull = asSafeNumberOrNull(s.toLongOrNull(obj4));
|
|
if (asSafeNumberOrNull != null) {
|
|
integerOptionValue = new IntegerOptionValue(asSafeNumberOrNull.longValue());
|
|
commandOptionValue = integerOptionValue;
|
|
break;
|
|
}
|
|
break;
|
|
case 4:
|
|
if (AutocompleteModelUtils.INSTANCE.isBoolean(obj4)) {
|
|
integerOptionValue = new BooleanOptionValue(Boolean.parseBoolean(obj4));
|
|
commandOptionValue = integerOptionValue;
|
|
break;
|
|
}
|
|
break;
|
|
case 5:
|
|
if (!(autocompletable instanceof UserAutocompletable)) {
|
|
autocompletable = null;
|
|
}
|
|
UserAutocompletable userAutocompletable = (UserAutocompletable) autocompletable;
|
|
if (userAutocompletable != null) {
|
|
integerOptionValue = new UserOptionValue(userAutocompletable.getUser());
|
|
commandOptionValue = integerOptionValue;
|
|
break;
|
|
}
|
|
break;
|
|
case 6:
|
|
if (!(autocompletable instanceof ChannelAutocompletable)) {
|
|
autocompletable = null;
|
|
}
|
|
ChannelAutocompletable channelAutocompletable = (ChannelAutocompletable) autocompletable;
|
|
if (channelAutocompletable != null) {
|
|
integerOptionValue = new ChannelOptionValue(channelAutocompletable.getChannel());
|
|
commandOptionValue = integerOptionValue;
|
|
break;
|
|
}
|
|
break;
|
|
case 7:
|
|
if (!(autocompletable instanceof RoleAutocompletable)) {
|
|
autocompletable = null;
|
|
}
|
|
RoleAutocompletable roleAutocompletable = (RoleAutocompletable) autocompletable;
|
|
if (roleAutocompletable != null) {
|
|
integerOptionValue = new RoleOptionValue(roleAutocompletable.getRole());
|
|
commandOptionValue = integerOptionValue;
|
|
break;
|
|
}
|
|
break;
|
|
case 8:
|
|
if (!(autocompletable instanceof RoleAutocompletable)) {
|
|
if (autocompletable instanceof UserAutocompletable) {
|
|
commandOptionValue = new UserOptionValue(((UserAutocompletable) autocompletable).getUser());
|
|
break;
|
|
}
|
|
} else {
|
|
commandOptionValue = new RoleOptionValue(((RoleAutocompletable) autocompletable).getRole());
|
|
break;
|
|
}
|
|
break;
|
|
case 9:
|
|
Number asSafeNumberOrNull2 = asSafeNumberOrNull(parseNumber(obj4));
|
|
if (asSafeNumberOrNull2 != null) {
|
|
commandOptionValue = new NumberOptionValue(asSafeNumberOrNull2);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
if (commandOptionValue != null) {
|
|
linkedHashMap.put(key, commandOptionValue);
|
|
} else {
|
|
Long snowflake = SnowflakeUtils.INSTANCE.toSnowflake(obj4);
|
|
if (snowflake != null) {
|
|
linkedHashMap.put(key, new SnowflakeOptionValue(snowflake.longValue()));
|
|
} else {
|
|
linkedHashMap.put(key, new RawOptionValue(obj3));
|
|
}
|
|
}
|
|
}
|
|
return linkedHashMap;
|
|
}
|
|
|
|
public final String transformParameterSpannableString(String str) {
|
|
String str2 = null;
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
if (w.endsWith$default((CharSequence) w.trim(str).toString(), (char) MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR, false, 2, (Object) null)) {
|
|
return w.trim(str).toString();
|
|
}
|
|
if (!w.contains$default((CharSequence) str, (char) MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR, false, 2, (Object) null)) {
|
|
return str;
|
|
}
|
|
List split$default = w.split$default((CharSequence) str, new char[]{MentionUtilsKt.EMOJIS_AND_STICKERS_CHAR}, false, 0, 6, (Object) null);
|
|
String str3 = (String) u.firstOrNull((List<? extends Object>) split$default);
|
|
if (str3 != null) {
|
|
str2 = w.trim(str3).toString();
|
|
}
|
|
String joinToString$default = u.joinToString$default(split$default.subList(1, split$default.size()), ":", null, null, 0, null, null, 62, null);
|
|
Objects.requireNonNull(joinToString$default, "null cannot be cast to non-null type kotlin.CharSequence");
|
|
return a.v(str2, ": ", w.trim(joinToString$default).toString());
|
|
}
|
|
}
|