From abd0b2c29453ebb239ba223d04de926e5aa4aff1 Mon Sep 17 00:00:00 2001 From: nin0dev Date: Sat, 3 Aug 2024 08:39:44 -0400 Subject: [PATCH] initial commit --- ReplaceSettings.tsx | 224 ++++++++++++++++++++++++++++++++++++++++++++ index.tsx | 155 ++++++++++++++++++++++++++++++ style.css | 14 +++ 3 files changed, 393 insertions(+) create mode 100644 ReplaceSettings.tsx create mode 100644 index.tsx create mode 100644 style.css diff --git a/ReplaceSettings.tsx b/ReplaceSettings.tsx new file mode 100644 index 0000000..c0414fc --- /dev/null +++ b/ReplaceSettings.tsx @@ -0,0 +1,224 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { CheckedTextInput } from "@components/CheckedTextInput"; +import { Margins } from "@utils/margins"; +import { identity } from "@utils/misc"; +import { Card, Forms, PresenceStore, React, Select, SnowflakeUtils, Switch, TextInput, UserStore } from "@webpack/common"; + +import { Activity, ActivityType, AppIdSetting, makeEmptyAppId } from "."; + +interface SettingsProps { + appIds: AppIdSetting[]; + update: () => void; + save: () => void; +} + +function isValidSnowflake(v: string) { + const regex = /^\d{17,20}$/; + return regex.test(v) && !Number.isNaN(SnowflakeUtils.extractTimestamp(v)); +} + +export function ReplaceTutorial() { + const activities: Activity[] = PresenceStore.getActivities(UserStore.getCurrentUser().id); + return ( + <> + IDs of currently running activities + { + activities.length === 0 ? No running activities : activities.map(activity => { return activity.flags !== 48 ? {activity.name}: {activity.application_id} : null; /* hide spotify */ }) + } + Available variables + + In all fields (except stream URL), you can put in variables that'll automatically be replaced by their original content: +
+                    :name:, :details:, :state:
+                    
+ :large_image:, :large_text:, :small_image:, :small_text: +
+
+ More details + + Leave a field empty to leave it as is. +
+ Set a field to "null" to hide it on the presence. +
+ You may need to reload Discord for changes to apply. +
+ + ); +} + +export function ReplaceSettings({ appIds, update, save }: SettingsProps) { + async function onChange(val: string | boolean, index: number, key: string) { + if (index === appIds.length - 1) + appIds.push(makeEmptyAppId()); + + appIds[index][key] = val; + + save(); + update(); + } + + return ( + <> + { + appIds.map((setting, i) => + + { + isValidSnowflake(setting.appId) ? + { + onChange(value, i, "enabled"); + }} + className={Margins.bottom8} + hideBorder={true} + > + Apply edits to app + : Add new application + } + Application ID + { + onChange(v, i, "appId"); + }} + validate={v => + !v || isValidSnowflake(v) || "Invalid application ID" + } + /> + { + isValidSnowflake(setting.appId) && <> + New activity type +