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] 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)); }} /> );