-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(creationDate): use SnowflakeUtil
- Loading branch information
Showing
1 changed file
with
15 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
const {Time} = require('../../utils/helpers/customParser.js'); | ||
const { Time } = require('../../utils/helpers/customParser.js'); | ||
const { SnowflakeUtil } = require('discord.js'); | ||
|
||
module.exports = async d => { | ||
const {code, inside, err} = d.util.aoiFunc(d); | ||
if (err) return d.error(err); | ||
const data = d.util.aoiFunc(d); | ||
if (data.err) return d.error(data.err); | ||
|
||
const [id, format = "date"] = inside.splits; | ||
const [id, format = "date"] = data.inside.splits; | ||
|
||
const Id = await d.util.findId(d, id) | ||
if (!Id) return d.aoiError.fnError(d, "custom", {inside}, "Invalid Id Provided In"); | ||
if (!id) return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Id"); | ||
|
||
let result; | ||
if (format === "date") result = new Date(Id.createdTimestamp).toLocaleString("en-us", {timeZone: d.timezone ?? "en-us"}) | ||
else if (format === "time-full" || format === "time") result = Time.format((Date.now() - Id.createdTimestamp)).toString() | ||
else if (format === "time-humanize") result = Time.format((Date.now() - (Id.createdTimestamp) || 0)).humanize() | ||
else result = Id.createdTimestamp; | ||
const timestamp = Number(SnowflakeUtil.deconstruct(id).timestamp); | ||
if (format === "date") result = new Date(timestamp).toLocaleString("en-us", {timeZone: d.timezone ?? "en-us"}) | ||
else if (format === "time-full" || format === "time") result = Time.format((Date.now() - timestamp)).toString() | ||
else if (format === "time-humanize") result = Time.format((Date.now() - timestamp) || 0).humanize() | ||
else result = timestamp; | ||
|
||
data.result = result; | ||
|
||
return { | ||
code: d.util.setCode({function: d.func, code, inside, result}) | ||
code: d.util.setCode(data) | ||
} | ||
} |