2020-10-01 01:43:38 +03:00
|
|
|
import { GuildPluginData } from "knub";
|
2020-08-09 17:28:21 +03:00
|
|
|
import { UtilityPluginType } from "../types";
|
2020-11-09 20:03:57 +02:00
|
|
|
import {
|
|
|
|
UnknownUser,
|
|
|
|
trimLines,
|
|
|
|
embedPadding,
|
|
|
|
resolveMember,
|
|
|
|
resolveUser,
|
|
|
|
preEmbedPadding,
|
|
|
|
EmbedWith,
|
|
|
|
} from "../../../utils";
|
2020-08-09 17:28:21 +03:00
|
|
|
import moment from "moment-timezone";
|
2020-10-01 01:43:38 +03:00
|
|
|
import { CaseTypes } from "../../../data/CaseTypes";
|
2020-08-09 17:28:21 +03:00
|
|
|
import humanizeDuration from "humanize-duration";
|
|
|
|
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
|
2020-08-19 00:19:12 +03:00
|
|
|
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
2021-06-02 04:07:50 +02:00
|
|
|
import { MessageEmbedOptions } from "discord.js";
|
2020-08-09 17:28:21 +03:00
|
|
|
|
|
|
|
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
|
|
|
|
|
2020-08-19 00:19:12 +03:00
|
|
|
export async function getSnowflakeInfoEmbed(
|
2020-10-01 01:43:38 +03:00
|
|
|
pluginData: GuildPluginData<UtilityPluginType>,
|
2020-08-09 17:28:21 +03:00
|
|
|
snowflake: string,
|
|
|
|
showUnknownWarning = false,
|
2020-08-19 00:19:12 +03:00
|
|
|
requestMemberId?: string,
|
2021-06-02 04:07:50 +02:00
|
|
|
): Promise<MessageEmbedOptions> {
|
2020-11-09 20:03:57 +02:00
|
|
|
const embed: EmbedWith<"fields"> = {
|
2020-08-09 17:28:21 +03:00
|
|
|
fields: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
embed.author = {
|
|
|
|
name: `Snowflake: ${snowflake}`,
|
|
|
|
icon_url: SNOWFLAKE_ICON,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (showUnknownWarning) {
|
|
|
|
embed.description =
|
|
|
|
"This is a valid [snowflake ID](https://discord.com/developers/docs/reference#snowflakes), but I don't know what it's for.";
|
|
|
|
}
|
|
|
|
|
2020-08-19 00:19:12 +03:00
|
|
|
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
|
2020-08-09 17:28:21 +03:00
|
|
|
const createdAtMS = snowflakeToTimestamp(snowflake);
|
2020-08-10 00:24:06 +03:00
|
|
|
const createdAt = moment.utc(createdAtMS, "x");
|
2020-08-19 00:19:12 +03:00
|
|
|
const tzCreatedAt = requestMemberId
|
|
|
|
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
|
|
|
|
: timeAndDate.inGuildTz(createdAt);
|
|
|
|
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
|
2020-08-09 17:28:21 +03:00
|
|
|
const snowflakeAge = humanizeDuration(Date.now() - createdAtMS, {
|
|
|
|
largest: 2,
|
|
|
|
round: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
embed.fields.push({
|
|
|
|
name: preEmbedPadding + "Basic information",
|
2020-08-10 00:24:06 +03:00
|
|
|
value: `Created: **${snowflakeAge} ago** (\`${prettyCreatedAt}\`)`,
|
2020-08-09 17:28:21 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return embed;
|
|
|
|
}
|