mirror of
https://github.com/Vendicated/Vencord
synced 2024-08-26 03:37:47 -04:00
NewGuildSettings: Add "Apply NewGuildSettings" button in menu (#2556)
Co-authored-by: vee <vendicated@riseup.net>
This commit is contained in:
parent
4008c93069
commit
3ad76b7f0f
1 changed files with 50 additions and 23 deletions
|
@ -16,10 +16,17 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
findGroupChildrenByChildId,
|
||||||
|
NavContextMenuPatchCallback
|
||||||
|
} from "@api/ContextMenu";
|
||||||
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
|
import { definePluginSettings, migratePluginSettings } from "@api/Settings";
|
||||||
|
import { CogWheel } from "@components/Icons";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy, mapMangledModuleLazy } from "@webpack";
|
||||||
|
import { Menu } from "@webpack/common";
|
||||||
|
import { Guild } from "discord-types/general";
|
||||||
|
|
||||||
const { updateGuildNotificationSettings } = findByPropsLazy("updateGuildNotificationSettings");
|
const { updateGuildNotificationSettings } = findByPropsLazy("updateGuildNotificationSettings");
|
||||||
const { toggleShowAllChannels } = mapMangledModuleLazy(".onboardExistingMember(", {
|
const { toggleShowAllChannels } = mapMangledModuleLazy(".onboardExistingMember(", {
|
||||||
|
@ -73,48 +80,68 @@ const settings = definePluginSettings({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const makeContextMenuPatch: (shouldAddIcon: boolean) => NavContextMenuPatchCallback = (shouldAddIcon: boolean) => (children, { guild }: { guild: Guild, onClose(): void; }) => {
|
||||||
|
if (!guild) return;
|
||||||
|
|
||||||
|
const group = findGroupChildrenByChildId("privacy", children);
|
||||||
|
group?.push(
|
||||||
|
<Menu.MenuItem
|
||||||
|
label="Apply NewGuildSettings"
|
||||||
|
id="vc-newguildsettings-apply"
|
||||||
|
icon={shouldAddIcon ? CogWheel : void 0}
|
||||||
|
action={() => applyDefaultSettings(guild.id)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
function applyDefaultSettings(guildId: string | null) {
|
||||||
|
if (guildId === "@me" || guildId === "null" || guildId == null) return;
|
||||||
|
updateGuildNotificationSettings(guildId,
|
||||||
|
{
|
||||||
|
muted: settings.store.guild,
|
||||||
|
suppress_everyone: settings.store.everyone,
|
||||||
|
suppress_roles: settings.store.role,
|
||||||
|
mute_scheduled_events: settings.store.events,
|
||||||
|
notify_highlights: settings.store.highlights ? 1 : 0
|
||||||
|
});
|
||||||
|
if (settings.store.messages !== 3) {
|
||||||
|
updateGuildNotificationSettings(guildId,
|
||||||
|
{
|
||||||
|
message_notifications: settings.store.messages,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (settings.store.showAllChannels && isOptInEnabledForGuild(guildId)) {
|
||||||
|
toggleShowAllChannels(guildId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
migratePluginSettings("NewGuildSettings", "MuteNewGuild");
|
migratePluginSettings("NewGuildSettings", "MuteNewGuild");
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "NewGuildSettings",
|
name: "NewGuildSettings",
|
||||||
description: "Automatically mute new servers and change various other settings upon joining",
|
description: "Automatically mute new servers and change various other settings upon joining",
|
||||||
tags: ["MuteNewGuild", "mute", "server"],
|
tags: ["MuteNewGuild", "mute", "server"],
|
||||||
authors: [Devs.Glitch, Devs.Nuckyz, Devs.carince, Devs.Mopi, Devs.GabiRP],
|
authors: [Devs.Glitch, Devs.Nuckyz, Devs.carince, Devs.Mopi, Devs.GabiRP],
|
||||||
|
contextMenus: {
|
||||||
|
"guild-context": makeContextMenuPatch(false),
|
||||||
|
"guild-header-popout": makeContextMenuPatch(true)
|
||||||
|
},
|
||||||
patches: [
|
patches: [
|
||||||
{
|
{
|
||||||
find: ",acceptInvite(",
|
find: ",acceptInvite(",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /INVITE_ACCEPT_SUCCESS.+?,(\i)=null!==.+?;/,
|
match: /INVITE_ACCEPT_SUCCESS.+?,(\i)=null!==.+?;/,
|
||||||
replace: (m, guildId) => `${m}$self.handleMute(${guildId});`
|
replace: (m, guildId) => `${m}$self.applyDefaultSettings(${guildId});`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
find: "{joinGuild:",
|
find: "{joinGuild:",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /guildId:(\i),lurker:(\i).{0,20}}\)\);/,
|
match: /guildId:(\i),lurker:(\i).{0,20}}\)\);/,
|
||||||
replace: (m, guildId, lurker) => `${m}if(!${lurker})$self.handleMute(${guildId});`
|
replace: (m, guildId, lurker) => `${m}if(!${lurker})$self.applyDefaultSettings(${guildId});`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
settings,
|
settings,
|
||||||
|
applyDefaultSettings
|
||||||
handleMute(guildId: string | null) {
|
|
||||||
if (guildId === "@me" || guildId === "null" || guildId == null) return;
|
|
||||||
updateGuildNotificationSettings(guildId,
|
|
||||||
{
|
|
||||||
muted: settings.store.guild,
|
|
||||||
suppress_everyone: settings.store.everyone,
|
|
||||||
suppress_roles: settings.store.role,
|
|
||||||
mute_scheduled_events: settings.store.events,
|
|
||||||
notify_highlights: settings.store.highlights ? 1 : 0
|
|
||||||
});
|
|
||||||
if (settings.store.messages !== 3) {
|
|
||||||
updateGuildNotificationSettings(guildId,
|
|
||||||
{
|
|
||||||
message_notifications: settings.store.messages,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (settings.store.showAllChannels && isOptInEnabledForGuild(guildId)) {
|
|
||||||
toggleShowAllChannels(guildId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue