commit abd0b2c29453ebb239ba223d04de926e5aa4aff1 Author: nin0dev Date: Sat Aug 3 08:39:44 2024 -0400 initial commit 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 +