Update index.ts
This commit is contained in:
parent
af92f76438
commit
6081da18e0
1 changed files with 58 additions and 40 deletions
|
|
@ -2,6 +2,8 @@ import { findByStoreName, findByProps, findByName } from "@vendetta/metro";
|
|||
import { after, instead } from "@vendetta/patcher";
|
||||
import { showConfirmationAlert } from "@vendetta/ui/alerts";
|
||||
import { React } from "@vendetta/metro/common";
|
||||
import { storage } from "@vendetta/plugin";
|
||||
import { Settings } from "./Settings";
|
||||
|
||||
const { Text } = findByProps("Button", "Text", "View");
|
||||
|
||||
|
|
@ -11,6 +13,7 @@ const { getChannel } = findByProps("getChannel") || findByName("getChannel", fal
|
|||
|
||||
let patches = [];
|
||||
|
||||
// Helper function to check if a channel is NSFW
|
||||
function isNSFWChannel(channelId) {
|
||||
if (typeof channelId === "string") {
|
||||
const channel = getChannel(channelId);
|
||||
|
|
@ -19,6 +22,7 @@ function isNSFWChannel(channelId) {
|
|||
return channelId?.nsfw === true;
|
||||
}
|
||||
|
||||
// Warning content component
|
||||
function NSFWWarningContent() {
|
||||
return React.createElement(
|
||||
Text,
|
||||
|
|
@ -29,48 +33,60 @@ function NSFWWarningContent() {
|
|||
|
||||
export default {
|
||||
onLoad: () => {
|
||||
patches.push(instead("handleNSFWGuildInvite", NSFWStuff, () => false));
|
||||
patches.push(instead("isNSFWInvite", NSFWStuff, () => false));
|
||||
patches.push(instead("shouldNSFWGateGuild", NSFWStuff, () => false));
|
||||
|
||||
// User store patch to modify nsfwAllowed property
|
||||
patches.push(after("getCurrentUser", UserStore, (_, user) => {
|
||||
if (user?.hasOwnProperty("nsfwAllowed")) {
|
||||
user.nsfwAllowed = true;
|
||||
}
|
||||
if (user?.hasOwnProperty("ageVerificationStatus")) {
|
||||
user.ageVerificationStatus = 3; // VERIFIED_ADULT
|
||||
}
|
||||
return user;
|
||||
}));
|
||||
// Initialize default settings
|
||||
storage.ageBypass ??= false; // Default to false for password-protected feature
|
||||
storage.nsfwBypass ??= true;
|
||||
storage.showWarningPopup ??= true;
|
||||
|
||||
// Add NSFW channel warning
|
||||
const transitionToGuild = findByProps("transitionToGuild");
|
||||
if (transitionToGuild) {
|
||||
for (const key of Object.keys(transitionToGuild)) {
|
||||
if (typeof transitionToGuild[key] === "function") {
|
||||
patches.push(
|
||||
instead(key, transitionToGuild, (args, orig) => {
|
||||
if (typeof args[0] === "string") {
|
||||
const pathMatch = args[0].match(/(\d+)$/);
|
||||
if (pathMatch?.[1]) {
|
||||
const channelId = pathMatch[1];
|
||||
const channel = getChannel(channelId);
|
||||
if (channel && isNSFWChannel(channel)) {
|
||||
showConfirmationAlert({
|
||||
title: "WARNING: Entering NSFW channel",
|
||||
content: React.createElement(NSFWWarningContent),
|
||||
confirmText: "Proceed with Caution",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: () => { return orig(...args); },
|
||||
});
|
||||
return {};
|
||||
// NSFW bypass patches - only if enabled
|
||||
if (storage.nsfwBypass) {
|
||||
patches.push(instead("handleNSFWGuildInvite", NSFWStuff, () => false));
|
||||
patches.push(instead("isNSFWInvite", NSFWStuff, () => false));
|
||||
patches.push(instead("shouldNSFWGateGuild", NSFWStuff, () => false));
|
||||
}
|
||||
|
||||
// Age verification bypass - only if enabled
|
||||
if (storage.ageBypass) {
|
||||
patches.push(after("getCurrentUser", UserStore, (_, user) => {
|
||||
if (user?.hasOwnProperty("nsfwAllowed")) {
|
||||
user.nsfwAllowed = true;
|
||||
}
|
||||
if (user?.hasOwnProperty("ageVerificationStatus")) {
|
||||
user.ageVerificationStatus = 3; // VERIFIED_ADULT
|
||||
}
|
||||
return user;
|
||||
}));
|
||||
}
|
||||
|
||||
// NSFW channel warning - only if enabled
|
||||
if (storage.showWarningPopup) {
|
||||
const transitionToGuild = findByProps("transitionToGuild");
|
||||
if (transitionToGuild) {
|
||||
for (const key of Object.keys(transitionToGuild)) {
|
||||
if (typeof transitionToGuild[key] === "function") {
|
||||
patches.push(
|
||||
instead(key, transitionToGuild, (args, orig) => {
|
||||
if (typeof args[0] === "string") {
|
||||
const pathMatch = args[0].match(/(\d+)$/);
|
||||
if (pathMatch?.[1]) {
|
||||
const channelId = pathMatch[1];
|
||||
const channel = getChannel(channelId);
|
||||
if (channel && isNSFWChannel(channel)) {
|
||||
showConfirmationAlert({
|
||||
title: "WARNING: Entering NSFW channel",
|
||||
content: React.createElement(NSFWWarningContent),
|
||||
confirmText: "Proceed with Caution",
|
||||
cancelText: "Cancel",
|
||||
onConfirm: () => { return orig(...args); },
|
||||
});
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return orig(...args);
|
||||
})
|
||||
);
|
||||
return orig(...args);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -81,5 +97,7 @@ export default {
|
|||
unpatch();
|
||||
}
|
||||
patches = [];
|
||||
}
|
||||
},
|
||||
|
||||
settings: Settings
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue