diff --git a/plugins/nsfwbypass/src/index.ts b/plugins/nsfwbypass/src/index.ts index 7538c36..80a17dc 100644 --- a/plugins/nsfwbypass/src/index.ts +++ b/plugins/nsfwbypass/src/index.ts @@ -1,11 +1,32 @@ -import { findByStoreName, findByProps } from "@vendetta/metro"; +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"; + +const { Text } = findByProps("Button", "Text", "View"); const NSFWStuff = findByProps("isNSFWInvite"); const UserStore = findByStoreName("UserStore"); +const { getChannel } = findByProps("getChannel") || findByName("getChannel", false); let patches = []; +function isNSFWChannel(channelId) { + if (typeof channelId === "string") { + const channel = getChannel(channelId); + return channel?.nsfw === true; + } + return channelId?.nsfw === true; +} + +function NSFWWarningContent() { + return React.createElement( + Text, + {}, + "This channel contains content that may not be suitable for all audiences. Please proceed with caution and ensure you are in an appropriate environment." + ); +} + export default { onLoad: () => { patches.push(instead("handleNSFWGuildInvite", NSFWStuff, () => false)); @@ -22,6 +43,37 @@ export default { } return user; })); + + // 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 {}; + } + } + } + return orig(...args); + }) + ); + } + } + } }, onUnload: () => {