Only show button when in VC

This commit is contained in:
Nick 2024-05-15 15:49:48 -04:00
parent e8e1a7e6f9
commit 8fcfb9579a

View file

@ -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(
<Menu.MenuItem
id="voice-mention-all-users"
label="Mention All Users"
action={async () => {
insertTextIntoChatInputBox(await getVoiceChannelMentions(channel));
insertTextIntoChatInputBox(getVoiceChannelMentions(channel));
}}
/>
);