decord/source/modules/soundboard/SoundboardStore.tsx

433 lines
14 KiB
TypeScript
Raw Normal View History

2026-08-24 06:08:38 +00:00
// Module ID: 4785
// Function ID: 4786
2026-07-29 08:29:29 +00:00
// Name: handleSoundCreateOrUpdate
2026-08-24 06:08:38 +00:00
// Dependencies: [32, 1340, 1922, 4786, 676, 685, 4561, 3978, 12, 698, 4787, 4069, 11, 589, 709, 2]
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
// Module 4785 (handleSoundCreateOrUpdate)
import DISCORD_EPOCHDefault from "DISCORD_EPOCH" /* 11 */;
import applyDefault from "apply" /* 12 */;
import initializeDefault from "initialize" /* 589 */;
import expandEventPropertiesDefault from "expandEventProperties" /* 698 */;
import dispatcherDefault from "dispatcher" /* 709 */;
import tDefault from "t" /* 3978 */;
import explicitContentFromProto from "explicitContentFromProto" /* 4069 */;
import DEFAULT_FRECENCYDefault from "DEFAULT_FRECENCY" /* 4561 */;
import perceptualToAmplitude from "perceptualToAmplitude" /* 4787 */;
import closure_3 from "_slicedToArray" /* 32 */;
import closure_4 from "handleConnectionClosedOrResumed" /* 1340 */;
import closure_5 from "mergeGuildAvatar" /* 1922 */;
import { DEFAULT_SOUND_GUILD_ID } from "MAX_LENGTH_SOUND_NAME" /* 4786 */;
import { AnalyticEvents } from "ME" /* 676 */;
import { UserSettingsTypes } from "MAX_FAVORITES" /* 685 */;
import closure_17 from "module_2026" /* 2026 */;
import set from "set" /* 2 */;
2026-07-20 16:05:17 +00:00
2026-08-24 06:08:38 +00:00
require = arg1;
2026-07-20 16:05:17 +00:00
function handleSoundCreateOrUpdate(sound) {
sound = sound.sound;
const value = map.get(sound.guildId);
2026-07-29 08:29:29 +00:00
if (value != null) {
2026-07-20 16:05:17 +00:00
const findIndexResult = value.findIndex((soundId) => soundId.soundId === sound.soundId);
}
if (null != value) {
if (null != findIndexResult) {
if (-1 !== findIndexResult) {
value[findIndexResult] = sound;
const items = [];
HermesBuiltin.arraySpread(value, 0);
const result = map.set(sound.guildId, items);
}
}
}
if (null != value) {
2026-07-29 08:29:29 +00:00
if (value != null) {
2026-07-20 16:05:17 +00:00
value.push(sound);
}
const items1 = [];
HermesBuiltin.arraySpread(value, 0);
const result1 = map.set(sound.guildId, items1);
}
}
function syncLocalSoundboardMutesFromUserSettings(proto) {
let user;
2026-07-29 08:29:29 +00:00
if (proto != null) {
2026-07-20 16:05:17 +00:00
const audioContextSettings = proto.audioContextSettings;
2026-07-29 08:29:29 +00:00
if (audioContextSettings != null) {
2026-07-20 16:05:17 +00:00
user = audioContextSettings.user;
}
}
2026-07-29 08:29:29 +00:00
if (user == null) {
2026-07-20 16:05:17 +00:00
user = {};
}
const entries = Object.entries(user);
2026-07-29 08:29:29 +00:00
while (tmp2 !== undefined) {
let tmp4 = callback;
let tmp5 = callback(tmp3, 2);
let first = tmp5[0];
2026-07-20 16:05:17 +00:00
let obj2 = set;
2026-07-29 08:29:29 +00:00
if (tmp5[1].soundboardMuted) {
let tmp9 = first;
2026-07-20 16:05:17 +00:00
let addResult = obj2.add(first);
} else {
2026-07-29 08:29:29 +00:00
let tmp7 = first;
2026-07-20 16:05:17 +00:00
let deleteResult = obj2.delete(first);
}
2026-07-29 08:29:29 +00:00
continue;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
const keys = set.keys();
for (const item10038 of keys) {
if (null == user[item10038]) {
let tmp13 = set;
let tmp14 = item10038;
let deleteResult1 = set.delete(tmp12);
}
continue;
2026-07-20 16:05:17 +00:00
}
}
let obj = { NOT_FETCHED: 0, [0]: "NOT_FETCHED", FETCHING: 1, [1]: "FETCHING", FETCHED: 2, [2]: "FETCHED" };
2026-07-23 10:11:24 +00:00
let map = new Map();
2026-07-29 08:29:29 +00:00
map1 = new Map();
2026-07-23 10:11:24 +00:00
let set = new Set();
2026-07-29 08:29:29 +00:00
({ NOT_FETCHED: map1, NOT_FETCHED: closure_14 } = obj);
2026-07-23 10:11:24 +00:00
let set1 = new Set();
2026-07-20 16:05:17 +00:00
const map2 = new Map();
obj = {
computeBonus() {
return 100;
},
computeWeight(arg0) {
2026-08-24 06:08:38 +00:00
if (arg0 > obj.diff(closure_17, "days")) {
2026-07-20 16:05:17 +00:00
return 0;
} else {
let num2 = 100;
if (arg0 > 3) {
num2 = 70;
if (arg0 > 15) {
num2 = 50;
if (arg0 > 30) {
num2 = 30;
if (arg0 > 45) {
num2 = 1;
if (arg0 <= 80) {
num2 = 10;
}
}
}
}
}
return num2;
}
2026-08-24 06:08:38 +00:00
obj = tDefault();
2026-07-20 16:05:17 +00:00
},
lookupKey(arg0) {
return arg0;
},
afterCompute() {
}
};
2026-08-24 06:08:38 +00:00
let closure_18 = new DEFAULT_FRECENCYDefault(obj);
2026-07-29 08:29:29 +00:00
let closure_19 = [];
let c20 = false;
let c21 = false;
2026-08-24 06:08:38 +00:00
let tmp7 = new DEFAULT_FRECENCYDefault(obj);
let closure_22 = applyDefault.debounce((volume) => {
obj = expandEventPropertiesDefault;
obj = { volume: Math.round(perceptualToAmplitude.amplitudeToPerceptual(volume)), location_stack: arg1 };
2026-07-20 16:05:17 +00:00
obj.track(AnalyticEvents.UPDATE_SOUNDBOARD_SETTINGS, obj);
2026-08-24 06:08:38 +00:00
const SoundboardSettings = explicitContentFromProto.SoundboardSettings;
2026-07-20 16:05:17 +00:00
obj = { volume };
SoundboardSettings.updateSetting(obj);
}, 1000);
2026-08-24 06:08:38 +00:00
const Store = initializeDefault.Store;
2026-07-29 08:29:29 +00:00
class SoundboardStore extends Store {
}
const prototype = SoundboardStore.prototype;
prototype["initialize"] = function initialize() {
2026-08-24 06:08:38 +00:00
this.waitFor(settings, closure_5);
2026-07-29 08:29:29 +00:00
syncLocalSoundboardMutesFromUserSettings(settings.settings);
2026-08-24 06:08:38 +00:00
const SoundboardSettings = explicitContentFromProto.SoundboardSettings;
2026-07-29 08:29:29 +00:00
const setting = SoundboardSettings.getSetting();
let volume;
if (setting != null) {
volume = setting.volume;
2026-07-20 16:05:17 +00:00
}
2026-08-24 06:08:38 +00:00
closure_21 = 0 === volume;
2026-07-29 08:29:29 +00:00
};
prototype["getOverlaySerializedState"] = function getOverlaySerializedState() {
return { soundboardSounds: Object.fromEntries(map), favoritedSoundIds: Array.from(set1), localSoundboardMutes: Array.from(set) };
};
prototype["getSounds"] = function getSounds() {
return map;
};
prototype["getSoundsForGuild"] = function getSoundsForGuild(arg0) {
return map.get(arg0);
};
prototype["getSound"] = function getSound(arg0, arg1) {
2026-08-24 06:08:38 +00:00
closure_0 = arg1;
2026-07-29 08:29:29 +00:00
let items = map.get(arg0);
if (items == null) {
items = [];
}
return items.find((soundId) => soundId.soundId === closure_0);
};
prototype["getSoundById"] = function getSoundById(soundId) {
2026-08-24 06:08:38 +00:00
closure_0 = soundId;
2026-07-29 08:29:29 +00:00
const arr = Array.from(map.values());
return Array.from(map.values()).flat().find((soundId) => soundId.soundId === closure_0);
};
prototype["isFetchingSounds"] = function isFetchingSounds() {
return closure_14 === obj.FETCHING;
};
prototype["isFetchingDefaultSounds"] = function isFetchingDefaultSounds() {
return closure_13 === obj.FETCHING;
};
prototype["isFetching"] = function isFetching() {
const self = this;
return this.isFetchingSounds() || self.isFetchingDefaultSounds();
};
prototype["shouldFetchDefaultSounds"] = function shouldFetchDefaultSounds() {
return closure_13 === obj.NOT_FETCHED;
};
prototype["hasFetchedDefaultSounds"] = function hasFetchedDefaultSounds() {
return closure_13 === obj.FETCHED;
};
prototype["isUserPlayingSounds"] = function isUserPlayingSounds(closure_0) {
const value = map2.get(closure_0);
let tmp2 = null != value;
if (tmp2) {
tmp2 = value > 0;
}
return tmp2;
};
prototype["isPlayingSound"] = function isPlayingSound(soundId) {
return null != map1.get(soundId);
};
prototype["isFavoriteSound"] = function isFavoriteSound(soundId) {
return set1.has(soundId);
};
prototype["getFavorites"] = function getFavorites() {
return set1;
};
prototype["getFrequentlyUsedSoundIds"] = function getFrequentlyUsedSoundIds() {
2026-08-24 06:08:38 +00:00
return closure_18.frequently;
2026-07-29 08:29:29 +00:00
};
prototype["hasPendingUsage"] = function hasPendingUsage() {
return arr.length > 0;
};
Object.defineProperty(prototype, "playedSoundFrecencyWithoutFetchingLatest", {
get: function playedSoundFrecencyWithoutFetchingLatest() {
return closure_18;
},
set: undefined
});
prototype["isLocalSoundboardMuted"] = function isLocalSoundboardMuted(id) {
return set.has(id);
};
prototype["isSoundboardVolumeMuted"] = function isSoundboardVolumeMuted() {
return c21;
};
prototype["hasHadOtherUserPlaySoundInSession"] = function hasHadOtherUserPlaySoundInSession() {
return c20;
};
prototype["hasFetchedAllSounds"] = function hasFetchedAllSounds() {
let tmp2 = closure_14 === obj.FETCHED;
if (tmp2) {
tmp2 = closure_13 === tmp.FETCHED;
}
return tmp2;
};
prototype["isFetchingAnySounds"] = function isFetchingAnySounds() {
let tmp2 = closure_14 === obj.FETCHING;
if (!tmp2) {
tmp2 = closure_13 === tmp.FETCHING;
}
return tmp2;
};
SoundboardStore.displayName = "SoundboardStore";
2026-07-20 16:05:17 +00:00
obj = {
LOGOUT: function handleReset() {
map.clear();
map1.clear();
map2.clear();
2026-08-24 06:08:38 +00:00
c20 = false;
2026-07-29 08:29:29 +00:00
({ NOT_FETCHED: closure_14, NOT_FETCHED: closure_13 } = obj);
2026-08-24 06:08:38 +00:00
c21 = false;
closure_19 = [];
closure_18.overwriteHistory({});
2026-07-20 16:05:17 +00:00
},
GUILD_SOUNDBOARD_FETCH: function handleSoundboardFetch() {
const FETCHING = obj.FETCHING;
},
GUILD_SOUNDBOARD_SOUND_CREATE: handleSoundCreateOrUpdate,
GUILD_SOUNDBOARD_SOUND_UPDATE: handleSoundCreateOrUpdate,
GUILD_SOUNDBOARD_SOUND_DELETE: function handleSoundDelete(arg0) {
2026-07-23 10:11:24 +00:00
({ soundId: require, guildId } = arg0);
2026-07-20 16:05:17 +00:00
const value = map.get(guildId);
let findIndexResult;
2026-07-29 08:29:29 +00:00
if (value != null) {
2026-07-20 16:05:17 +00:00
findIndexResult = value.findIndex((soundId) => soundId.soundId === closure_0);
}
let tmp2 = null == value || null == findIndexResult;
if (!tmp2) {
tmp2 = findIndexResult < 0;
}
if (!tmp2) {
value.splice(findIndexResult, 1);
const items = [];
HermesBuiltin.arraySpread(value, 0);
const result = map.set(guildId, items);
}
},
GUILD_SOUNDBOARD_SOUND_PLAY_START: function handleSoundPlayStart(arg0) {
({ soundId, userId } = arg0);
2026-07-29 08:29:29 +00:00
let num = map1.get(soundId);
if (num == null) {
num = 0;
2026-07-20 16:05:17 +00:00
}
const sum = num + 1;
2026-07-29 08:29:29 +00:00
let num2 = map2.get(userId);
if (num2 == null) {
num2 = 0;
2026-07-20 16:05:17 +00:00
}
const sum1 = num2 + 1;
const result = map1.set(soundId, sum);
const result1 = map2.set(userId, sum1);
2026-07-23 10:11:24 +00:00
currentUser = currentUser.getCurrentUser();
2026-07-20 16:05:17 +00:00
let id;
2026-07-29 08:29:29 +00:00
if (currentUser != null) {
2026-07-20 16:05:17 +00:00
id = currentUser.id;
}
if (userId !== id) {
2026-08-24 06:08:38 +00:00
c20 = true;
2026-07-20 16:05:17 +00:00
}
},
GUILD_SOUNDBOARD_SOUND_PLAY_END: function handleSoundPlayEnd(arg0) {
({ soundId, userId } = arg0);
2026-07-29 08:29:29 +00:00
let num = map1.get(soundId);
if (num == null) {
num = 0;
2026-07-20 16:05:17 +00:00
}
const diff = num - 1;
2026-07-29 08:29:29 +00:00
let num2 = map2.get(userId);
if (num2 == null) {
num2 = 0;
2026-07-20 16:05:17 +00:00
}
const diff1 = num2 - 1;
if (diff <= 0) {
2026-07-29 08:29:29 +00:00
obj.delete(soundId);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
const result = obj.set(soundId, diff);
2026-07-20 16:05:17 +00:00
}
if (diff1 <= 0) {
2026-07-29 08:29:29 +00:00
obj2.delete(userId);
2026-07-20 16:05:17 +00:00
} else {
2026-07-29 08:29:29 +00:00
const result1 = obj2.set(userId, diff1);
2026-07-20 16:05:17 +00:00
}
},
GUILD_SOUNDBOARD_SOUNDS_UPDATE: function handleSoundsUpdate(guildId) {
const result = map.set(guildId.guildId, guildId.soundboardSounds);
},
USER_SOUNDBOARD_SET_VOLUME: function handleSetLocalVolume(volume) {
volume = volume.volume;
2026-08-24 06:08:38 +00:00
closure_21 = 0 === volume;
2026-07-29 08:29:29 +00:00
callback2(volume, volume.location);
if (closure_21 !== closure_21) {
callback2.flush();
2026-07-20 16:05:17 +00:00
}
},
SOUNDBOARD_TRACK_USAGE: function handleTrackUsage(soundId) {
soundId = soundId.soundId;
2026-08-24 06:08:38 +00:00
closure_18.track(soundId);
obj = { key: soundId, timestamp: Date.now() };
closure_18.compute();
2026-07-20 16:05:17 +00:00
},
VOICE_CHANNEL_SELECT: function handleVoiceChannelSelect() {
map1.clear();
map2.clear();
},
USER_SETTINGS_PROTO_UPDATE: function handleUserSettingsProtoUpdate(settings) {
({ type, proto } = settings.settings);
if (UserSettingsTypes.FRECENCY_AND_FAVORITES_SETTINGS === type) {
let soundIds;
2026-07-29 08:29:29 +00:00
if (proto != null) {
2026-07-20 16:05:17 +00:00
const favoriteSoundboardSounds = proto.favoriteSoundboardSounds;
2026-07-29 08:29:29 +00:00
if (favoriteSoundboardSounds != null) {
2026-07-20 16:05:17 +00:00
soundIds = favoriteSoundboardSounds.soundIds;
}
}
2026-07-29 08:29:29 +00:00
if (soundIds == null) {
2026-07-20 16:05:17 +00:00
soundIds = [];
}
2026-08-24 06:08:38 +00:00
set = new Set(soundIds);
2026-07-20 16:05:17 +00:00
if (tmp) {
2026-08-24 06:08:38 +00:00
closure_19 = [];
2026-07-20 16:05:17 +00:00
}
let playedSoundFrecency;
2026-07-29 08:29:29 +00:00
if (proto != null) {
2026-07-20 16:05:17 +00:00
playedSoundFrecency = proto.playedSoundFrecency;
}
if (null != playedSoundFrecency) {
let playedSounds = proto.playedSoundFrecency.playedSounds;
2026-07-29 08:29:29 +00:00
if (playedSounds == null) {
2026-07-20 16:05:17 +00:00
playedSounds = {};
}
2026-08-24 06:08:38 +00:00
closure_18.overwriteHistory(applyDefault.mapValues(playedSounds, (recentUses) => {
obj = {};
2026-07-20 16:05:17 +00:00
const merged = Object.assign(recentUses);
recentUses = recentUses.recentUses;
const mapped = recentUses.map(Number);
2026-07-29 08:29:29 +00:00
obj.recentUses = mapped.filter((arg0) => arg0 > 0);
2026-07-20 16:05:17 +00:00
return obj;
2026-07-29 08:29:29 +00:00
}), closure_19);
2026-08-24 06:08:38 +00:00
obj = applyDefault;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
} else if (tmp2.PRELOADED_USER_SETTINGS === type) {
2026-07-20 16:05:17 +00:00
syncLocalSoundboardMutesFromUserSettings(proto);
2026-08-24 06:08:38 +00:00
const SoundboardSettings = explicitContentFromProto.SoundboardSettings;
2026-07-29 08:29:29 +00:00
const setting = SoundboardSettings.getSetting();
let volume;
if (setting != null) {
volume = setting.volume;
}
2026-08-24 06:08:38 +00:00
closure_21 = 0 === volume;
2026-07-20 16:05:17 +00:00
}
},
SOUNDBOARD_FETCH_DEFAULT_SOUNDS: function handleFetchDefaultSounds() {
const FETCHING = obj.FETCHING;
},
SOUNDBOARD_FETCH_DEFAULT_SOUNDS_SUCCESS: function handleFetchDefaultSoundsSuccess(soundboardSounds) {
const result = map.set(DEFAULT_SOUND_GUILD_ID, soundboardSounds.soundboardSounds);
const FETCHED = obj.FETCHED;
},
SOUNDBOARD_SOUNDS_RECEIVED: function handleSoundboardSoundsReceived(updates) {
updates = updates.updates;
const item = updates.forEach((guildId) => {
2026-07-29 08:29:29 +00:00
const result = closure_10.set(guildId.guildId, guildId.sounds);
2026-07-20 16:05:17 +00:00
});
const FETCHED = obj.FETCHED;
},
GUILD_DELETE: function handleGuildDelete(guild) {
map.delete(guild.guild.id);
},
AUDIO_TOGGLE_LOCAL_SOUNDBOARD_MUTE: function handleToggleLocalSoundboardMute(userId) {
userId = userId.userId;
if (set.has(userId)) {
obj.delete(userId);
} else {
obj.add(userId);
}
},
OVERLAY_INITIALIZE: function handleOverlayInitialize(soundboardStoreState) {
soundboardStoreState = soundboardStoreState.soundboardStoreState;
2026-08-24 06:08:38 +00:00
map = new Map(DISCORD_EPOCHDefault.entries(soundboardStoreState.soundboardSounds));
set = new Set(soundboardStoreState.favoritedSoundIds);
set1 = new Set(soundboardStoreState.localSoundboardMutes);
2026-07-20 16:05:17 +00:00
}
};
2026-08-24 06:08:38 +00:00
const soundboardStore = new SoundboardStore(dispatcherDefault, obj);
2026-07-23 10:11:24 +00:00
let result = set.fileFinishedImporting("modules/soundboard/SoundboardStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default soundboardStore;
2026-07-20 16:05:17 +00:00
export const FetchState = obj;