3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-25 18:25:03 +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

@ -1,15 +1,21 @@
import { PluginData } from "knub";
import { CasesPluginType } from "../types";
import { convertDelayStringToMS, DAYS, disableLinkPreviews, emptyEmbedValue, messageLink } from "../../../utils";
import { DBDateFormat, getDateFormat } from "../../../utils/dateFormats";
import {
convertDelayStringToMS,
DAYS,
DBDateFormat,
disableLinkPreviews,
emptyEmbedValue,
messageLink,
} from "../../../utils";
import { CaseTypes, CaseTypeToName } from "../../../data/CaseTypes";
import moment from "moment-timezone";
import { Case } from "../../../data/entities/Case";
import { inGuildTz } from "../../../utils/timezones";
import humanizeDuration from "humanize-duration";
import { humanizeDurationShort } from "../../../humanizeDurationShort";
import { caseAbbreviations } from "../caseAbbreviations";
import { getCaseIcon } from "./getCaseIcon";
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
const INCLUDE_MORE_NOTES_THRESHOLD = 20;
@ -21,8 +27,10 @@ export async function getCaseSummary(
pluginData: PluginData<CasesPluginType>,
caseOrCaseId: Case | number,
withLinks = false,
requestMemberId?: string,
) {
const config = pluginData.config.get();
const timeAndDate = pluginData.getPlugin(TimeAndDatePlugin);
const caseId = caseOrCaseId instanceof Case ? caseOrCaseId.id : caseOrCaseId;
const theCase = await pluginData.state.cases.with("notes").find(caseId);
@ -50,9 +58,12 @@ export async function getCaseSummary(
const timestamp = moment.utc(theCase.created_at, DBDateFormat);
const relativeTimeCutoff = convertDelayStringToMS(config.relative_time_cutoff);
const useRelativeTime = config.show_relative_times && Date.now() - timestamp.valueOf() < relativeTimeCutoff;
const timestampWithTz = requestMemberId
? await timeAndDate.inMemberTz(requestMemberId, timestamp)
: timeAndDate.inGuildTz(timestamp);
const prettyTimestamp = useRelativeTime
? moment.utc().to(timestamp)
: inGuildTz(pluginData, timestamp).format(getDateFormat(pluginData, "date"));
: timestampWithTz.format(timeAndDate.getDateFormat("date"));
const icon = getCaseIcon(pluginData, theCase.type);