mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-25 07:48:32 +00:00
removed some questionable code
This commit is contained in:
parent
f078181598
commit
45d678d52a
2 changed files with 17 additions and 20 deletions
|
@ -23,33 +23,30 @@ const API_URL = "https://timezonedb.catvibers.me/";
|
|||
const Cache = new Map();
|
||||
export const moment: typeof import("moment") = findByPropsLazy("parseTwoDigitYear");
|
||||
|
||||
export interface Timezone {
|
||||
userID: string,
|
||||
timezoneId: string,
|
||||
timezone: string;
|
||||
error: string;
|
||||
}
|
||||
const getSettings = () => Vencord.Settings.plugins.Timezones;
|
||||
|
||||
export async function getUserTimezone(discordID: string): Promise<Timezone> {
|
||||
export async function getUserTimezone(discordID: string): Promise<Number | null> {
|
||||
|
||||
if (getSettings()[`timezones.${discordID}`])
|
||||
return {
|
||||
timezone: getSettings()[`timezones.${discordID}`],
|
||||
} as Timezone;
|
||||
return Number(getSettings()[`timezones.${discordID}`]);
|
||||
|
||||
if (Cache.has(discordID)) {
|
||||
return Cache.get(discordID).timezone;
|
||||
return Cache.get(discordID);
|
||||
}
|
||||
|
||||
const timezone = await fetch(API_URL + "api/user/" + discordID).then(
|
||||
r => r.json()
|
||||
);
|
||||
Cache.set(discordID, timezone);
|
||||
|
||||
if (timezone.error) {
|
||||
Cache.set(discordID, null);
|
||||
return null;
|
||||
}
|
||||
Cache.set(discordID, timezone.timezone);
|
||||
return timezone.timezone;
|
||||
}
|
||||
|
||||
export function getTimeString(timezone: Timezone, timestamp = moment()): string {
|
||||
export function getTimeString(timezone: Number, timestamp = moment()): string {
|
||||
|
||||
const time = timestamp.utcOffset(Number(timezone));
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import { findByPropsLazy } from "@webpack";
|
|||
import { React } from "@webpack/common";
|
||||
import { Message, User } from "discord-types/general";
|
||||
|
||||
import { getTimeString, getUserTimezone, Timezone } from "./Utils";
|
||||
import { getTimeString, getUserTimezone } from "./Utils";
|
||||
const styles = findByPropsLazy("timestampInline");
|
||||
|
||||
export default definePlugin({
|
||||
|
@ -141,7 +141,7 @@ export default definePlugin({
|
|||
|
||||
const user = e.user as User;
|
||||
|
||||
const [timezone, setTimezone] = React.useState<Timezone | null>(null);
|
||||
const [timezone, setTimezone] = React.useState<Number | null>(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
getUserTimezone(user.id).then(timezone => setTimezone(timezone));
|
||||
|
@ -171,7 +171,7 @@ export default definePlugin({
|
|||
|
||||
const message = e.message as Message;
|
||||
|
||||
const [timezone, setTimezone] = React.useState<Timezone | null>(null);
|
||||
const [timezone, setTimezone] = React.useState<Number | null>(null);
|
||||
|
||||
React.useEffect(() => {
|
||||
getUserTimezone(e.message.author.id).then(timezone => setTimezone(timezone));
|
||||
|
|
Loading…
Add table
Reference in a new issue