Plugin

NewGuildSettings

Automatically mute new servers and change various other settings upon joining

Servers Customisation
index.tsx
Download

Source

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