From e5c3c2911d77e79b9ef35d72fb35833a262c3cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pedro=20Borges=20Martins?= Date: Wed, 11 Jan 2023 21:26:51 -0300 Subject: [PATCH] chore(genLog): use `@naval-base/ms` for conversion --- .../src/functions/logging/generateCaseLog.ts | 4 ++-- apps/yuudachi/src/util/findClosestDuration.ts | 24 ------------------- 2 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 apps/yuudachi/src/util/findClosestDuration.ts diff --git a/apps/yuudachi/src/functions/logging/generateCaseLog.ts b/apps/yuudachi/src/functions/logging/generateCaseLog.ts index fb40fb9e0..b43f4ddeb 100644 --- a/apps/yuudachi/src/functions/logging/generateCaseLog.ts +++ b/apps/yuudachi/src/functions/logging/generateCaseLog.ts @@ -1,9 +1,9 @@ +import { ms } from "@naval-base/ms"; import { logger, kSQL, container } from "@yuudachi/framework"; import { Client, type Snowflake, hyperlink, time, TimestampStyles, messageLink, channelLink } from "discord.js"; import i18next from "i18next"; import type { Sql } from "postgres"; import { caseActionLabel } from "../../util/actionKeys.js"; -import { findClosestDuration } from "../../util/findClosestDuration.js"; import { type Case, CaseAction } from "../cases/createCase.js"; import { getGuildSetting, SettingsKeys } from "../settings/getGuildSetting.js"; @@ -40,7 +40,7 @@ export async function generateCaseLog(case_: Case, logChannelId: Snowflake, loca const expirationDate = new Date(case_.actionExpiration); msg += i18next.t("log.mod_log.case_log.duration", { - time: findClosestDuration(expirationDate.getTime() - Date.now()), + time: ms(expirationDate.getTime() - Date.now()), timestamp: time(expirationDate, TimestampStyles.RelativeTime), lng: locale, }); diff --git a/apps/yuudachi/src/util/findClosestDuration.ts b/apps/yuudachi/src/util/findClosestDuration.ts deleted file mode 100644 index d703b0817..000000000 --- a/apps/yuudachi/src/util/findClosestDuration.ts +++ /dev/null @@ -1,24 +0,0 @@ -const DurationLabel = { - "1m": 60 * 1_000, - "5m": 5 * 60 * 1_000, - "10m": 10 * 60 * 1_000, - "1h": 60 * 60 * 1_000, - "3h": 3 * 60 * 60 * 1_000, - "6h": 6 * 60 * 60 * 1_000, - "12h": 12 * 60 * 60 * 1_000, - "1d": 24 * 60 * 60 * 1_000, - "2d": 2 * 24 * 60 * 60 * 1_000, - "3d": 3 * 24 * 60 * 60 * 1_000, - "7d": 7 * 24 * 60 * 60 * 1_000, -}; - -export function findClosestDuration(value: number): string { - const keys = Object.keys(DurationLabel); - const durations = Object.values(DurationLabel); - - const closest = durations.reduce((prev, curr) => { - return Math.abs(curr - value) < Math.abs(prev - value) ? curr : prev; - }); - - return keys[durations.indexOf(closest)]!; -}