2024-05-02 23:09:53 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2023 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-05-09 06:14:20 +00:00
|
|
|
import ErrorBoundary from "@components/ErrorBoundary";
|
2024-05-02 23:09:53 +00:00
|
|
|
import { Devs } from "@utils/constants";
|
|
|
|
import definePlugin from "@utils/types";
|
2024-06-19 02:36:21 +00:00
|
|
|
import { findLazy } from "@webpack";
|
2024-05-14 02:00:02 +00:00
|
|
|
import { Constants, GuildStore, i18n, RestAPI } from "@webpack/common";
|
2024-05-02 23:09:53 +00:00
|
|
|
|
2024-06-19 02:36:21 +00:00
|
|
|
const InvitesDisabledExperiment = findLazy(m => m.definition?.id === "2022-07_invites_disabled");
|
2024-05-02 23:09:53 +00:00
|
|
|
|
2024-05-14 01:45:57 +00:00
|
|
|
function showDisableInvites(guildId: string) {
|
|
|
|
// Once the experiment is removed, this should keep working
|
|
|
|
const { enableInvitesDisabled } = InvitesDisabledExperiment?.getCurrentConfig?.({ guildId }) ?? { enableInvitesDisabled: true };
|
|
|
|
// @ts-ignore
|
|
|
|
return enableInvitesDisabled && !GuildStore.getGuild(guildId).hasFeature("INVITES_DISABLED");
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableInvites(guildId: string) {
|
|
|
|
const guild = GuildStore.getGuild(guildId);
|
|
|
|
const features = [...guild.features, "INVITES_DISABLED"];
|
|
|
|
RestAPI.patch({
|
2024-05-14 02:00:02 +00:00
|
|
|
url: Constants.Endpoints.GUILD(guildId),
|
2024-05-14 01:45:57 +00:00
|
|
|
body: { features },
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:09:53 +00:00
|
|
|
export default definePlugin({
|
|
|
|
name: "PauseInvitesForever",
|
|
|
|
tags: ["DisableInvitesForever"],
|
|
|
|
description: "Brings back the option to pause invites indefinitely that stupit Discord removed.",
|
|
|
|
authors: [Devs.Dolfies, Devs.amia],
|
|
|
|
|
|
|
|
patches: [
|
|
|
|
{
|
|
|
|
find: "Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION",
|
2024-05-14 01:45:57 +00:00
|
|
|
group: true,
|
|
|
|
replacement: [
|
|
|
|
{
|
|
|
|
match: /children:\i\.\i\.\i\.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION/,
|
|
|
|
replace: "children: $self.renderInvitesLabel({guildId:arguments[0].guildId,setChecked})",
|
|
|
|
},
|
|
|
|
{
|
2024-06-19 05:16:29 +00:00
|
|
|
match: /\.INVITES_DISABLED\)(?=.+?\.Messages\.INVITES_PERMANENTLY_DISABLED_TIP.+?checked:(\i)).+?\[\1,(\i)\]=\i.useState\(\i\)/,
|
|
|
|
replace: "$&,setChecked=$2"
|
2024-05-14 01:45:57 +00:00
|
|
|
}
|
|
|
|
]
|
2024-05-02 23:09:53 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
2024-05-14 01:45:57 +00:00
|
|
|
renderInvitesLabel: ErrorBoundary.wrap(({ guildId, setChecked }) => {
|
2024-05-02 23:09:53 +00:00
|
|
|
return (
|
2024-05-14 01:45:57 +00:00
|
|
|
<div>
|
|
|
|
{i18n.Messages.GUILD_INVITE_DISABLE_ACTION_SHEET_DESCRIPTION}
|
|
|
|
{showDisableInvites(guildId) && <a role="button" onClick={() => {
|
|
|
|
setChecked(true);
|
|
|
|
disableInvites(guildId);
|
|
|
|
}}> Pause Indefinitely.</a>}
|
|
|
|
</div>
|
2024-05-02 23:09:53 +00:00
|
|
|
);
|
2024-05-14 01:45:57 +00:00
|
|
|
})
|
2024-05-02 23:09:53 +00:00
|
|
|
});
|