add slash command and small error handling

This commit is contained in:
Manti 2023-04-14 17:05:24 +03:00
parent aeff943207
commit f60e371050
2 changed files with 17 additions and 3 deletions

View file

@ -33,9 +33,12 @@ const Cache: Record<string, string> = {};
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
}
}

View file

@ -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 (