From 1a37064f2eae0cbf94ea3e1c02e52dbc6e1de6f4 Mon Sep 17 00:00:00 2001 From: thororen <78185467+thororen1234@users.noreply.github.com> Date: Sat, 4 May 2024 00:50:59 -0400 Subject: [PATCH] Requests & Updates --- src/equicordplugins/friendshipRanks/index.tsx | 149 ++++++ src/equicordplugins/imageLink/index.ts | 24 - .../components/ThemeInfoModal.tsx | 154 ++++++ .../themeLibrary/components/ThemeTab.tsx | 496 ++++++++++++++++++ .../themeLibrary/components/styles.css | 54 ++ src/equicordplugins/themeLibrary/index.ts | 39 ++ src/equicordplugins/themeLibrary/types.ts | 56 ++ src/plugins/imageLink/README.md | 3 - src/plugins/pauseInvitesForever/README.md | 5 - src/utils/constants.ts | 4 + 10 files changed, 952 insertions(+), 32 deletions(-) create mode 100644 src/equicordplugins/friendshipRanks/index.tsx delete mode 100644 src/equicordplugins/imageLink/index.ts create mode 100644 src/equicordplugins/themeLibrary/components/ThemeInfoModal.tsx create mode 100644 src/equicordplugins/themeLibrary/components/ThemeTab.tsx create mode 100644 src/equicordplugins/themeLibrary/components/styles.css create mode 100644 src/equicordplugins/themeLibrary/index.ts create mode 100644 src/equicordplugins/themeLibrary/types.ts delete mode 100644 src/plugins/imageLink/README.md delete mode 100644 src/plugins/pauseInvitesForever/README.md diff --git a/src/equicordplugins/friendshipRanks/index.tsx b/src/equicordplugins/friendshipRanks/index.tsx new file mode 100644 index 00000000..52d0f1fa --- /dev/null +++ b/src/equicordplugins/friendshipRanks/index.tsx @@ -0,0 +1,149 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { BadgeUserArgs, ProfileBadge } from "@api/Badges"; +import ErrorBoundary from "@components/ErrorBoundary"; +import { Devs } from "@utils/constants"; +import { Margins } from "@utils/margins"; +import { Modals, ModalSize, openModal } from "@utils/modal"; +import definePlugin from "@utils/types"; +import { Flex, Forms, RelationshipStore } from "@webpack/common"; + +interface rankInfo { + title: string; + description: string; + requirement: number; + assetURL: string; +} + +function daysSince(dateString: string): number { + const date = new Date(dateString); + const currentDate = new Date(); + + const differenceInMs = currentDate.getTime() - date.getTime(); + + const days = differenceInMs / (1000 * 60 * 60 * 24); + + return Math.floor(days); +} + +const ranks: rankInfo[] = + [ + { + title: "Sprout", + description: "Your friendship is just starting", + requirement: 0, + assetURL: "https://files.catbox.moe/d6gis2.png" + }, + { + title: "Blooming", + description: "Your friendship is getting there! (1 Month)", + requirement: 30, + assetURL: "https://files.catbox.moe/z7fxjq.png" + }, + { + title: "Burning", + description: "Your friendship has reached terminal velocity :o (3 Months)", + requirement: 90, + assetURL: "https://files.catbox.moe/8oiu0o.png" + }, + { + title: "Star", + description: "Your friendship has been going on for a WHILE (1 Year)", + requirement: 365, + assetURL: "https://files.catbox.moe/7bpe7v.png" + }, + { + title: "Royal", + description: "Your friendship has gone through thick and thin- a whole 2 years!", + requirement: 730, + assetURL: "https://files.catbox.moe/0yp9mp.png" + }, + { + title: "Besties", + description: "How do you even manage this??? (5 Years)", + assetURL: "https://files.catbox.moe/qojb7d.webp", + requirement: 1826.25 + } + ]; + +function openRankModal(rank: rankInfo) { + openModal(props => ( + + + + + + Your friendship rank + + + + +
+ + {rank.title} + + + + {rank.description} + +
+
+
+
+ )); +} + +function getBadgesToApply() { + + const badgesToApply: ProfileBadge[] = ranks.map((rank, index, self) => { + return ( + { + description: rank.title, + image: rank.assetURL, + props: { + style: { + transform: "scale(0.8)" + } + }, + shouldShow: (info: BadgeUserArgs) => { + if (!RelationshipStore.isFriend(info.user.id)) { return false; } + + const days = daysSince(RelationshipStore.getSince(info.user.id)); + + if (self[index + 1] == null) { + return days > rank.requirement; + } + + return (days > rank.requirement && days < self[index + 1].requirement); + }, + onClick: () => openRankModal(rank) + }); + }); + return badgesToApply; +} + +export default definePlugin({ + name: "FriendshipRanks", + description: "Adds badges showcasing how long you have been friends with a user for", + authors: [ + Devs.Samwich + ], + start() { + getBadgesToApply().forEach(thing => Vencord.Api.Badges.addBadge(thing)); + + }, + stop() { + getBadgesToApply().forEach(thing => Vencord.Api.Badges.removeBadge(thing)); + }, +}); diff --git a/src/equicordplugins/imageLink/index.ts b/src/equicordplugins/imageLink/index.ts deleted file mode 100644 index d3cce116..00000000 --- a/src/equicordplugins/imageLink/index.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Vencord, a Discord client mod - * Copyright (c) 2024 Vendicated and contributors - * SPDX-License-Identifier: GPL-3.0-or-later - */ - -import { Devs } from "@utils/constants"; -import definePlugin from "@utils/types"; - -export default definePlugin({ - name: "ImageLink", - description: "Suppresses the hiding of links for \"simple embeds\"", - authors: [Devs.Kyuuhachi], - - patches: [ - { - find: "isEmbedInline:function", - replacement: { - match: /(?<=isEmbedInline:function\(\)\{return )\w+(?=\})/, - replace: "()=>false", - }, - }, - ], -}); diff --git a/src/equicordplugins/themeLibrary/components/ThemeInfoModal.tsx b/src/equicordplugins/themeLibrary/components/ThemeInfoModal.tsx new file mode 100644 index 00000000..ce5d2652 --- /dev/null +++ b/src/equicordplugins/themeLibrary/components/ThemeInfoModal.tsx @@ -0,0 +1,154 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { CodeBlock } from "@components/CodeBlock"; +import { Heart } from "@components/Heart"; +import { openInviteModal } from "@utils/discord"; +import { Margins } from "@utils/margins"; +import { ModalContent, ModalFooter, ModalHeader, ModalRoot, openModal } from "@utils/modal"; +import { findComponentByCodeLazy } from "@webpack"; +import { Button, Clipboard, Forms, React, showToast, Toasts } from "@webpack/common"; + +import { ThemeInfoModalProps } from "../types"; + +const UserSummaryItem = findComponentByCodeLazy("defaultRenderUser", "showDefaultAvatarsForNullUsers"); + +export const ThemeInfoModal: React.FC = ({ author, theme, ...props }) => { + + const content = atob(theme.content); + const metadata = content.match(/\/\*\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\//g)?.[0] || ""; + const donate = metadata.match(/@donate\s+(.+)/)?.[1] || ""; + const version = metadata.match(/@version\s+(.+)/)?.[1] || ""; + + return ( + + + Theme Details + + + + Author +
+
+
+ + + + {author.username} + +
+ Source + + + + + + ))} + > + View Theme Source + + + {version && ( + <> + Version + + {version} + + + )} + {donate && ( + <> + Donate + + You can support the author by donating below. + + + + + + )} + {theme.guild && ( + <> + Support Server + + {theme.guild.name} + + + + + + )} + {theme.tags && ( + <> + Tags + + {theme.tags.map(tag => ( + + {tag} + + ))} + + + )} +
+
+
+ + + +
+ ); +}; diff --git a/src/equicordplugins/themeLibrary/components/ThemeTab.tsx b/src/equicordplugins/themeLibrary/components/ThemeTab.tsx new file mode 100644 index 00000000..a3be760f --- /dev/null +++ b/src/equicordplugins/themeLibrary/components/ThemeTab.tsx @@ -0,0 +1,496 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./styles.css"; + +import { generateId } from "@api/Commands"; +import { classNameFactory } from "@api/Styles"; +import { CodeBlock } from "@components/CodeBlock"; +import { SettingsTab, wrapTab } from "@components/VencordSettings/shared"; +import { proxyLazy } from "@utils/lazy"; +import { Margins } from "@utils/margins"; +import { classes } from "@utils/misc"; +import { openModal } from "@utils/modal"; +import { findByPropsLazy, findLazy } from "@webpack"; +import { Button, Card, FluxDispatcher, Forms, React, Select, showToast, TabBar, TextArea, TextInput, Toasts, useEffect, UserStore, UserUtils, useState } from "@webpack/common"; +import { User } from "discord-types/general"; +import { Constructor } from "type-fest"; + +import { SearchStatus, TabItem, Theme } from "../types"; +import { ThemeInfoModal } from "./ThemeInfoModal"; + +const cl = classNameFactory("vc-plugins-"); +const InputStyles = findByPropsLazy("inputDefault", "inputWrapper"); +const UserRecord: Constructor> = proxyLazy(() => UserStore.getCurrentUser().constructor) as any; +const TextAreaProps = findLazy(m => typeof m.textarea === "string"); + +const API_URL = "https://themes-delta.vercel.app/api"; + +async function themeRequest(path: string, options: RequestInit = {}) { + return fetch(API_URL + path, { + ...options, + headers: { + ...options.headers, + } + }); +} + +function makeDummyUser(user: { username: string; id?: string; avatar?: string; }) { + const newUser = new UserRecord({ + username: user.username, + id: user.id ?? generateId(), + avatar: user.avatar, + bot: true, + }); + FluxDispatcher.dispatch({ + type: "USER_UPDATE", + user: newUser, + }); + return newUser; +} + +const themeTemplate = `/** +* @name [Theme name] +* @author [Your name] +* @description [Your Theme Description] +* @version [Your Theme Version] +* @donate [Optionally, your Donation Link] +* @tags [Optionally, tags that apply to your theme] +* @invite [Optionally, your Support Server Invite] +* @source [Optionally, your source code link] +*/ + +/* Your CSS goes here */ +`; + +function ThemeTab() { + const [themes, setThemes] = useState([]); + const [filteredThemes, setFilteredThemes] = useState([]); + const [themeLinks, setThemeLinks] = useState(Vencord.Settings.themeLinks); + const [searchValue, setSearchValue] = useState({ value: "", status: SearchStatus.ALL }); + const [loading, setLoading] = useState(true); + + const getUser = (id: string, username: string) => UserUtils.getUser(id) ?? makeDummyUser({ username, id }); + const onSearch = (query: string) => setSearchValue(prev => ({ ...prev, value: query })); + const onStatusChange = (status: SearchStatus) => setSearchValue(prev => ({ ...prev, status })); + + const themeFilter = (theme: Theme) => { + const enabled = themeLinks.includes("https://themes-delta.vercel.app/api/" + theme.name); + if (enabled && searchValue.status === SearchStatus.DISABLED) return false; + if (!theme.tags.includes("theme") && searchValue.status === SearchStatus.THEME) return false; + if (!theme.tags.includes("snippet") && searchValue.status === SearchStatus.SNIPPET) return false; + if (!theme.tags.includes("dark") && searchValue.status === SearchStatus.DARK) return false; + if (!theme.tags.includes("light") && searchValue.status === SearchStatus.LIGHT) return false; + if (!enabled && searchValue.status === SearchStatus.ENABLED) return false; + if (!searchValue.value.length) return true; + + const v = searchValue.value.toLowerCase(); + return ( + theme.name.toLowerCase().includes(v) || + theme.description.toLowerCase().includes(v) || + theme.author.discord_name.toLowerCase().includes(v) || + theme.tags?.some(t => t.toLowerCase().includes(v)) + ); + }; + + useEffect(() => { + themeRequest("/themes", { + method: "GET", + }).then(async (response: Response) => { + const data = await response.json(); + const themes: Theme[] = Object.values(data); + themes.sort((a, b) => new Date(b.release_date).getTime() - new Date(a.release_date).getTime()); + setThemes(themes); + setFilteredThemes(themes); + setLoading(false); + }); + }, []); + + useEffect(() => { + setThemeLinks(Vencord.Settings.themeLinks); + }, [Vencord.Settings.themeLinks]); + + useEffect(() => { + const filteredThemes = themes.filter(themeFilter); + setFilteredThemes(filteredThemes); + }, [searchValue]); + + return ( +
+ <> + {loading ? ( +
Loading Themes...
+ ) : (<> +
+ + Newest Additions + + + {themes.slice(0, 2).map((theme: Theme) => ( + + + {theme.name} + + + {theme.description} + +
+
+ {theme.tags && ( + + {theme.tags.map(tag => ( + + {tag} + + ))} + + )} +
+ {themeLinks.includes("https://themes-delta.vercel.app/api/" + theme.name) ? ( + + ) : ( + + )} + + +
+
+
+
+ ))} +
+ + Themes + +
+ +
+