From f60e37105039bec1eaa30829b1eaea3d2cc5e114 Mon Sep 17 00:00:00 2001 From: Manti <67705577+mantikafasi@users.noreply.github.com> Date: Fri, 14 Apr 2023 17:05:24 +0300 Subject: [PATCH] add slash command and small error handling --- src/plugins/Timezones/Utils.ts | 9 ++++++--- src/plugins/Timezones/index.tsx | 11 +++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins/Timezones/Utils.ts b/src/plugins/Timezones/Utils.ts index cfc4772e3..14c1ee920 100644 --- a/src/plugins/Timezones/Utils.ts +++ b/src/plugins/Timezones/Utils.ts @@ -33,9 +33,12 @@ const Cache: Record = {}; const PreloadedUserSettings = findLazy(m => m.ProtoClass?.typeName === "discord_protos.discord_users.v1.PreloadedUserSettings"); export function getTimeString(timezone: string, timestamp = new Date()): string { - const locale = PreloadedUserSettings.getCurrentValue().localization.locale.value; - - return new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "numeric", timeZone: timezone }).format(timestamp); // we hate javascript + try { + const locale = PreloadedUserSettings.getCurrentValue().localization.locale.value; + return new Intl.DateTimeFormat(locale, { hour: "numeric", minute: "numeric", timeZone: timezone }).format(timestamp); // we hate javascript + } catch (e) { + return "Error"; // incase it gets invalid timezone from api, probably not gonna happen but if it does this will prevent discord from crashing + } } diff --git a/src/plugins/Timezones/index.tsx b/src/plugins/Timezones/index.tsx index 53440d7a7..47609a656 100644 --- a/src/plugins/Timezones/index.tsx +++ b/src/plugins/Timezones/index.tsx @@ -32,6 +32,7 @@ const EditIcon = findByCodeLazy("M19.2929 9.8299L19.9409 9.18278C21.353 7.77064 const DeleteIcon = findByCodeLazy("M15 3.999V2H9V3.999H3V5.999H21V3.999H15Z"); const classNames = findByPropsLazy("customStatusSection"); + import { API_URL, DATASTORE_KEY, getAllTimezones, getTimeString, getUserTimezone, TimezoneDB } from "./Utils"; const styles = findByPropsLazy("timestampInline"); @@ -44,6 +45,16 @@ export default definePlugin({ description: "Allows you to see and set the timezones of other users.", authors: [Devs.mantikafasi, Devs.Arjix], + commands: [ + { + name: "timezone", + description: "Sends link to a website that shows timezone string, useful if you want to know your friends timezone", + execute: () => { + return { content: "https://gh.lewisakura.moe/timezone/" }; + } + } + ], + settingsAboutComponent: () => { const href = `${API_URL}?client_mod=${encodeURIComponent(VENCORD_USER_AGENT)}`; return (