Skip to content

Commit

Permalink
Merge branch 'autoMute' into sqaaakoi-stable-v2 (stupid submodule fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sqaaakoi committed Jul 21, 2024
2 parents 78f6b1b + b16cb25 commit cdfef56
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/plugins/autoMute/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { definePluginSettings } from "@api/Settings";
import { makeRange } from "@components/PluginSettings/components";
import { clearableDebounce, debounce } from "@shared/debounce";
import { Devs } from "@utils/constants";
import { humanFriendlyJoin } from "@utils/text";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy, findStoreLazy } from "@webpack";
import { Menu, RelationshipStore, SelectedChannelStore, Toasts, UserStore } from "@webpack/common";
import { ChannelStore, GuildMemberStore, Menu, RelationshipStore, SelectedChannelStore, Toasts, UserStore } from "@webpack/common";
import { User } from "discord-types/general";

const { toggleSelfMute } = findByPropsLazy("toggleSelfMute");
Expand Down Expand Up @@ -44,7 +45,7 @@ interface VoiceState {

const enum AutoMuteReasons {
Inactivity = "You have been silent for a while, so your mic has been automatically muted.",
NonFriend = "A user who isn't your friend has joined your voice channel, so your mic has been automatically muted."
NonFriend = "[USER] who isn't your friend has joined your voice channel, so your mic has been automatically muted."
}

let [setAutoMute, cancelAutoMute] = [() => { }, () => { }];
Expand Down Expand Up @@ -78,7 +79,7 @@ const settings = definePluginSettings({
type: OptionType.BOOLEAN,
description: "Whether the plugin will automatically mute you when someone who isn't you friend joins your voice channel",
default: true
},
}
});


Expand Down Expand Up @@ -156,7 +157,7 @@ function autoMute(reason: string) {
type: Toasts.Type.MESSAGE,
id: Toasts.genId(),
options: {
duration: 5000,
duration: 3500,
position: Toasts.Position.TOP
}
});
Expand Down Expand Up @@ -225,15 +226,24 @@ export default definePlugin({
});

const allVoiceStates: VoiceState[] = Object.values(VoiceStateStore.getVoiceStatesForChannel(SelectedChannelStore.getVoiceChannelId()));
let willMute = false;
const untrustedUsers = new Set<string>();
if (!clearTrustedUsers) allVoiceStates.forEach(({ userId }) => {
if (movingChannel) {
if (!MediaEngineStore.isSelfMute()) trustedUsers.add(userId);
} else {
if (!isTrusted(userId)) willMute = true;
if (!isTrusted(userId)) {
untrustedUsers.add(userId);
}
}
});
if (willMute && settings.store.nonFriendJoinsChannel) autoMute(AutoMuteReasons.NonFriend);
if (untrustedUsers.size && settings.store.nonFriendJoinsChannel) {
const guildId = ChannelStore.getChannel(SelectedChannelStore.getVoiceChannelId()!).getGuildId();
const users = [...untrustedUsers].map(userId => {
const user = UserStore.getUser(userId);
return GuildMemberStore.getNick(guildId, userId) ?? (user as any).globalName ?? user.username;
});
autoMute(AutoMuteReasons.NonFriend.replaceAll("[USER]", humanFriendlyJoin(users)));
}
},
AUDIO_TOGGLE_SELF_MUTE() {
updateAutoMute();
Expand Down

0 comments on commit cdfef56

Please sign in to comment.