3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Add time_and_date plugin. Use it for timezones and date formats around the bot.

This commit is contained in:
Dragory 2020-08-19 00:19:12 +03:00
parent cffb0dbd6b
commit 4ae8cf85a3
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
67 changed files with 543 additions and 177 deletions

View file

@ -6,16 +6,16 @@ import moment from "moment-timezone";
import { CaseTypes } from "src/data/CaseTypes";
import humanizeDuration from "humanize-duration";
import { snowflakeToTimestamp } from "../../../utils/snowflakeToTimestamp";
import { inGuildTz } from "../../../utils/timezones";
import { getDateFormat } from "../../../utils/dateFormats";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
const SNOWFLAKE_ICON = "https://cdn.discordapp.com/attachments/740650744830623756/742020790471491668/snowflake.png";
export function getSnowflakeInfoEmbed(
export async function getSnowflakeInfoEmbed(
pluginData: PluginData<UtilityPluginType>,
snowflake: string,
showUnknownWarning = false,
): EmbedOptions {
requestMemberId?: string,
): Promise<EmbedOptions> {
const embed: EmbedOptions = {
fields: [],
};
@ -30,9 +30,13 @@ export function getSnowflakeInfoEmbed(
"This is a valid [snowflake ID](https://discord.com/developers/docs/reference#snowflakes), but I don't know what it's for.";
}
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
const createdAtMS = snowflakeToTimestamp(snowflake);
const createdAt = moment.utc(createdAtMS, "x");
const prettyCreatedAt = inGuildTz(pluginData, createdAt).format(getDateFormat(pluginData, "pretty_datetime"));
const tzCreatedAt = requestMemberId
? await timeAndDate.inMemberTz(requestMemberId, createdAt)
: timeAndDate.inGuildTz(createdAt);
const prettyCreatedAt = tzCreatedAt.format(timeAndDate.getDateFormat("pretty_datetime"));
const snowflakeAge = humanizeDuration(Date.now() - createdAtMS, {
largest: 2,
round: true,