Plugin
NewGuildSettings
Automatically mute new servers and change various other settings upon joining
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import {8
findGroupChildrenByChildId,9
NavContextMenuPatchCallback10
} from "@api/ContextMenu";11
import { definePluginSettings } from "@api/Settings";12
import { CogWheel } from "@components/Icons";13
import { Devs } from "@utils/constants";14
import definePlugin, { OptionType } from "@utils/types";15
import { Guild } from "@vencord/discord-types";16
import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack";17
import { Menu, UserStore } from "@webpack/common";18
19
const { updateGuildNotificationSettings } = findByPropsLazy("updateGuildNotificationSettings");20
const { toggleShowAllChannels } = mapMangledModuleLazy(".onboardExistingMember(", {21
toggleShowAllChannels: m => {22
const s = String(m);23
return s.length < 100 && !s.includes("onboardExistingMember") && !s.includes("getOptedInChannels");24
}25
});26
const isOptInEnabledForGuild = findByCodeLazy(".COMMUNITY)||", ".isOptInEnabled(");27
28
const settings = definePluginSettings({29
guild: {30
description: "Mute Guild automatically",31
type: OptionType.BOOLEAN,32
default: true33
},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: true48
},49
role: {50
description: "Suppress All Role @mentions",51
type: OptionType.BOOLEAN,52
default: true53
},54
highlights: {55
description: "Suppress Highlights automatically",56
type: OptionType.BOOLEAN,57
default: true58
},59
events: {60
description: "Mute New Events automatically",61
type: OptionType.BOOLEAN,62
default: true63
},64
showAllChannels: {65
description: "Show all channels automatically",66
type: OptionType.BOOLEAN,67
default: true68
}69
});70
71
const 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.MenuItem77
label="Apply NewGuildSettings"78
id="vc-newguildsettings-apply"79
icon={shouldAddIcon ? CogWheel : void 0}80
action={() => applyDefaultSettings(guild.id)}81
/>82
);83
};84
85
function 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 : 094
});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
106
export 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