From 89690367cbd9888ceb2c3aa546aa5a313099a5a3 Mon Sep 17 00:00:00 2001 From: verticalsync <60797172+verticalsync@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:00:26 +0200 Subject: [PATCH] feat(plugin): VoiceChatUtilities --- readme.md | 1 + src/plugins/voiceChatUtilities/README.md | 5 + src/plugins/voiceChatUtilities/index.tsx | 137 +++++++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 src/plugins/voiceChatUtilities/README.md create mode 100644 src/plugins/voiceChatUtilities/index.tsx diff --git a/readme.md b/readme.md index 4d4d9bfc..59f9d0a0 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,7 @@ Suncord is a fork of [Vencord](https://github.com/Vendicated/Vencord). - ReplyTimestamp (by [Kyuuhachi](https://github.com/Kyuuhachi/)) - SoundBoardLogger (by [ImpishMoxxie](https://github.com/ImpishMoxxie/SoundBoardLogger)) - MemberListActivities (by [D3SOX](https://github.com/D3SOX/vencord-userplugins/)) +- VoiceChatUtilities (by [D3SOX](https://github.com/D3SOX/vencord-userplugins/)) ## Installing / Uninstalling diff --git a/src/plugins/voiceChatUtilities/README.md b/src/plugins/voiceChatUtilities/README.md new file mode 100644 index 00000000..5329ff2e --- /dev/null +++ b/src/plugins/voiceChatUtilities/README.md @@ -0,0 +1,5 @@ +# VoiceChatUtilities + +Allows you to perform multiple actions on an entire channel (move, mute, disconnect, etc.) + +![Screenshot](https://user-images.githubusercontent.com/60252259/224880206-9f923f0c-9939-4e1b-81ad-70167f0ee6d4.png) diff --git a/src/plugins/voiceChatUtilities/index.tsx b/src/plugins/voiceChatUtilities/index.tsx new file mode 100644 index 00000000..aad5f7e9 --- /dev/null +++ b/src/plugins/voiceChatUtilities/index.tsx @@ -0,0 +1,137 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addContextMenuPatch, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu"; +import { Devs } from "@utils/constants"; +import definePlugin from "@utils/types"; +import { findStoreLazy } from "@webpack"; +import { GuildChannelStore, Menu, React, RestAPI, UserStore } from "@webpack/common"; +import type { Channel } from "discord-types/general"; + +const VoiceStateStore = findStoreLazy("VoiceStateStore"); + +function sendPatch(channel: Channel, body: Record, bypass = false) { + const usersVoice = VoiceStateStore.getVoiceStatesForChannel(channel.id); // Get voice states by channel id + const myId = UserStore.getCurrentUser().id; // Get my user id + + Object.keys(usersVoice).forEach((key, index) => { + const userVoice = usersVoice[key]; + + if (bypass || userVoice.userId !== myId) { + setTimeout(() => { + RestAPI.patch({ + url: `/guilds/${channel.guild_id}/members/${userVoice.userId}`, + body: body + }); + }, index * 500); + } + }); +} + +interface VoiceChannelContextProps { + channel: Channel; +} + +const VoiceChannelContext: NavContextMenuPatchCallback = (children, { channel }: VoiceChannelContextProps) => () => { + // only for voice and stage channels + if (!channel || (channel.type !== 2 && channel.type !== 13)) return; + const userCount = Object.keys(VoiceStateStore.getVoiceStatesForChannel(channel.id)).length; + if (userCount === 0) return; + + const guildChannels: { VOCAL: { channel: Channel, comparator: number; }[]; } = GuildChannelStore.getChannels(channel.guild_id); + const voiceChannels = guildChannels.VOCAL.map(({ channel }) => channel).filter(({ id }) => id !== channel.id); + + children.splice( + -1, + 0, + + sendPatch(channel, { + channel_id: null, + })} + /> + + sendPatch(channel, { + mute: true, + })} + /> + + sendPatch(channel, { + mute: false, + })} + /> + + sendPatch(channel, { + deaf: true, + })} + /> + + sendPatch(channel, { + deaf: false, + })} + /> + + + {voiceChannels.map(voiceChannel => { + return ( + sendPatch(channel, { + channel_id: voiceChannel.id, + }, true)} + /> + ); + })} + + + + ); +}; + + + +export default definePlugin({ + name: "VoiceChatUtilities", + description: "This plugin allows you to perform multiple actions on an entire channel (move, mute, disconnect, etc.) (originally by dutake)", + authors: [{ name: "! 𝕯'𝖆𝖒𝖘", id: 769939285792653325n }, Devs.D3SOX], + + start() { + addContextMenuPatch("channel-context", VoiceChannelContext); + }, + + stop() { + removeContextMenuPatch("channel-context", VoiceChannelContext); + }, +});