diff options
Diffstat (limited to 'src/plugins/vcNarrator.tsx')
-rw-r--r-- | src/plugins/vcNarrator.tsx | 95 |
1 files changed, 44 insertions, 51 deletions
diff --git a/src/plugins/vcNarrator.tsx b/src/plugins/vcNarrator.tsx index f55f639..a318e89 100644 --- a/src/plugins/vcNarrator.tsx +++ b/src/plugins/vcNarrator.tsx @@ -24,7 +24,7 @@ import { Margins } from "@utils/margins"; import { wordsToTitle } from "@utils/text"; import definePlugin, { OptionType, PluginOptionsItem } from "@utils/types"; import { findByPropsLazy } from "@webpack"; -import { Button, ChannelStore, FluxDispatcher, Forms, SelectedChannelStore, useMemo, UserStore } from "@webpack/common"; +import { Button, ChannelStore, Forms, SelectedChannelStore, useMemo, UserStore } from "@webpack/common"; interface VoiceState { userId: string; @@ -137,59 +137,61 @@ function updateStatuses(type: string, { deaf, mute, selfDeaf, selfMute, userId, } */ -function handleVoiceStates({ voiceStates }: { voiceStates: VoiceState[]; }) { - const myChanId = SelectedChannelStore.getVoiceChannelId(); - const myId = UserStore.getCurrentUser().id; +function playSample(tempSettings: any, type: string) { + const settings = Object.assign({}, Settings.plugins.VcNarrator, tempSettings); - for (const state of voiceStates) { - const { userId, channelId, oldChannelId } = state; - const isMe = userId === myId; - if (!isMe) { - if (!myChanId) continue; - if (channelId !== myChanId && oldChannelId !== myChanId) continue; - } + speak(formatText(settings[type + "Message"], UserStore.getCurrentUser().username, "general"), settings); +} - const [type, id] = getTypeAndChannelId(state, isMe); - if (!type) continue; +export default definePlugin({ + name: "VcNarrator", + description: "Announces when users join, leave, or move voice channels via narrator", + authors: [Devs.Ven], - const template = Settings.plugins.VcNarrator[type + "Message"]; - const user = isMe ? "" : UserStore.getUser(userId).username; - const channel = ChannelStore.getChannel(id).name; + flux: { + VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) { + const myChanId = SelectedChannelStore.getVoiceChannelId(); + const myId = UserStore.getCurrentUser().id; - speak(formatText(template, user, channel)); + for (const state of voiceStates) { + const { userId, channelId, oldChannelId } = state; + const isMe = userId === myId; + if (!isMe) { + if (!myChanId) continue; + if (channelId !== myChanId && oldChannelId !== myChanId) continue; + } - // updateStatuses(type, state, isMe); - } -} + const [type, id] = getTypeAndChannelId(state, isMe); + if (!type) continue; -function handleToggleSelfMute() { - const chanId = SelectedChannelStore.getVoiceChannelId()!; - const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState; - if (!s) return; + const template = Settings.plugins.VcNarrator[type + "Message"]; + const user = isMe ? "" : UserStore.getUser(userId).username; + const channel = ChannelStore.getChannel(id).name; - const event = s.mute || s.selfMute ? "unmute" : "mute"; - speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name)); -} + speak(formatText(template, user, channel)); -function handleToggleSelfDeafen() { - const chanId = SelectedChannelStore.getVoiceChannelId()!; - const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState; - if (!s) return; + // updateStatuses(type, state, isMe); + } + }, - const event = s.deaf || s.selfDeaf ? "undeafen" : "deafen"; - speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name)); -} + AUDIO_TOGGLE_SELF_MUTE() { + const chanId = SelectedChannelStore.getVoiceChannelId()!; + const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState; + if (!s) return; -function playSample(tempSettings: any, type: string) { - const settings = Object.assign({}, Settings.plugins.VcNarrator, tempSettings); + const event = s.mute || s.selfMute ? "unmute" : "mute"; + speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name)); + }, - speak(formatText(settings[type + "Message"], UserStore.getCurrentUser().username, "general"), settings); -} + AUDIO_TOGGLE_SELF_DEAF() { + const chanId = SelectedChannelStore.getVoiceChannelId()!; + const s = VoiceStateStore.getVoiceStateForChannel(chanId) as VoiceState; + if (!s) return; -export default definePlugin({ - name: "VcNarrator", - description: "Announces when users join, leave, or move voice channels via narrator", - authors: [Devs.Ven], + const event = s.deaf || s.selfDeaf ? "undeafen" : "deafen"; + speak(formatText(Settings.plugins.VcNarrator[event + "Message"], "", ChannelStore.getChannel(chanId).name)); + } + }, start() { if (typeof speechSynthesis === "undefined" || speechSynthesis.getVoices().length === 0) { @@ -199,15 +201,6 @@ export default definePlugin({ return; } - FluxDispatcher.subscribe("VOICE_STATE_UPDATES", handleVoiceStates); - FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_MUTE", handleToggleSelfMute); - FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_DEAF", handleToggleSelfDeafen); - }, - - stop() { - FluxDispatcher.unsubscribe("VOICE_STATE_UPDATES", handleVoiceStates); - FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_MUTE", handleToggleSelfMute); - FluxDispatcher.subscribe("AUDIO_TOGGLE_SELF_DEAF", handleToggleSelfDeafen); }, optionsCache: null as Record<string, PluginOptionsItem> | null, |