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"); const SortedVoiceStateStore = findByPropsLazy("getVoiceStatesForChannel");
async function getVoiceChannelMentions(channel: Channel) { function getVoiceChannelMentions(channel: Channel) {
return await SortedVoiceStateStore.getVoiceStatesForChannel(channel) return SortedVoiceStateStore.getVoiceStatesForChannel(channel)
.filter((value: any) => value.user.id !== UserStore.getCurrentUser().id) .filter((value: any) => value.user.id !== UserStore.getCurrentUser().id)
.map((value: any) => { .map((value: any) => {
return `<@${value.user.id}>`; return `<@${value.user.id}>`;
@ -22,18 +22,23 @@ async function getVoiceChannelMentions(channel: Channel) {
.join(" "); .join(" ");
} }
function isInVoiceChannel(channel: Channel) {
return SortedVoiceStateStore.getVoiceStatesForChannel(channel)
.some((value: any) => value.user.id == UserStore.getCurrentUser().id);
}
export default definePlugin({ export default definePlugin({
name: "VoiceChatMention", 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], authors: [Devs.nickwoah],
contextMenus: { contextMenus: {
"channel-context"(children, { channel }: { channel: Channel; }) { "channel-context"(children, { channel }: { channel: Channel; }) {
if (channel.isVocal()) children.push( if (channel.isVocal() && isInVoiceChannel(channel)) children.push(
<Menu.MenuItem <Menu.MenuItem
id="voice-mention-all-users" id="voice-mention-all-users"
label="Mention All Users" label="Mention All Users"
action={async () => { action={async () => {
insertTextIntoChatInputBox(await getVoiceChannelMentions(channel)); insertTextIntoChatInputBox(getVoiceChannelMentions(channel));
}} }}
/> />
); );