From 5c0f1601c2a8e684c2f1788ed98b6adfff9703aa Mon Sep 17 00:00:00 2001 From: programminglaboratorys Date: Tue, 1 Oct 2024 20:45:13 +0300 Subject: [PATCH] re-implementing setStatus Co-authored-by: Nuckyz <61953774+Nuckyz@users.noreply.github.com> --- src/plugins/statusPresets/index.tsx | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/plugins/statusPresets/index.tsx b/src/plugins/statusPresets/index.tsx index 8763c1b92..f28e88c99 100644 --- a/src/plugins/statusPresets/index.tsx +++ b/src/plugins/statusPresets/index.tsx @@ -24,7 +24,7 @@ import ErrorBoundary from "@components/ErrorBoundary"; import { Devs } from "@utils/constants"; import { classes } from "@utils/misc"; import definePlugin, { OptionType, StartAt } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy, findComponentByCodeLazy } from "@webpack"; +import { findByPropsLazy, findComponentByCodeLazy } from "@webpack"; import { Button, Clickable, Icons, Menu, Toasts, UserStore, useState } from "@webpack/common"; const settings = definePluginSettings({ @@ -45,19 +45,35 @@ interface Emoji { interface DiscordStatus { emojiInfo: Emoji | null; text: string; - clearAfter: string | number | null; + clearAfter: "TODAY" | number | null; status: "online" | "dnd" | "idle" | "invisible"; } const StatusStyles = findByPropsLazy("statusItem"); -const setStatus = findByCodeLazy(".CUSTOM_STATUS_UPDATED,{"); const PMenu = findComponentByCodeLazy(".menuItemLabel", ".menuItemInner"); const EmojiComponent = findComponentByCodeLazy(".translateSurrogatesToInlineEmoji("); -const customStatusSettings = getUserSettingLazy("status", "customStatus"); +const CustomStatusSettings = getUserSettingLazy("status", "customStatus")!; -const ClearStatusButton = () => { e.stopPropagation(); customStatusSettings?.updateSetting(null); }}>; +function getExpirationMs(expiration: "TODAY" | number) { + if (expiration !== "TODAY") return Date.now() + expiration; + + const now = new Date(); + return new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime(); +} + +function setStatus(status: DiscordStatus) { + CustomStatusSettings.updateSetting({ + text: status.text.trim(), + expiresAtMs: status.clearAfter != null ? String(getExpirationMs(status.clearAfter)) : "0", + emojiId: status.emojiInfo?.id ?? "0", + emojiName: status.emojiInfo?.name ?? "", + createdAtMs: String(Date.now()) + }); +} + +const ClearStatusButton = () => { e.stopPropagation(); CustomStatusSettings?.updateSetting(null); }}>; function StatusIcon({ isHovering, status }: { isHovering: boolean; status: DiscordStatus; }) { return
{isHovering ? @@ -96,7 +112,7 @@ const StatusSubMenuComponent = () => { {Object.entries((settings.store.StatusPresets as { [k: string]: DiscordStatus; })).map(([index, status]) => (status.emojiInfo?.id != null && UserStore.getCurrentUser().hasPremiumPerks || status.emojiInfo?.id == null) && setStatus(status.text, status.emojiInfo, status.clearAfter, { "location": { "section": "Account Panel", "object": "Avatar" } })} + action={() => (status.emojiInfo?.id != null && UserStore.getCurrentUser().hasPremiumPerks || status.emojiInfo?.id == null) && setStatus(status)} render={() =>