/* * Vencord, a Discord client mod * Copyright (c) 2024 Vendicated and contributors * SPDX-License-Identifier: GPL-3.0-or-later */ import { NavContextMenuPatchCallback } from "@api/ContextMenu"; import { migratePluginSettings } from "@api/Settings"; import { CodeBlock } from "@components/CodeBlock"; import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { getIntlMessage } from "@utils/discord"; import { Margins } from "@utils/margins"; import { closeModal, ModalCloseButton, ModalContent, ModalHeader, ModalRoot, ModalSize, openModal, } from "@utils/modal"; import definePlugin from "@utils/types"; import { Forms, Menu, Text } from "@webpack/common"; import { Message } from "discord-types/general"; migratePluginSettings("ViewRawVariant", "ViewRaw2"); type CustomMessage = Message & { editHistory?: any; deleted?: any; firstEditTimestamp?: any; }; const CopyIcon = () => { return ( ); }; function cleanMessage(msg: CustomMessage) { const author = { ...msg.author } as any; delete author.email; delete author.phone; delete author.mfaEnabled; delete author.personalConnectionId; delete msg.editHistory; delete msg.deleted; delete msg.firstEditTimestamp; return { ...msg, author }; } function openViewRawModal(obj: any, type: string, isMessage?: boolean) { const key = openModal(props => ( View Raw {type} closeModal(key)} />
{isMessage && ( <> Content )} {type} Data
)); } function makeContextCallback( name: string, action: (any) => void, ): NavContextMenuPatchCallback { return (children, props) => { if (props.label === getIntlMessage("CHANNEL_ACTIONS_MENU_LABEL")) return; // random shit like notification settings const value = props[name]; if (!value) return; const lastChild = children.at(-1); if (lastChild?.key === "developer-actions") { const p = lastChild.props; if (!Array.isArray(p.children)) p.children = [p.children]; children = p.children; } children.push( action(value)} icon={CopyIcon} />, ); }; } export default definePlugin({ name: "ViewRawVariant", description: "Copy/View raw content of any message, channel, or guild, but show in the right click menu.", authors: [Devs.KingFish, Devs.Ven, Devs.rad, Devs.ImLvna, Devs.Kyuuhachi], contextMenus: { "guild-context": makeContextCallback("guild", val => openViewRawModal(val, "Guild"), ), "channel-context": makeContextCallback("channel", val => openViewRawModal(val, "Channel"), ), "user-context": makeContextCallback("user", val => openViewRawModal(val, "User"), ), message: makeContextCallback("message", val => openViewRawModal(cleanMessage(val), "Message", true), ), }, });