// Metro module 13564 (f13565). import SoundboardStore from "../../../soundboard/SoundboardStore"; import UserStore from "../../../../stores/UserStore"; import * as _Constants from "../../Constants"; import { RPCCommands, RPCErrors } from "../../../../_bundle/Module505"; import { OAuth2Scopes } from "../../../../_bundle/Module8174"; import { maybeFetchSoundboardSounds } from "../../../soundboard/SoundboardActionCreators"; import { soundboardSoundToAPI } from "../../../soundboard/SoundboardTypes"; import createRpcJoiSchemaObject from "../../helpers/createRpcJoiSchemaObject"; import getCurrentVoiceChannel from "../../helpers/getCurrentVoiceChannel"; import { canUseSoundboardSound, playSound } from "../../../soundboard/SoundboardUtils"; import RPCError from "../../RPCError"; import canChannelUseSoundboard from "../../../soundboard/canChannelUseSoundboard"; import AnalyticsLocation from "../../../app_analytics/AnalyticsLocation"; function $mk116547($env) { return (a0) => a0.forEach.call(a0, $mk118397($env)); } function $mk118397($env) { return (a0) => { const r3 = $env[1]; return r3.push(soundboardSoundToAPI(a0)); }; } let env9421 = {}; const { RPC_LOCAL_SCOPE, RPC_SCOPE_CONFIG } = _Constants; const r30 = {}; const GET_SOUNDBOARD_SOUNDS = RPCCommands.GET_SOUNDBOARD_SOUNDS; const scope = {}; scope[RPC_SCOPE_CONFIG.ANY] = [OAuth2Scopes.RPC, RPC_LOCAL_SCOPE]; r30[GET_SOUNDBOARD_SOUNDS] = { scope, handler: async () => { let env30646; const r21 = env9421; let c27511_1 = r21; const r10 = env30646 = { $parent: r21 }; let c27511_0 = r10; env30646[0] = void 0; env30646[1] = void 0; await maybeFetchSoundboardSounds(); env30646[0] = SoundboardStore.getSounds(); env30646[1] = []; env30646[0].forEach($mk116547(c27511_0)); return env30646[1]; } }; const PLAY_SOUNDBOARD_SOUND = RPCCommands.PLAY_SOUNDBOARD_SOUND; const scope2 = {}; scope2[RPC_SCOPE_CONFIG.ALL] = [OAuth2Scopes.RPC, OAuth2Scopes.RPC_VOICE_WRITE]; r30[PLAY_SOUNDBOARD_SOUND] = { scope: scope2, validation: (a0) => createRpcJoiSchemaObject(a0).required().keys({ guild_id: a0.string(), sound_id: a0.string() }), handler: async ({ args }) => { const { guild_id, sound_id } = args; let c27512_1; c27512_1 = void 0; await maybeFetchSoundboardSounds(); let c30647_0 = UserStore.getCurrentUser(); let c30647_1 = SoundboardStore.getSound(guild_id, sound_id); let c30647_2 = getCurrentVoiceChannel(); let c30647_3 = c30647_1 != null && c30647_0 != null && canUseSoundboardSound(c30647_0, c30647_1, c30647_2); if (c30647_2 == null) { throw new RPCError({ errorCode: RPCErrors.INVALID_CHANNEL }, "Invalid Channel."); } if (!c30647_3) { throw new RPCError({ errorCode: RPCErrors.INVALID_SOUND }, "Invalid Sound."); } if (!canChannelUseSoundboard(c30647_2)) { throw new RPCError({ errorCode: RPCErrors.INVALID_PERMISSIONS }, "Invalid Permissions."); } if (c30647_1 != null) { playSound(c30647_1, c30647_2.id, [AnalyticsLocation.RPC]); } } }; export default r30;