Files
discord-decomp/modules/soundboard/searchSounds.tsx
T
2026-11-01 12:12:55 +02:00

67 lines
2.5 KiB
TypeScript

// Metro module 12633 (f12634).
import EmojiStore from "../emojis/EmojiStore";
import { AnalyticEvents, SearchTypes } from "../../Constants";
import debounce from "../../_bundle/debounce";
import AnalyticsUtils from "../../utils/AnalyticsUtils";
import UnicodeEmojis from "../emojis/UnicodeEmojis";
import fuzzysearch from "../../_bundle/fuzzysearch";
import { canUseSoundboardSound } from "./SoundboardUtils";
let c8720_6, c8720_7;
export function trackSearchStart(a0, a1) {
AnalyticsUtils.track(AnalyticEvents.SEARCH_STARTED, {
channel_id: a1,
search_type: SearchTypes.SOUNDBOARD,
location_stack: a0
});
}
export function trackSearchResultViewed(a0, a1, a2, a3) {
AnalyticsUtils.track(AnalyticEvents.SEARCH_RESULT_VIEWED, {
search_type: SearchTypes.SOUNDBOARD,
channel_id: a2,
query: a3,
total_results: a0.length,
location_stack: a1
});
}
c8720_6 = debounce(trackSearchStart, 350);
c8720_7 = debounce(trackSearchResultViewed, 350);
export function searchSounds(a0, a1, c19944_1, a3, a4) {
let c19944_4 = a1.reduce((acc, a1) => {
let r48;
const id = a3?.id;
c8720_6(a4, id);
const soundId = a1.soundId;
const r17 = a0.toLocaleLowerCase();
let c27348_0 = r17;
const r27 = a1.name.toLocaleLowerCase();
const r30 = a1.emojiId != null ? EmojiStore.getCustomEmojiById(a1.emojiId) : null;
const r19 = a1.emojiName != null ? UnicodeEmojis.convertSurrogateToName(a1.emojiName, false) : null;
const r41 = r19 != null ? UnicodeEmojis.getByName(r19) : null;
if (r30 != null) {
r48 = [r30.name];
} else {
r48 = r41?.names;
if (r48 == null) {
r48 = [];
}
}
const r1 = r17 === r27 ? 8 : 0;
const r0 = r48.includes(r17) ? r1 + 7 : r1;
const r55 = r27.startsWith(r17) ? r0 + 6 : r0;
const r60 = r48.some((item) => item.startsWith(c27348_0)) ? r55 + 5 : r55;
const r64 = r27.endsWith(r17) ? r60 + 4 : r60;
const r69 = r48.some((item) => item.endsWith(c27348_0)) ? r64 + 3 : r64;
const r79 = fuzzysearch(r17, a1.name.toLocaleLowerCase()) ? r69 + 2 : r69;
const r84 = r48.some((item) => fuzzysearch(c27348_0, item)) ? r79 + 1 : r79;
let r86 = r84 > 0;
if (0 < r84) {
r86 = canUseSoundboardSound(c19944_1, a1, a3);
}
acc[soundId] = r86 ? r84 + 100 : r84;
return acc;
}, {});
const r22 = a1.filter((item) => c19944_4[item.soundId] > 0).sort((a, b) => c19944_4[b.soundId] - c19944_4[a.soundId]);
c8720_7(r22, a4, a3?.id, a0);
return r22;
}