Plugin
NewGuildSettings
Automatically mute new servers and change various other settings upon joining
1
import {2
findGroupChildrenByChildId,3
NavContextMenuPatchCallback4
} from "@api/ContextMenu";5
import { definePluginSettings } from "@api/Settings";6
import { CogWheel } from "@components/Icons";7
import { Devs } from "@utils/constants";8
import definePlugin, { OptionType } from "@utils/types";9
import { Guild } from "@vencord/discord-types";10
import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack";11
import { Menu, UserStore } from "@webpack/common";12
13
const { updateGuildNotificationSettings } = findByPropsLazy("updateGuildNotificationSettings");14
const { toggleShowAllChannels } = mapMangledModuleLazy(".onboardExistingMember(", {15
toggleShowAllChannels: m => {16
const s = String(m);17
return s.length < 100 && !s.includes("onboardExistingMember") && !s.includes("getOptedInChannels");18
}19
});20
const isOptInEnabledForGuild = findByCodeLazy(".COMMUNITY)||", ".isOptInEnabled(");21
22
const settings = definePluginSettings({23
guild: {24
description: "Mute Guild automatically",25
type: OptionType.BOOLEAN,26
default: true27
},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: true42
},43
role: {44
description: "Suppress All Role @mentions",45
type: OptionType.BOOLEAN,46
default: true47
},48
highlights: {49
description: "Suppress Highlights automatically",50
type: OptionType.BOOLEAN,51
default: true52
},53
events: {54
description: "Mute New Events automatically",55
type: OptionType.BOOLEAN,56
default: true57
},58
showAllChannels: {59
description: "Show all channels automatically",60
type: OptionType.BOOLEAN,61
default: true62
}63
});64
65
const 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.MenuItem71
label="Apply NewGuildSettings"72
id="vc-newguildsettings-apply"73
icon={shouldAddIcon ? CogWheel : void 0}74
action={() => applyDefaultSettings(guild.id)}75
/>76
);77
};78
79
function 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 : 088
});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
100
export 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