diff --git a/src/plugins/webcamStartNotifier/index.ts b/src/plugins/webcamStartNotifier/index.ts index 2c3dfae59..bb2c2429f 100644 --- a/src/plugins/webcamStartNotifier/index.ts +++ b/src/plugins/webcamStartNotifier/index.ts @@ -4,9 +4,10 @@ * SPDX-License-Identifier: GPL-3.0-or-later */ -import definePlugin from "@utils/types"; -import { SelectedChannelStore } from "@webpack/common"; +import definePlugin, { OptionType } from "@utils/types"; +import { SelectedChannelStore, ChannelStore } from "@webpack/common"; import { Devs } from "@utils/constants"; +import { definePluginSettings } from "@api/Settings"; const startSound = "https://raw.githubusercontent.com/redbaron2k7/videoStartNotifier/117738bff76699a89531a067e321b6406bffbc88/start.mp3"; const stopSound = "https://raw.githubusercontent.com/redbaron2k7/videoStartNotifier/117738bff76699a89531a067e321b6406bffbc88/stop.mp3"; @@ -17,10 +18,24 @@ function playNotification(isVideoOn: boolean) { new Audio(isVideoOn ? startSound : stopSound).play(); } +const settings = definePluginSettings({ + playInPrivate: { + type: OptionType.BOOLEAN, + description: "Play notification sound in private voice calls (DMs)", + default: true + }, + playInServer: { + type: OptionType.BOOLEAN, + description: "Play notification sound in server voice channels", + default: true + } +}); + export default definePlugin({ name: "WebcamStartNotifier", description: "Plays a sound when someone starts/stops their webcam in a voice channel", authors: [Devs.redbaron2k7], + settings, flux: (() => { return { @@ -28,6 +43,16 @@ export default definePlugin({ const currentChannelId = SelectedChannelStore.getVoiceChannelId(); if (!currentChannelId) return; + const currentChannel = ChannelStore.getChannel(currentChannelId); + if (!currentChannel) return; + + const isPrivateChannel = currentChannel.type === 1 || currentChannel.type === 3; + + if ((isPrivateChannel && !settings.store.playInPrivate) || + (!isPrivateChannel && !settings.store.playInServer)) { + return; + } + voiceStates.forEach(state => { if (state.channelId !== currentChannelId) return;