Plugin

NewGuildSettings

Automatically mute new servers and change various other settings upon joining

Servers Customisation
index.tsx
Download

Source

src/plugins/newGuildSettings/index.tsx
1/*
2 * FiveCord — a Discord client mod
3 * Copyright (c) 2025 FiveCord
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7import {
8 findGroupChildrenByChildId,
9 NavContextMenuPatchCallback
10} from "@api/ContextMenu";
11import { definePluginSettings } from "@api/Settings";
12import { CogWheel } from "@components/Icons";
13import { Devs } from "@utils/constants";
14import definePlugin, { OptionType } from "@utils/types";
15import { Guild } from "@vencord/discord-types";
16import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
17import { Menu, UserStore } from "@webpack/common";
18
19const { updateGuildNotificationSettings } = findByPropsLazy("updateGuildNotificationSettings");
20const { toggleShowAllChannels } = mapMangledModuleLazy(".onboardExistingMember(", {
21 toggleShowAllChannels: m => {
22 const s = String(m);
23 return s.length < 100 && !s.includes("onboardExistingMember") && !s.includes("getOptedInChannels");
24 }
25});
26const isOptInEnabledForGuild = findByCodeLazy(".COMMUNITY)||", ".isOptInEnabled(");
27
28const settings = definePluginSettings({
29 guild: {
30 description: "Mute Guild automatically",
31 type: OptionType.BOOLEAN,
32 default: true
33 },
34 messages: {
35 description: "Server Notification Settings",
36 type: OptionType.SELECT,
37 options: [
38 { label: "All messages", value: 0 },
39 { label: "Only @mentions", value: 1 },
40 { label: "Nothing", value: 2 },
41 { label: "Server default", value: 3, default: true }
42 ],
43 },
44 everyone: {
45 description: "Suppress @everyone and @here",
46 type: OptionType.BOOLEAN,
47 default: true
48 },
49 role: {
50 description: "Suppress All Role @mentions",
51 type: OptionType.BOOLEAN,
52 default: true
53 },
54 highlights: {
55 description: "Suppress Highlights automatically",
56 type: OptionType.BOOLEAN,
57 default: true
58 },
59 events: {
60 description: "Mute New Events automatically",
61 type: OptionType.BOOLEAN,
62 default: true
63 },
64 showAllChannels: {
65 description: "Show all channels automatically",
66 type: OptionType.BOOLEAN,
67 default: true
68 }
69});
70
71const makeContextMenuPatch: (shouldAddIcon: boolean) => NavContextMenuPatchCallback = (shouldAddIcon: boolean) => (children, { guild }: { guild: Guild, onClose(): void; }) => {
72 if (!guild) return;
73
74 const group = findGroupChildrenByChildId("privacy", children);
75 group?.push(
76 <Menu.MenuItem
77 label="Apply NewGuildSettings"
78 id="vc-newguildsettings-apply"
79 icon={shouldAddIcon ? CogWheel : void 0}
80 action={() => applyDefaultSettings(guild.id)}
81 />
82 );
83};
84
85function applyDefaultSettings(guildId: string | null) {
86 if (guildId === "@me" || guildId === "null" || guildId == null) return;
87 updateGuildNotificationSettings(guildId,
88 {
89 muted: settings.store.guild,
90 suppress_everyone: settings.store.everyone,
91 suppress_roles: settings.store.role,
92 mute_scheduled_events: settings.store.events,
93 notify_highlights: settings.store.highlights ? 1 : 0
94 });
95 if (settings.store.messages !== 3) {
96 updateGuildNotificationSettings(guildId,
97 {
98 message_notifications: settings.store.messages,
99 });
100 }
101 if (settings.store.showAllChannels && isOptInEnabledForGuild(guildId)) {
102 toggleShowAllChannels(guildId);
103 }
104}
105
106export default definePlugin({
107 name: "NewGuildSettings",
108 description: "Automatically mute new servers and change various other settings upon joining",
109 tags: ["Servers", "Customisation"],
110 searchTerms: ["MuteNewGuild", "mute", "server"],
111 authors: [Devs.Glitch, Devs.Nuckyz, Devs.carince, Devs.Mopi, Devs.GabiRP],
112 contextMenus: {
113 "guild-context": makeContextMenuPatch(false),
114 "guild-header-popout": makeContextMenuPatch(true)
115 },
116 patches: [
117 {
118 find: ",acceptInvite(",
119 replacement: {
120 match: /INVITE_ACCEPT_SUCCESS.+?,(\i)=null!=.+?;/,
121 replace: (m, guildId) => `${m}$self.applyDefaultSettings(${guildId});`
122 }
123 },
124 {
125 find: "{joinGuild:",
126 replacement: {
127 match: /guildId:(\i),lurker:(\i).{0,20}}\)\);/,
128 replace: (m, guildId, lurker) => `${m}if(!${lurker})$self.applyDefaultSettings(${guildId});`
129 }
130 }
131 ],
132 settings,
133 applyDefaultSettings,
134 flux: {
135 GUILD_JOIN_REQUEST_UPDATE({ guildId, request, status }) {
136 if (status === "APPROVED" && request.user_id === UserStore.getCurrentUser().id)
137 applyDefaultSettings(guildId);
138 }
139 }
140});
141