From 2c230ec00dcbf2c7d7b52e35e0f857454c30483f Mon Sep 17 00:00:00 2001 From: Dark <7890309+DarkView@users.noreply.github.com> Date: Sat, 11 Apr 2020 17:59:04 +0200 Subject: [PATCH] Added today, timeXAgo, humanizeTime and discordDateFormat --- backend/src/plugins/Tags.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/Tags.ts b/backend/src/plugins/Tags.ts index 4a2511f1..c763fc6b 100644 --- a/backend/src/plugins/Tags.ts +++ b/backend/src/plugins/Tags.ts @@ -1,6 +1,6 @@ import { decorators as d, IPluginOptions, logger } from "knub"; import { Member, Message, TextChannel } from "eris"; -import { errorMessage, successMessage, stripObjectToScalars, tNullable } from "../utils"; +import { errorMessage, successMessage, stripObjectToScalars, tNullable, convertDelayStringToMS } from "../utils"; import { GuildTags } from "../data/GuildTags"; import { GuildSavedMessages } from "../data/GuildSavedMessages"; import { SavedMessage } from "../data/entities/SavedMessage"; @@ -101,6 +101,30 @@ export class TagsPlugin extends ZeppelinPlugin { return diff >= 0 ? result : `${result} ago`; }, + today() { + return moment(); + }, + + timeXAgo(timeDiff) { + if (typeof timeDiff !== "string") + return 'Please pass a valid delay as a string to timeXAgo (e.g. timeXAgo("1w"))'; + + const delay = convertDelayStringToMS(timeDiff); + return moment(moment().valueOf() - delay); + }, + + humanizeTime(timems) { + if (typeof timems !== "number") return moment().format("DD-MM-YYYY HH:mm"); + + return moment(timems).format("DD-MM-YYYY HH:mm"); + }, + + discordDateFormat(timems) { + if (typeof timems !== "number") return moment().format("YYYY-MM-DD"); + + return moment(timems).format("YYYY-MM-DD"); + }, + mention: input => { if (typeof input !== "string") return ""; if (input.match(/^<(@#)(!&)\d+>$/)) {