226 lines
8.8 KiB
TypeScript
226 lines
8.8 KiB
TypeScript
// Metro module 9659 (f9660).
|
|
import ApplicationCommandAutocompleteStore from "../../application_commands/ApplicationCommandAutocompleteStore";
|
|
import ApplicationCommandStore from "../../application_commands/ApplicationCommandStore";
|
|
import GameAutocompleteStore from "../../games/autocomplete/GameAutocompleteStore";
|
|
import StickersStore from "../../stickers/StickersStore";
|
|
import ChannelStore from "../../../stores/ChannelStore";
|
|
import GuildMemberStore from "../../../stores/GuildMemberStore";
|
|
import GuildStore from "../../../stores/GuildStore";
|
|
import { AutoCompleteResultTypes, MAX_AUTOCOMPLETE_RESULTS } from "../../../Constants";
|
|
import { AUTOCOMPLETE_OPTION_DEBOUNCE_TIME } from "../../application_commands/ApplicationCommandConstants";
|
|
import { CHANNEL_SENTINEL, COMMAND_SENTINEL, EMOJI_SENTINEL, MENTION_SENTINEL } from "../../channel_autocomplete/ChannelAutocompleteConstants";
|
|
import { AutocompleteTypes } from "../../channel_text_area/native/ChannelAutocompleteConstants";
|
|
import { EMOJI_MAX_LENGTH, EMOJI_URL_BASE_SIZE, EmojiIntention } from "../../emojis/EmojiConstants";
|
|
import Module12 from "../../../_bundle/Module12";
|
|
import executeCommand from "../../application_commands/executeCommand";
|
|
import AutocompleteUtils from "../../../utils/AutocompleteUtils";
|
|
import { getGameMentionsAutocompleteConfig } from "../../game_mentions/getGameMentionsAutocompleteConfig";
|
|
import { queryGamesAutocomplete } from "../../games/autocomplete/queryGamesAutocomplete";
|
|
import { fetchStickerPacks } from "../../stickers/StickersActionCreators";
|
|
import { StickerSendability } from "../../stickers/StickerSendability";
|
|
import AvatarUtils from "../../../utils/AvatarUtils";
|
|
import { intl, t } from "../../../intl/index.native";
|
|
import { HermesBuiltin } from "../../../_hermes/prelude";
|
|
let $mk83005 = function() {
|
|
return (a0) => ({
|
|
type: AutoCompleteResultTypes.GAME_MENTION,
|
|
game: a0
|
|
});
|
|
};
|
|
let c6387_20 = false;
|
|
let c6387_21 = Module12.debounce(executeCommand, AUTOCOMPLETE_OPTION_DEBOUNCE_TIME, {
|
|
leading: true,
|
|
trailing: true
|
|
});
|
|
export function getAutocompleteOptions(channel, r10 = false) {
|
|
let c17380_1 = r10;
|
|
let r11 = arguments[2];
|
|
if (r11 === void 0) {
|
|
r11 = true;
|
|
}
|
|
let c17380_2 = r11;
|
|
const r12 = {};
|
|
r12[AutocompleteTypes.MENTIONS] = {
|
|
stores: [GuildMemberStore, GameAutocompleteStore],
|
|
queryResults: (a0, a1, a2) => {
|
|
let r57;
|
|
const r33 = AutocompleteUtils.queryMentionResults({
|
|
query: a0,
|
|
channel,
|
|
canMentionEveryone: a1?.canMentionEveryone,
|
|
canMentionHere: a1?.canMentionHere,
|
|
canMentionUsers: a1?.canMentionUsers,
|
|
canMentionRoles: a1?.canMentionRoles,
|
|
includeAllGuildUsers: a1?.canMentionAnyGuildUser,
|
|
includeNonMentionableRoles: a1?.canMentionNonMentionableRoles,
|
|
request: a2
|
|
});
|
|
const { users, globals, roles } = r33;
|
|
const gameMentionsAutocompleteConfig = getGameMentionsAutocompleteConfig("mentions autocomplete");
|
|
if (a1?.canMentionGames === true && gameMentionsAutocompleteConfig.enabled && gameMentionsAutocompleteConfig.combineMentionAutocomplete && a0.length > 0) {
|
|
if (!a1?.isActiveApplicationCommand) {
|
|
let r52 = queryGamesAutocomplete(a0);
|
|
if (r52 == null) {
|
|
r52 = [];
|
|
}
|
|
r57 = r52.slice(0, 1).map($mk83005());
|
|
} else {
|
|
r57 = [];
|
|
}
|
|
} else {
|
|
r57 = [];
|
|
}
|
|
const r18 = users.map((user) => ({
|
|
type: AutoCompleteResultTypes.USER,
|
|
...user
|
|
}));
|
|
const r62 = [];
|
|
const r63 = HermesBuiltin.arraySpread(r62, r18, 0);
|
|
const r68 = HermesBuiltin.arraySpread(r62, globals.map((global) => ({
|
|
type: AutoCompleteResultTypes.GLOBAL,
|
|
...global
|
|
})), r63);
|
|
HermesBuiltin.arraySpread(r62, r57, HermesBuiltin.arraySpread(r62, roles.map((role) => ({
|
|
type: AutoCompleteResultTypes.ROLE,
|
|
...role
|
|
})), r68));
|
|
return Module12(r62).value();
|
|
},
|
|
matches: (a0, a1) => AutocompleteUtils.matchSentinel(a0, a1, MENTION_SENTINEL)
|
|
};
|
|
r12[AutocompleteTypes.GAME_MENTIONS] = {
|
|
stores: [GameAutocompleteStore],
|
|
queryResults: (a0) => {
|
|
let r24;
|
|
const gameMentionsAutocompleteConfig = getGameMentionsAutocompleteConfig("game_mentions autocomplete");
|
|
if (gameMentionsAutocompleteConfig.enabled && (!gameMentionsAutocompleteConfig.combineMentionAutocomplete && a0.length !== 0)) {
|
|
let r17 = queryGamesAutocomplete(a0);
|
|
if (r17 == null) {
|
|
r17 = [];
|
|
}
|
|
r24 = r17.slice(0, MAX_AUTOCOMPLETE_RESULTS).map($mk83005());
|
|
} else {
|
|
r24 = [];
|
|
}
|
|
return r24;
|
|
},
|
|
matches: () => false
|
|
};
|
|
r12[AutocompleteTypes.CHANNELS] = {
|
|
queryResults: (a0, a1) => {
|
|
const channelTypes = a1?.channelTypes;
|
|
return (a1?.isActiveApplicationCommand ? AutocompleteUtils.queryApplicationCommandChannelResults({
|
|
query: a0,
|
|
channel,
|
|
channelTypes
|
|
}) : AutocompleteUtils.queryChannelResults({
|
|
query: a0,
|
|
channel
|
|
})).channels.map((a0) => ({
|
|
type: AutoCompleteResultTypes.CHANNEL,
|
|
channel: a0,
|
|
category: ChannelStore.getChannel(a0.parent_id)
|
|
}));
|
|
},
|
|
matches: (a0, a1) => {
|
|
const isPrivate = channel.isPrivate();
|
|
return isPrivate ? !isPrivate : AutocompleteUtils.matchSentinel(a0, a1, CHANNEL_SENTINEL);
|
|
}
|
|
};
|
|
r12[AutocompleteTypes.EMOJIS_AND_STICKERS] = {
|
|
queryResults: (a0, a1) => {
|
|
const r23 = AutocompleteUtils.queryEmojiResults({
|
|
query: a0,
|
|
channel,
|
|
intention: EmojiIntention.CHAT,
|
|
maxCount: MAX_AUTOCOMPLETE_RESULTS + (c17380_2 ? 0 : 40)
|
|
});
|
|
const r34 = a1?.includeEmojiPremiumUpsell && (r23.emojis.locked.length > 0 && r23.emojis.unlocked.length < 4) ? [{
|
|
type: AutoCompleteResultTypes.EMOJI_PREMIUM_UPSELL,
|
|
results: r23.emojis.locked
|
|
}] : [];
|
|
let r41 = [];
|
|
if (c17380_2) {
|
|
if (!(c6387_20 || StickersStore.hasLoadedStickerPacks)) {
|
|
c6387_20 = true;
|
|
fetchStickerPacks();
|
|
}
|
|
r41 = AutocompleteUtils.queryStickers([a0], true, [channel, (a0, a1) => a1 === StickerSendability.SENDABLE]);
|
|
}
|
|
const r16 = r41.map(({ sticker }) => ({
|
|
type: AutoCompleteResultTypes.STICKER,
|
|
name: sticker.name,
|
|
sticker
|
|
}));
|
|
const r59 = [];
|
|
const r60 = HermesBuiltin.arraySpread(r59, r16, 0);
|
|
HermesBuiltin.arraySpread(r59, r34, HermesBuiltin.arraySpread(r59, r23.emojis.unlocked.map((item) => ({
|
|
type: AutoCompleteResultTypes.EMOJI,
|
|
name: item.name,
|
|
url: item.id != null ? AvatarUtils.getEmojiURL({
|
|
id: item.id,
|
|
animated: item.animated,
|
|
size: EMOJI_URL_BASE_SIZE
|
|
}) : item.url,
|
|
surrogates: item.id == null ? item.surrogates : void 0
|
|
})), r60));
|
|
return r59;
|
|
},
|
|
matches: (a0, a1) => {
|
|
let r2 = a0 === EMOJI_SENTINEL;
|
|
if (r2) {
|
|
const r1 = a1.length < 2 || a1.length > EMOJI_MAX_LENGTH;
|
|
r2 = r1 ? !r1 : !a1.includes(EMOJI_SENTINEL);
|
|
}
|
|
return r2;
|
|
}
|
|
};
|
|
r12[AutocompleteTypes.SLASHES] = {
|
|
queryResults: () => [],
|
|
matches: (a0, a1, a2) => a2 === 0 && a0 === COMMAND_SENTINEL && !(c17380_1 && a1.length === 0)
|
|
};
|
|
r12[AutocompleteTypes.SLASHES_DISCOVERY] = {
|
|
queryResults: () => [],
|
|
matches: (a0, a1, a2) => c17380_1 && a2 === 0 && a0 === COMMAND_SENTINEL && a1.length === 0
|
|
};
|
|
r12[AutocompleteTypes.CHOICES] = {
|
|
stores: [ApplicationCommandStore, ApplicationCommandAutocompleteStore],
|
|
queryResults: (a0, a1) => {
|
|
if ((a1 == null ? void 0 : a1.option?.autocomplete) && a1?.activeCommand != null && a1?.optionValues != null) {
|
|
c6387_21({
|
|
command: a1.activeCommand,
|
|
optionValues: a1.optionValues,
|
|
context: {
|
|
channel,
|
|
guild: GuildStore.getGuild(channel.guild_id),
|
|
autocomplete: {
|
|
name: a1.option.name,
|
|
query: a0
|
|
}
|
|
}
|
|
});
|
|
const autocompleteChoices = ApplicationCommandAutocompleteStore.getAutocompleteChoices(channel.id, a1.option.name, a0);
|
|
return autocompleteChoices == null ? new Array(4).fill({
|
|
type: AutoCompleteResultTypes.CHOICE_LOADING
|
|
}) : autocompleteChoices.length === 0 ? [{
|
|
type: AutoCompleteResultTypes.LABEL,
|
|
label: intl.string(t["41014u"])
|
|
}] : autocompleteChoices.map((autocompleteChoice) => ({
|
|
type: AutoCompleteResultTypes.CHOICE,
|
|
choice: autocompleteChoice
|
|
}));
|
|
}
|
|
const choices = a1?.choices;
|
|
return choices == null ? [] : AutocompleteUtils.queryChoiceResults({
|
|
query: a0,
|
|
choices
|
|
}).choices.map((a0) => ({
|
|
type: AutoCompleteResultTypes.CHOICE,
|
|
choice: a0
|
|
}));
|
|
},
|
|
matches: () => false
|
|
};
|
|
return r12;
|
|
}
|