forked from Vendicated/Vencord
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'askMeToMute' into sqaaakoi-stable-v2
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Vencord, a Discord client mod | ||
* Copyright (c) 2024 Vendicated and contributors | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
*/ | ||
|
||
import { Devs } from "@utils/constants"; | ||
import definePlugin from "@utils/types"; | ||
import { findByPropsLazy } from "@webpack"; | ||
import { PermissionsBits, PermissionStore, UserStore } from "@webpack/common"; | ||
|
||
const { toggleSelfMute } = findByPropsLazy("toggleSelfMute"); | ||
const { setServerMute } = findByPropsLazy("setServerMute"); | ||
|
||
interface VoiceState { | ||
guildId?: string; | ||
channelId?: string; | ||
mute: boolean; | ||
selfMute: boolean; | ||
userId: string; | ||
} | ||
|
||
export default definePlugin({ | ||
name: "AskMeToMute", | ||
description: "Mute yourself when moderators server mute you, and automatically remove your server mute if you have permission.", | ||
authors: [Devs.Sqaaakoi], | ||
|
||
flux: { | ||
VOICE_STATE_UPDATES({ voiceStates }: { voiceStates: VoiceState[]; }) { | ||
if (!voiceStates) return; | ||
voiceStates.forEach(state => { | ||
if (state.userId !== UserStore.getCurrentUser().id) return; | ||
if (!state.guildId) return; | ||
if (!(state.mute && !state.selfMute)) return; | ||
toggleSelfMute({ playSoundEffect: false }); | ||
if (PermissionStore.canWithPartialContext(PermissionsBits.MUTE_MEMBERS, { channelId: state.channelId })) setServerMute(state.guildId, state.userId, false); | ||
}); | ||
} | ||
} | ||
}); |