From f4f27348067b070676d66188133d42600f97ca61 Mon Sep 17 00:00:00 2001 From: Nick <29809309+PrinceBunBun981@users.noreply.github.com> Date: Mon, 8 Apr 2024 12:50:20 -0400 Subject: [PATCH 1/4] Voice Chat Mention --- src/plugins/voiceChannelMention/index.tsx | 37 +++++++++++++++++++++++ src/utils/constants.ts | 4 +++ 2 files changed, 41 insertions(+) create mode 100644 src/plugins/voiceChannelMention/index.tsx diff --git a/src/plugins/voiceChannelMention/index.tsx b/src/plugins/voiceChannelMention/index.tsx new file mode 100644 index 000000000..024fb13d0 --- /dev/null +++ b/src/plugins/voiceChannelMention/index.tsx @@ -0,0 +1,37 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated, nickwoah, and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { Devs } from "@utils/constants"; +import { insertTextIntoChatInputBox } from "@utils/discord"; +import definePlugin from "@utils/types"; +import { findByPropsLazy } from "@webpack"; +import { Menu, UserStore } from "@webpack/common"; +import { Channel } from "discord-types/general"; + +const SortedVoiceStateStore = findByPropsLazy("getVoiceStatesForChannel"); + +async function getVoiceChannelMentions(channel: Channel) { + return await SortedVoiceStateStore.getVoiceStatesForChannel(channel).filter((value: any) => value.user.id !== UserStore.getCurrentUser().id).map((value: any) => { return `<@${value.user.id}>`; }).join(" "); +} + +export default definePlugin({ + name: "VoiceChatMention", + description: "Adds a context menu button to put mentions of all users in a voice chat in the text box.", + authors: [Devs.nickwoah], + contextMenus: { + "channel-context"(children, { channel }: { channel: Channel; }) { + if (channel.isVocal()) children.push( + { + insertTextIntoChatInputBox(await getVoiceChannelMentions(channel)); + }} + /> + ); + } + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f3626aaa0..12622ae53 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -425,6 +425,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ newwares: { name: "newwares", id: 421405303951851520n + }, + nickwoah: { + name: "nickwoah", + id: 644298972420374528n } } satisfies Record); From b3598e3a6a4e73e47cb51ea6224b1d7bc6b0c99c Mon Sep 17 00:00:00 2001 From: Nick <29809309+PrinceBunBun981@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:10:18 -0400 Subject: [PATCH 2/4] Split getVoiceChannelMentions into multiple lines --- src/plugins/voiceChannelMention/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/voiceChannelMention/index.tsx b/src/plugins/voiceChannelMention/index.tsx index 024fb13d0..1720464a8 100644 --- a/src/plugins/voiceChannelMention/index.tsx +++ b/src/plugins/voiceChannelMention/index.tsx @@ -14,7 +14,12 @@ import { Channel } from "discord-types/general"; const SortedVoiceStateStore = findByPropsLazy("getVoiceStatesForChannel"); async function getVoiceChannelMentions(channel: Channel) { - return await SortedVoiceStateStore.getVoiceStatesForChannel(channel).filter((value: any) => value.user.id !== UserStore.getCurrentUser().id).map((value: any) => { return `<@${value.user.id}>`; }).join(" "); + return await SortedVoiceStateStore.getVoiceStatesForChannel(channel) + .filter((value: any) => value.user.id !== UserStore.getCurrentUser().id) + .map((value: any) => { + return `<@${value.user.id}>`; + }) + .join(" "); } export default definePlugin({ From 57b397e053aae181581b2eb40d2ec9ec7e570914 Mon Sep 17 00:00:00 2001 From: Nick <29809309+PrinceBunBun981@users.noreply.github.com> Date: Wed, 10 Apr 2024 09:04:37 -0400 Subject: [PATCH 3/4] Rename the directory for consistency --- src/plugins/{voiceChannelMention => voiceChatMention}/index.tsx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{voiceChannelMention => voiceChatMention}/index.tsx (100%) diff --git a/src/plugins/voiceChannelMention/index.tsx b/src/plugins/voiceChatMention/index.tsx similarity index 100% rename from src/plugins/voiceChannelMention/index.tsx rename to src/plugins/voiceChatMention/index.tsx From 8fcfb9579a77b5dcc52f4f0abaec60af4734f2ab Mon Sep 17 00:00:00 2001 From: Nick <29809309+PrinceBunBun981@users.noreply.github.com> Date: Wed, 15 May 2024 15:49:48 -0400 Subject: [PATCH 4/4] Only show button when in VC --- src/plugins/voiceChatMention/index.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/plugins/voiceChatMention/index.tsx b/src/plugins/voiceChatMention/index.tsx index 1720464a8..50c8e6820 100644 --- a/src/plugins/voiceChatMention/index.tsx +++ b/src/plugins/voiceChatMention/index.tsx @@ -13,8 +13,8 @@ import { Channel } from "discord-types/general"; const SortedVoiceStateStore = findByPropsLazy("getVoiceStatesForChannel"); -async function getVoiceChannelMentions(channel: Channel) { - return await SortedVoiceStateStore.getVoiceStatesForChannel(channel) +function getVoiceChannelMentions(channel: Channel) { + return SortedVoiceStateStore.getVoiceStatesForChannel(channel) .filter((value: any) => value.user.id !== UserStore.getCurrentUser().id) .map((value: any) => { return `<@${value.user.id}>`; @@ -22,18 +22,23 @@ async function getVoiceChannelMentions(channel: Channel) { .join(" "); } +function isInVoiceChannel(channel: Channel) { + return SortedVoiceStateStore.getVoiceStatesForChannel(channel) + .some((value: any) => value.user.id == UserStore.getCurrentUser().id); +} + export default definePlugin({ name: "VoiceChatMention", - description: "Adds a context menu button to put mentions of all users in a voice chat in the text box.", + description: "Adds a context menu button to put mentions of all users in your voice chat in the text box.", authors: [Devs.nickwoah], contextMenus: { "channel-context"(children, { channel }: { channel: Channel; }) { - if (channel.isVocal()) children.push( + if (channel.isVocal() && isInVoiceChannel(channel)) children.push( { - insertTextIntoChatInputBox(await getVoiceChannelMentions(channel)); + insertTextIntoChatInputBox(getVoiceChannelMentions(channel)); }} /> );