diff options
author | V <vendicated@riseup.net> | 2023-04-22 03:18:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-22 01:18:19 +0000 |
commit | 63fc354d483b86857bbee7f540c66ba614fc0f1f (patch) | |
tree | 6ebe100e5ff63254adfdb0c44cb473dcc339cf35 /src/plugins/vcNarrator.tsx | |
parent | c6f0c84935db37e2a18578a081404d84292fe36a (diff) | |
download | Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.gz Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.tar.bz2 Vencord-63fc354d483b86857bbee7f540c66ba614fc0f1f.zip |
feat: auto-managed flux subscriptions via plugin.flux (#959)
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, |