From 41f5d71e38f785786656e111cf2ea1200e45886d Mon Sep 17 00:00:00 2001 From: V Date: Tue, 19 Sep 2023 04:07:24 +0200 Subject: Bundle dependencies with extensions for webstore rule compliance (#1740) --- src/components/monacoWin.html | 66 -- src/globals.d.ts | 1 + src/main/ipcMain.ts | 2 +- src/main/monacoWin.html | 66 ++ src/plugins/_core/supportHelper.tsx | 120 ++ src/plugins/fakeNitro.ts | 11 +- .../components/DecryptionModal.tsx | 77 ++ .../components/EncryptionModal.tsx | 112 ++ src/plugins/invisibleChat.desktop/index.tsx | 255 +++++ .../invisibleChat/components/DecryptionModal.tsx | 77 -- .../invisibleChat/components/EncryptionModal.tsx | 112 -- src/plugins/invisibleChat/index.tsx | 255 ----- src/plugins/petpet.ts | 5 +- .../shikiCodeblocks.desktop/api/languages.ts | 74 ++ src/plugins/shikiCodeblocks.desktop/api/shiki.ts | 118 ++ src/plugins/shikiCodeblocks.desktop/api/themes.ts | 67 ++ .../components/ButtonRow.tsx | 46 + .../shikiCodeblocks.desktop/components/Code.tsx | 93 ++ .../components/CopyButton.tsx | 41 + .../shikiCodeblocks.desktop/components/Header.tsx | 42 + .../components/Highlighter.tsx | 126 +++ src/plugins/shikiCodeblocks.desktop/devicon.css | 1 + .../hooks/useCopyCooldown.ts | 34 + .../hooks/useShikiSettings.ts | 47 + .../shikiCodeblocks.desktop/hooks/useTheme.ts | 49 + src/plugins/shikiCodeblocks.desktop/index.ts | 75 ++ .../shikiCodeblocks.desktop/previewExample.tsx | 13 + src/plugins/shikiCodeblocks.desktop/settings.ts | 123 +++ src/plugins/shikiCodeblocks.desktop/shiki.css | 101 ++ src/plugins/shikiCodeblocks.desktop/types.ts | 64 ++ src/plugins/shikiCodeblocks.desktop/utils/color.ts | 32 + .../shikiCodeblocks.desktop/utils/createStyle.ts | 36 + src/plugins/shikiCodeblocks.desktop/utils/misc.ts | 50 + src/plugins/shikiCodeblocks/api/languages.ts | 74 -- src/plugins/shikiCodeblocks/api/shiki.ts | 118 -- src/plugins/shikiCodeblocks/api/themes.ts | 67 -- .../shikiCodeblocks/components/ButtonRow.tsx | 46 - src/plugins/shikiCodeblocks/components/Code.tsx | 93 -- .../shikiCodeblocks/components/CopyButton.tsx | 41 - src/plugins/shikiCodeblocks/components/Header.tsx | 42 - .../shikiCodeblocks/components/Highlighter.tsx | 126 --- src/plugins/shikiCodeblocks/devicon.css | 1 - .../shikiCodeblocks/hooks/useCopyCooldown.ts | 34 - .../shikiCodeblocks/hooks/useShikiSettings.ts | 47 - src/plugins/shikiCodeblocks/hooks/useTheme.ts | 49 - src/plugins/shikiCodeblocks/index.ts | 75 -- src/plugins/shikiCodeblocks/previewExample.tsx | 13 - src/plugins/shikiCodeblocks/settings.ts | 123 --- src/plugins/shikiCodeblocks/shiki.css | 101 -- src/plugins/shikiCodeblocks/types.ts | 64 -- src/plugins/shikiCodeblocks/utils/color.ts | 32 - src/plugins/shikiCodeblocks/utils/createStyle.ts | 36 - src/plugins/shikiCodeblocks/utils/misc.ts | 50 - src/plugins/supportHelper.tsx | 120 -- src/utils/apng-canvas.js | 1168 ++++++++++++++++++++ src/utils/dependencies.ts | 35 +- src/utils/web-metadata.ts | 14 + 57 files changed, 3069 insertions(+), 1891 deletions(-) delete mode 100644 src/components/monacoWin.html create mode 100644 src/main/monacoWin.html create mode 100644 src/plugins/_core/supportHelper.tsx create mode 100644 src/plugins/invisibleChat.desktop/components/DecryptionModal.tsx create mode 100644 src/plugins/invisibleChat.desktop/components/EncryptionModal.tsx create mode 100644 src/plugins/invisibleChat.desktop/index.tsx delete mode 100644 src/plugins/invisibleChat/components/DecryptionModal.tsx delete mode 100644 src/plugins/invisibleChat/components/EncryptionModal.tsx delete mode 100644 src/plugins/invisibleChat/index.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/api/languages.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/api/shiki.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/api/themes.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/components/ButtonRow.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/components/Code.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/components/CopyButton.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/components/Header.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/components/Highlighter.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/devicon.css create mode 100644 src/plugins/shikiCodeblocks.desktop/hooks/useCopyCooldown.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/hooks/useShikiSettings.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/hooks/useTheme.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/index.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/previewExample.tsx create mode 100644 src/plugins/shikiCodeblocks.desktop/settings.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/shiki.css create mode 100644 src/plugins/shikiCodeblocks.desktop/types.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/utils/color.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/utils/createStyle.ts create mode 100644 src/plugins/shikiCodeblocks.desktop/utils/misc.ts delete mode 100644 src/plugins/shikiCodeblocks/api/languages.ts delete mode 100644 src/plugins/shikiCodeblocks/api/shiki.ts delete mode 100644 src/plugins/shikiCodeblocks/api/themes.ts delete mode 100644 src/plugins/shikiCodeblocks/components/ButtonRow.tsx delete mode 100644 src/plugins/shikiCodeblocks/components/Code.tsx delete mode 100644 src/plugins/shikiCodeblocks/components/CopyButton.tsx delete mode 100644 src/plugins/shikiCodeblocks/components/Header.tsx delete mode 100644 src/plugins/shikiCodeblocks/components/Highlighter.tsx delete mode 100644 src/plugins/shikiCodeblocks/devicon.css delete mode 100644 src/plugins/shikiCodeblocks/hooks/useCopyCooldown.ts delete mode 100644 src/plugins/shikiCodeblocks/hooks/useShikiSettings.ts delete mode 100644 src/plugins/shikiCodeblocks/hooks/useTheme.ts delete mode 100644 src/plugins/shikiCodeblocks/index.ts delete mode 100644 src/plugins/shikiCodeblocks/previewExample.tsx delete mode 100644 src/plugins/shikiCodeblocks/settings.ts delete mode 100644 src/plugins/shikiCodeblocks/shiki.css delete mode 100644 src/plugins/shikiCodeblocks/types.ts delete mode 100644 src/plugins/shikiCodeblocks/utils/color.ts delete mode 100644 src/plugins/shikiCodeblocks/utils/createStyle.ts delete mode 100644 src/plugins/shikiCodeblocks/utils/misc.ts delete mode 100644 src/plugins/supportHelper.tsx create mode 100644 src/utils/apng-canvas.js create mode 100644 src/utils/web-metadata.ts (limited to 'src') diff --git a/src/components/monacoWin.html b/src/components/monacoWin.html deleted file mode 100644 index 61d075f..0000000 --- a/src/components/monacoWin.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - Vencord QuickCSS Editor - - - - - -
- - - - - diff --git a/src/globals.d.ts b/src/globals.d.ts index daccf33..94b5f15 100644 --- a/src/globals.d.ts +++ b/src/globals.d.ts @@ -33,6 +33,7 @@ declare global { * replace: `${IS_WEB}?foo:bar` */ export var IS_WEB: boolean; + export var IS_EXTENSION: boolean; export var IS_DEV: boolean; export var IS_STANDALONE: boolean; export var IS_UPDATER_DISABLED: boolean; diff --git a/src/main/ipcMain.ts b/src/main/ipcMain.ts index c8e4567..61cbe7a 100644 --- a/src/main/ipcMain.ts +++ b/src/main/ipcMain.ts @@ -27,7 +27,7 @@ import { mkdirSync, readFileSync, watch } from "fs"; import { open, readdir, readFile, writeFile } from "fs/promises"; import { join, normalize } from "path"; -import monacoHtml from "~fileContent/../components/monacoWin.html;base64"; +import monacoHtml from "~fileContent/monacoWin.html;base64"; import { getThemeInfo, stripBOM, UserThemeHeader } from "./themes"; import { ALLOWED_PROTOCOLS, QUICKCSS_PATH, SETTINGS_DIR, SETTINGS_FILE, THEMES_DIR } from "./utils/constants"; diff --git a/src/main/monacoWin.html b/src/main/monacoWin.html new file mode 100644 index 0000000..61d075f --- /dev/null +++ b/src/main/monacoWin.html @@ -0,0 +1,66 @@ + + + + + Vencord QuickCSS Editor + + + + + +
+ + + + + diff --git a/src/plugins/_core/supportHelper.tsx b/src/plugins/_core/supportHelper.tsx new file mode 100644 index 0000000..674be8e --- /dev/null +++ b/src/plugins/_core/supportHelper.tsx @@ -0,0 +1,120 @@ +/* + * 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 { DataStore } from "@api/index"; +import { Devs, SUPPORT_CHANNEL_ID } from "@utils/constants"; +import { isPluginDev } from "@utils/misc"; +import { makeCodeblock } from "@utils/text"; +import definePlugin from "@utils/types"; +import { isOutdated } from "@utils/updater"; +import { Alerts, Forms, UserStore } from "@webpack/common"; + +import gitHash from "~git-hash"; +import plugins from "~plugins"; + +import settings from "./settings"; + +const REMEMBER_DISMISS_KEY = "Vencord-SupportHelper-Dismiss"; + +const AllowedChannelIds = [ + SUPPORT_CHANNEL_ID, + "1024286218801926184", // Vencord > #bot-spam + "1033680203433660458", // Vencord > #v +]; + +export default definePlugin({ + name: "SupportHelper", + required: true, + description: "Helps us provide support to you", + authors: [Devs.Ven], + dependencies: ["CommandsAPI"], + + commands: [{ + name: "vencord-debug", + description: "Send Vencord Debug info", + predicate: ctx => AllowedChannelIds.includes(ctx.channel.id), + async execute() { + const { RELEASE_CHANNEL } = window.GLOBAL_ENV; + + const client = (() => { + if (IS_DISCORD_DESKTOP) return `Discord Desktop v${DiscordNative.app.getVersion()}`; + if (IS_VESKTOP) return `Vesktop v${VesktopNative.app.getVersion()}`; + if ("armcord" in window) return `ArmCord v${window.armcord.version}`; + + // @ts-expect-error + const name = typeof unsafeWindow !== "undefined" ? "UserScript" : "Web"; + return `${name} (${navigator.userAgent})`; + })(); + + const isApiPlugin = (plugin: string) => plugin.endsWith("API") || plugins[plugin].required; + + const enabledPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && !isApiPlugin(p)); + const enabledApiPlugins = Object.keys(plugins).filter(p => Vencord.Plugins.isPluginEnabled(p) && isApiPlugin(p)); + + const info = { + Vencord: `v${VERSION} • ${gitHash}${settings.additionalInfo} - ${Intl.DateTimeFormat("en-GB", { dateStyle: "medium" }).format(BUILD_TIMESTAMP)}`, + "Discord Branch": RELEASE_CHANNEL, + Client: client, + Platform: window.navigator.platform, + Outdated: isOutdated, + OpenAsar: "openasar" in window, + }; + + if (IS_DISCORD_DESKTOP) { + info["Last Crash Reason"] = (await DiscordNative.processUtils.getLastCrash())?.rendererCrashReason ?? "N/A"; + } + + const debugInfo = ` +**Vencord Debug Info** +>>> ${Object.entries(info).map(([k, v]) => `${k}: ${v}`).join("\n")} + +Enabled Plugins (${enabledPlugins.length + enabledApiPlugins.length}): +${makeCodeblock(enabledPlugins.join(", ") + "\n\n" + enabledApiPlugins.join(", "))} +`; + + return { + content: debugInfo.trim().replaceAll("```\n", "```") + }; + } + }], + + flux: { + async CHANNEL_SELECT({ channelId }) { + if (channelId !== SUPPORT_CHANNEL_ID) return; + + if (isPluginDev(UserStore.getCurrentUser().id)) return; + + if (isOutdated && gitHash !== await DataStore.get(REMEMBER_DISMISS_KEY)) { + const rememberDismiss = () => DataStore.set(REMEMBER_DISMISS_KEY, gitHash); + + Alerts.show({ + title: "Hold on!", + body:
+ You are using an outdated version of Vencord! Chances are, your issue is already fixed. + + Please first update using the Updater Page in Settings, or use the VencordInstaller (Update Vencord Button) + to do so, in case you can't access the Updater page. + +
, + onCancel: rememberDismiss, + onConfirm: rememberDismiss + }); + } + } + } +}); diff --git a/src/plugins/fakeNitro.ts b/src/plugins/fakeNitro.ts index f56239f..1313145 100644 --- a/src/plugins/fakeNitro.ts +++ b/src/plugins/fakeNitro.ts @@ -19,7 +19,7 @@ import { addPreEditListener, addPreSendListener, removePreEditListener, removePreSendListener } from "@api/MessageEvents"; import { definePluginSettings, Settings } from "@api/Settings"; import { Devs } from "@utils/constants"; -import { ApngBlendOp, ApngDisposeOp, getGifEncoder, importApngJs } from "@utils/dependencies"; +import { ApngBlendOp, ApngDisposeOp, importApngJs } from "@utils/dependencies"; import { getCurrentGuild } from "@utils/discord"; import { proxyLazy } from "@utils/lazy"; import { Logger } from "@utils/Logger"; @@ -27,6 +27,7 @@ import definePlugin, { OptionType } from "@utils/types"; import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack"; import { ChannelStore, EmojiStore, FluxDispatcher, Parser, PermissionStore, UserStore } from "@webpack/common"; import type { Message } from "discord-types/general"; +import { applyPalette, GIFEncoder, quantize } from "gifenc"; import type { ReactElement, ReactNode } from "react"; const DRAFT_TYPE = 0; @@ -650,15 +651,11 @@ export default definePlugin({ }, async sendAnimatedSticker(stickerLink: string, stickerId: string, channelId: string) { - const [{ parseURL }, { - GIFEncoder, - quantize, - applyPalette - }] = await Promise.all([importApngJs(), getGifEncoder()]); + const { parseURL } = importApngJs(); const { frames, width, height } = await parseURL(stickerLink); - const gif = new GIFEncoder(); + const gif = GIFEncoder(); const resolution = Settings.plugins.FakeNitro.stickerSize; const canvas = document.createElement("canvas"); diff --git a/src/plugins/invisibleChat.desktop/components/DecryptionModal.tsx b/src/plugins/invisibleChat.desktop/components/DecryptionModal.tsx new file mode 100644 index 0000000..b4bf6eb --- /dev/null +++ b/src/plugins/invisibleChat.desktop/components/DecryptionModal.tsx @@ -0,0 +1,77 @@ +/* + * 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 { + ModalContent, + ModalFooter, + ModalHeader, + ModalRoot, + openModal, +} from "@utils/modal"; +import { Button, Forms, React, TextInput } from "@webpack/common"; + +import { decrypt } from "../index"; + +export function DecModal(props: any) { + const encryptedMessage: string = props?.message?.content; + const [password, setPassword] = React.useState("password"); + + return ( + + + Decrypt Message + + + + Message with Encryption + + Password + + + + + + + + + ); +} + +export function buildDecModal(msg: any): any { + openModal((props: any) => ); +} diff --git a/src/plugins/invisibleChat.desktop/components/EncryptionModal.tsx b/src/plugins/invisibleChat.desktop/components/EncryptionModal.tsx new file mode 100644 index 0000000..f893680 --- /dev/null +++ b/src/plugins/invisibleChat.desktop/components/EncryptionModal.tsx @@ -0,0 +1,112 @@ +/* + * 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 { insertTextIntoChatInputBox } from "@utils/discord"; +import { + ModalContent, + ModalFooter, + ModalHeader, + ModalProps, + ModalRoot, + openModal, +} from "@utils/modal"; +import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; + +import { encrypt } from "../index"; + +function EncModal(props: ModalProps) { + const [secret, setSecret] = React.useState(""); + const [cover, setCover] = React.useState(""); + const [password, setPassword] = React.useState("password"); + const [noCover, setNoCover] = React.useState(false); + + const isValid = secret && (noCover || (cover && cover.trim().split(" ").length > 1)); + + return ( + + + Encrypt Message + + + + Secret + { + setSecret(e); + }} + /> + Cover (2 or more Words!!) + { + setCover(e); + }} + /> + Password + { + setPassword(e); + }} + /> + { + setNoCover(e); + }} + > + Don't use a Cover + + + + + + + + + ); +} + +export function buildEncModal(): any { + openModal(props => ); +} diff --git a/src/plugins/invisibleChat.desktop/index.tsx b/src/plugins/invisibleChat.desktop/index.tsx new file mode 100644 index 0000000..58fccb9 --- /dev/null +++ b/src/plugins/invisibleChat.desktop/index.tsx @@ -0,0 +1,255 @@ +/* + * 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 { definePluginSettings } from "@api/Settings"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import { getStegCloak } from "@utils/dependencies"; +import definePlugin, { OptionType } from "@utils/types"; +import { Button, ButtonLooks, ButtonWrapperClasses, ChannelStore, FluxDispatcher, RestAPI, Tooltip } from "@webpack/common"; +import { Message } from "discord-types/general"; + +import { buildDecModal } from "./components/DecryptionModal"; +import { buildEncModal } from "./components/EncryptionModal"; + +let steggo: any; + +function PopOverIcon() { + return ( + + + + + ); +} + + +function Indicator() { + return ( + + {({ onMouseEnter, onMouseLeave }) => ( + + )} + + + ); + +} + +function ChatBarIcon(chatBoxProps: { + type: { + analyticsName: string; + }; +}) { + if (chatBoxProps.type.analyticsName !== "normal") return null; + + 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 + */ +
+ +
+ ) + } +
+ ); +} + +const settings = definePluginSettings({ + savedPasswords: { + type: OptionType.STRING, + default: "password, Password", + description: "Saved Passwords (Seperated with a , )" + } +}); + +export default definePlugin({ + name: "InvisibleChat", + description: "Encrypt your Messages in a non-suspicious way!", + authors: [Devs.SammCheese], + dependencies: ["MessagePopoverAPI"], + patches: [ + { + // Indicator + find: ".Messages.MESSAGE_EDITED,", + replacement: { + match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm, + replace: "try {$1 && $self.INV_REGEX.test($1.message.content) ? $1.content.push($self.indicator()) : null } catch {};$&" + } + }, + { + find: ".activeCommandOption", + replacement: { + match: /(.)\.push.{1,30}disabled:(\i),.{1,20}\},"gift"\)\)/, + replace: "$&;try{$2||$1.push($self.chatBarIcon(arguments[0]))}catch{}", + } + }, + ], + + 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@:%_+.~#?&//=]*)/, + ), + settings, + 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: async () => { + await iteratePasswords(message).then((res: string | false) => { + if (res) return void this.buildEmbed(message, res); + return void buildDecModal({ message }); + }); + } + } + : null; + }); + }, + + stop() { + removeButton("invDecrypt"); + }, + + // Gets the Embed of a Link + async getEmbed(url: URL): Promise { + const { body } = await RestAPI.post({ + url: "/unfurler/embed-urls", + body: { + urls: [url] + } + }); + return await body.embeds[0]; + }, + + async buildEmbed(message: any, revealed: string): Promise { + const urlCheck = revealed.match(this.URL_REGEX); + + message.embeds.push({ + type: "rich", + title: "Decrypted Message", + color: "0x45f5f5", + description: revealed, + footer: { + text: "Made with ❤️ by c0dine and Sammy!", + }, + }); + + if (urlCheck?.length) { + const embed = await this.getEmbed(new URL(urlCheck[0])); + if (embed) + message.embeds.push(embed); + } + + this.updateMessage(message); + }, + + updateMessage: (message: any) => { + FluxDispatcher.dispatch({ + type: "MESSAGE_UPDATE", + message, + }); + }, + + chatBarIcon: ErrorBoundary.wrap(ChatBarIcon, { noop: true }), + popOverIcon: () => , + indicator: ErrorBoundary.wrap(Indicator, { noop: true }) +}); + +export function encrypt(secret: string, password: string, cover: string): string { + return steggo.hide(secret + "\u200b", password, cover); +} + +export function decrypt(encrypted: string, password: string, removeIndicator: boolean): string { + const decrypted = steggo.reveal(encrypted, password); + return removeIndicator ? decrypted.replace("\u200b", "") : decrypted; +} + +export function isCorrectPassword(result: string): boolean { + return result.endsWith("\u200b"); +} + +export async function iteratePasswords(message: Message): Promise { + const passwords = settings.store.savedPasswords.split(",").map(s => s.trim()); + + if (!message?.content || !passwords?.length) return false; + + let { content } = message; + + // we use an extra variable so we dont have to edit the message content directly + if (/^\W/.test(message.content)) content = `d ${message.content}d`; + + for (let i = 0; i < passwords.length; i++) { + const result = decrypt(content, passwords[i], false); + if (isCorrectPassword(result)) { + return result; + } + } + + return false; +} diff --git a/src/plugins/invisibleChat/components/DecryptionModal.tsx b/src/plugins/invisibleChat/components/DecryptionModal.tsx deleted file mode 100644 index b4bf6eb..0000000 --- a/src/plugins/invisibleChat/components/DecryptionModal.tsx +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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 { - ModalContent, - ModalFooter, - ModalHeader, - ModalRoot, - openModal, -} from "@utils/modal"; -import { Button, Forms, React, TextInput } from "@webpack/common"; - -import { decrypt } from "../index"; - -export function DecModal(props: any) { - const encryptedMessage: string = props?.message?.content; - const [password, setPassword] = React.useState("password"); - - return ( - - - Decrypt Message - - - - Message with Encryption - - Password - - - - - - - - - ); -} - -export function buildDecModal(msg: any): any { - openModal((props: any) => ); -} diff --git a/src/plugins/invisibleChat/components/EncryptionModal.tsx b/src/plugins/invisibleChat/components/EncryptionModal.tsx deleted file mode 100644 index f893680..0000000 --- a/src/plugins/invisibleChat/components/EncryptionModal.tsx +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 { insertTextIntoChatInputBox } from "@utils/discord"; -import { - ModalContent, - ModalFooter, - ModalHeader, - ModalProps, - ModalRoot, - openModal, -} from "@utils/modal"; -import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; - -import { encrypt } from "../index"; - -function EncModal(props: ModalProps) { - const [secret, setSecret] = React.useState(""); - const [cover, setCover] = React.useState(""); - const [password, setPassword] = React.useState("password"); - const [noCover, setNoCover] = React.useState(false); - - const isValid = secret && (noCover || (cover && cover.trim().split(" ").length > 1)); - - return ( - - - Encrypt Message - - - - Secret - { - setSecret(e); - }} - /> - Cover (2 or more Words!!) - { - setCover(e); - }} - /> - Password - { - setPassword(e); - }} - /> - { - setNoCover(e); - }} - > - Don't use a Cover - - - - - - - - - ); -} - -export function buildEncModal(): any { - openModal(props => ); -} diff --git a/src/plugins/invisibleChat/index.tsx b/src/plugins/invisibleChat/index.tsx deleted file mode 100644 index 58fccb9..0000000 --- a/src/plugins/invisibleChat/index.tsx +++ /dev/null @@ -1,255 +0,0 @@ -/* - * 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 { definePluginSettings } from "@api/Settings"; -import ErrorBoundary from "@components/ErrorBoundary"; -import { Devs } from "@utils/constants"; -import { getStegCloak } from "@utils/dependencies"; -import definePlugin, { OptionType } from "@utils/types"; -import { Button, ButtonLooks, ButtonWrapperClasses, ChannelStore, FluxDispatcher, RestAPI, Tooltip } from "@webpack/common"; -import { Message } from "discord-types/general"; - -import { buildDecModal } from "./components/DecryptionModal"; -import { buildEncModal } from "./components/EncryptionModal"; - -let steggo: any; - -function PopOverIcon() { - return ( - - - - - ); -} - - -function Indicator() { - return ( - - {({ onMouseEnter, onMouseLeave }) => ( - - )} - - - ); - -} - -function ChatBarIcon(chatBoxProps: { - type: { - analyticsName: string; - }; -}) { - if (chatBoxProps.type.analyticsName !== "normal") return null; - - 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 - */ -
- -
- ) - } -
- ); -} - -const settings = definePluginSettings({ - savedPasswords: { - type: OptionType.STRING, - default: "password, Password", - description: "Saved Passwords (Seperated with a , )" - } -}); - -export default definePlugin({ - name: "InvisibleChat", - description: "Encrypt your Messages in a non-suspicious way!", - authors: [Devs.SammCheese], - dependencies: ["MessagePopoverAPI"], - patches: [ - { - // Indicator - find: ".Messages.MESSAGE_EDITED,", - replacement: { - match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/gm, - replace: "try {$1 && $self.INV_REGEX.test($1.message.content) ? $1.content.push($self.indicator()) : null } catch {};$&" - } - }, - { - find: ".activeCommandOption", - replacement: { - match: /(.)\.push.{1,30}disabled:(\i),.{1,20}\},"gift"\)\)/, - replace: "$&;try{$2||$1.push($self.chatBarIcon(arguments[0]))}catch{}", - } - }, - ], - - 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@:%_+.~#?&//=]*)/, - ), - settings, - 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: async () => { - await iteratePasswords(message).then((res: string | false) => { - if (res) return void this.buildEmbed(message, res); - return void buildDecModal({ message }); - }); - } - } - : null; - }); - }, - - stop() { - removeButton("invDecrypt"); - }, - - // Gets the Embed of a Link - async getEmbed(url: URL): Promise { - const { body } = await RestAPI.post({ - url: "/unfurler/embed-urls", - body: { - urls: [url] - } - }); - return await body.embeds[0]; - }, - - async buildEmbed(message: any, revealed: string): Promise { - const urlCheck = revealed.match(this.URL_REGEX); - - message.embeds.push({ - type: "rich", - title: "Decrypted Message", - color: "0x45f5f5", - description: revealed, - footer: { - text: "Made with ❤️ by c0dine and Sammy!", - }, - }); - - if (urlCheck?.length) { - const embed = await this.getEmbed(new URL(urlCheck[0])); - if (embed) - message.embeds.push(embed); - } - - this.updateMessage(message); - }, - - updateMessage: (message: any) => { - FluxDispatcher.dispatch({ - type: "MESSAGE_UPDATE", - message, - }); - }, - - chatBarIcon: ErrorBoundary.wrap(ChatBarIcon, { noop: true }), - popOverIcon: () => , - indicator: ErrorBoundary.wrap(Indicator, { noop: true }) -}); - -export function encrypt(secret: string, password: string, cover: string): string { - return steggo.hide(secret + "\u200b", password, cover); -} - -export function decrypt(encrypted: string, password: string, removeIndicator: boolean): string { - const decrypted = steggo.reveal(encrypted, password); - return removeIndicator ? decrypted.replace("\u200b", "") : decrypted; -} - -export function isCorrectPassword(result: string): boolean { - return result.endsWith("\u200b"); -} - -export async function iteratePasswords(message: Message): Promise { - const passwords = settings.store.savedPasswords.split(",").map(s => s.trim()); - - if (!message?.content || !passwords?.length) return false; - - let { content } = message; - - // we use an extra variable so we dont have to edit the message content directly - if (/^\W/.test(message.content)) content = `d ${message.content}d`; - - for (let i = 0; i < passwords.length; i++) { - const result = decrypt(content, passwords[i], false); - if (isCorrectPassword(result)) { - return result; - } - } - - return false; -} diff --git a/src/plugins/petpet.ts b/src/plugins/petpet.ts index 9b1c2f1..0bfd21a 100644 --- a/src/plugins/petpet.ts +++ b/src/plugins/petpet.ts @@ -18,10 +18,10 @@ import { ApplicationCommandInputType, ApplicationCommandOptionType, Argument, CommandContext, findOption, sendBotMessage } from "@api/Commands"; import { Devs } from "@utils/constants"; -import { getGifEncoder } from "@utils/dependencies"; import { makeLazy } from "@utils/lazy"; import definePlugin from "@utils/types"; import { findByCodeLazy, findByPropsLazy } from "@webpack"; +import { applyPalette, GIFEncoder, quantize } from "gifenc"; const DRAFT_TYPE = 0; const DEFAULT_DELAY = 20; @@ -124,7 +124,6 @@ export default definePlugin({ } ], execute: async (opts, cmdCtx) => { - const { GIFEncoder, quantize, applyPalette } = await getGifEncoder(); const frames = await getFrames(); const noServerPfp = findOption(opts, "no-server-pfp", false); @@ -143,7 +142,7 @@ export default definePlugin({ const delay = findOption(opts, "delay", DEFAULT_DELAY); const resolution = findOption(opts, "resolution", DEFAULT_RESOLUTION); - const gif = new GIFEncoder(); + const gif = GIFEncoder(); const canvas = document.createElement("canvas"); canvas.width = canvas.height = resolution; diff --git a/src/plugins/shikiCodeblocks.desktop/api/languages.ts b/src/plugins/shikiCodeblocks.desktop/api/languages.ts new file mode 100644 index 0000000..f14a4dc --- /dev/null +++ b/src/plugins/shikiCodeblocks.desktop/api/languages.ts @@ -0,0 +1,74 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 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 { ILanguageRegistration } from "@vap/shiki"; + +export const VPC_REPO = "Vap0r1ze/vapcord"; +export const VPC_REPO_COMMIT = "88a7032a59cca40da170926651b08201ea3b965a"; +export const vpcRepoAssets = `https://raw.githubusercontent.com/${VPC_REPO}/${VPC_REPO_COMMIT}/assets/shiki-codeblocks`; +export const vpcRepoGrammar = (fileName: string) => `${vpcRepoAssets}/${fileName}`; +export const vpcRepoLanguages = `${vpcRepoAssets}/languages.json`; + +export interface Language { + name: string; + id: string; + devicon?: string; + grammarUrl: string, + grammar?: ILanguageRegistration["grammar"]; + scopeName: string; + aliases?: string[]; + custom?: boolean; +} +export interface LanguageJson { + name: string; + id: string; + fileName: string; + devicon?: string; + scopeName: string; + aliases?: string[]; +} + +export const languages: Record = {}; + +export const loadLanguages = async () => { + const langsJson: LanguageJson[] = await fetch(vpcRepoLanguages).then(res => res.json()); + const loadedLanguages = Object.fromEntries( + langsJson.map(lang => [lang.id, { + ...lang, + grammarUrl: vpcRepoGrammar(lang.fileName), + }]) + ); + Object.assign(languages, loadedLanguages); +}; + +export const getGrammar = (lang: Language): Promise> => { + if (lang.grammar) return Promise.resolve(lang.grammar); + return fetch(lang.grammarUrl).then(res => res.json()); +}; + +const aliasCache = new Map(); +export function resolveLang(idOrAlias: string) { + if (Object.prototype.hasOwnProperty.call(languages, idOrAlias)) return languages[idOrAlias]; + + const lang = Object.values(languages).find(lang => lang.aliases?.includes(idOrAlias)); + + if (!lang) return null; + + aliasCache.set(idOrAlias, lang); + return lang; +} diff --git a/src/plugins/shikiCodeblocks.desktop/api/shiki.ts b/src/plugins/shikiCodeblocks.desktop/api/shiki.ts new file mode 100644 index 0000000..91e179b --- /dev/null +++ b/src/plugins/shikiCodeblocks.desktop/api/shiki.ts @@ -0,0 +1,118 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 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 { shikiOnigasmSrc, shikiWorkerSrc } from "@utils/dependencies"; +import { WorkerClient } from "@vap/core/ipc"; +import type { IShikiTheme, IThemedToken } from "@vap/shiki"; + +import { dispatchTheme } from "../hooks/useTheme"; +import type { ShikiSpec } from "../types"; +import { getGrammar, languages, loadLanguages, resolveLang } from "./languages"; +import { themes } from "./themes"; + +const themeUrls = Object.values(themes); + +let resolveClient: (client: WorkerClient) => void; + +export const shiki = { + client: null as WorkerClient | null, + currentTheme: null as IShikiTheme | null, + currentThemeUrl: null as string | null, + timeoutMs: 10000, + languages, + themes, + loadedThemes: new Set(), + loadedLangs: new Set(), + clientPromise: new Promise>(resolve => resolveClient = resolve), + + init: async (initThemeUrl: string | undefined) => { + /** https://stackoverflow.com/q/58098143 */ + const workerBlob = await fetch(shikiWorkerSrc).then(res => res.blob()); + + const client = shiki.client = new WorkerClient( + "shiki-client", + "shiki-host", + workerBlob, + { name: "ShikiWorker" }, + ); + await client.init(); + + const themeUrl = initThemeUrl || themeUrls[0]; + + await loadLanguages(); + await client.run("setOnigasm", { wasm: shikiOnigasmSrc }); + await client.run("setHighlighter", { theme: themeUrl, langs: [] }); + shiki.loadedThemes.add(themeUrl); + await shiki._setTheme(themeUrl); + resolveClient(client); + }, + _setTheme: async (themeUrl: string) => { + shiki.currentThemeUrl = themeUrl; + const { themeData } = await shiki.client!.run("getTheme", { theme: themeUrl }); + shiki.currentTheme = JSON.parse(themeData); + dispatchTheme({ id: themeUrl, theme: shiki.currentTheme }); + }, + loadTheme: async (themeUrl: string) => { + const client = await shiki.clientPromise; + if (shiki.loadedThemes.has(themeUrl)) return; + + await client.run("loadTheme", { theme: themeUrl }); + + shiki.loadedThemes.add(themeUrl); + }, + setTheme: async (themeUrl: string) => { + await shiki.clientPromise; + themeUrl ||= themeUrls[0]; + if (!shiki.loadedThemes.has(themeUrl)) await shiki.loadTheme(themeUrl); + + await shiki._setTheme(themeUrl); + }, + loadLang: async (langId: string) => { + const client = await shiki.clientPromise; + const lang = resolveLang(langId); + + if (!lang || shiki.loadedLangs.has(lang.id)) return; + + await client.run("loadLanguage", { + lang: { + ...lang, + grammar: lang.grammar ?? await getGrammar(lang), + } + }); + shiki.loadedLangs.add(lang.id); + }, + tokenizeCode: async (code: string, langId: string): Promise => { + const client = await shiki.clientPromise; + const lang = resolveLang(langId); + if (!lang) return []; + + if (!shiki.loadedLangs.has(lang.id)) await shiki.loadLang(lang.id); + + return await client.run("codeToThemedTokens", { + code, + lang: langId, + theme: shiki.currentThemeUrl ?? themeUrls[0], + }); + }, + destroy() { + shiki.currentTheme = null; + shiki.currentThemeUrl = null; + dispatchTheme({ id: null, theme: null }); + shiki.client?.destroy(); + } +}; diff --git a/src/plugins/shikiCodeblocks.desktop/api/themes.ts b/src/plugins/shikiCodeblocks.desktop/api/themes.ts new file mode 100644 index 0000000..f31ce60 --- /dev/null +++ b/src/plugins/shikiCodeblocks.desktop/api/themes.ts @@ -0,0 +1,67 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2022 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; with