/*
* 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 .
*/
import { addButton, removeButton } from "@api/MessagePopover";
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import { getStegCloak } from "@utils/dependencies";
import definePlugin from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { Button, ButtonLooks, ChannelStore, FluxDispatcher, Tooltip } from "@webpack/common";
import { buildDecModal } from "./components/DecryptionModal";
import { buildEncModal } from "./components/EncryptionModal";
const ButtonWrapperClasses = findByPropsLazy("buttonWrapper", "buttonContent");
let steggo: any;
function PopOverIcon() {
return (
);
}
function Indicator() {
return (
{({ onMouseEnter, onMouseLeave }) => (
)}
);
}
function ChatBarIcon() {
return (
{({ onMouseEnter, onMouseLeave }) => (
// size="" = Button.Sizes.NONE
/*
many themes set "> button" to display: none, as the gift button is
the only directly descending button (all the other elements are divs.)
Thus, wrap in a div here to avoid getting hidden by that.
flex is for some reason necessary as otherwise the button goes flying off
*/
)
}
);
}
export default definePlugin({
name: "InvisibleChat",
description: "Encrypt your Messages in a non-suspicious way! This plugin makes requests to >>https://embed.sammcheese.net<< to provide embeds to decrypted links!",
authors: [Devs.SammCheese],
patches: [
{
// Indicator
find: ".Messages.MESSAGE_EDITED,",
replacement: {
match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm,
replace: "try {$1 && $self.INV_REGEX.test($1.content[0]) ? $1.content.push($self.indicator()) : null } catch {};$&"
}
},
{
find: ".activeCommandOption",
replacement: {
match: /.=.\.activeCommand,.=.\.activeCommandOption,.{1,133}(.)=\[\];/,
replace: "$&;$1.push($self.chatBarIcon());",
}
},
],
EMBED_API_URL: "https://embed.sammcheese.net",
INV_REGEX: new RegExp(/( \u200c|\u200d |[\u2060-\u2064])[^\u200b]/),
URL_REGEX: new RegExp(
/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
),
async start() {
const { default: StegCloak } = await getStegCloak();
steggo = new StegCloak(true, false);
addButton("invDecrypt", message => {
return this.INV_REGEX.test(message?.content)
? {
label: "Decrypt Message",
icon: this.popOverIcon,
message: message,
channel: ChannelStore.getChannel(message.channel_id),
onClick: () => buildDecModal({ message })
}
: null;
});
},
stop() {
removeButton("invDecrypt");
},
// Gets the Embed of a Link
async getEmbed(url: URL): Promise