mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-25 18:25:03 +00:00
Add case icons. Clean up !cases. Allow customizing case colors and icons.
This commit is contained in:
parent
ad24d166ce
commit
131a79ffd4
24 changed files with 138 additions and 22 deletions
|
@ -1,17 +1,19 @@
|
|||
import { PluginData } from "knub";
|
||||
import { CasesPluginType } from "../types";
|
||||
import { convertDelayStringToMS, DAYS, disableLinkPreviews, messageLink } from "../../../utils";
|
||||
import { convertDelayStringToMS, DAYS, disableLinkPreviews, emptyEmbedValue, messageLink } from "../../../utils";
|
||||
import { DBDateFormat, getDateFormat } from "../../../utils/dateFormats";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
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";
|
||||
|
||||
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
|
||||
const INCLUDE_MORE_NOTES_THRESHOLD = 20;
|
||||
const UPDATED_STR = "__[Update]__";
|
||||
const UPDATE_STR = "**[Update]**";
|
||||
|
||||
const RELATIVE_TIME_THRESHOLD = 7 * DAYS;
|
||||
|
||||
|
@ -20,8 +22,9 @@ export async function getCaseSummary(
|
|||
caseOrCaseId: Case | number,
|
||||
withLinks = false,
|
||||
) {
|
||||
const caseId = caseOrCaseId instanceof Case ? caseOrCaseId.id : caseOrCaseId;
|
||||
const config = pluginData.config.get();
|
||||
|
||||
const caseId = caseOrCaseId instanceof Case ? caseOrCaseId.id : caseOrCaseId;
|
||||
const theCase = await pluginData.state.cases.with("notes").find(caseId);
|
||||
|
||||
const firstNote = theCase.notes[0];
|
||||
|
@ -29,8 +32,8 @@ export async function getCaseSummary(
|
|||
let leftoverNotes = Math.max(0, theCase.notes.length - 1);
|
||||
|
||||
for (let i = 1; i < theCase.notes.length; i++) {
|
||||
if (reason.length >= CASE_SUMMARY_REASON_MAX_LENGTH - UPDATED_STR.length - INCLUDE_MORE_NOTES_THRESHOLD) break;
|
||||
reason += ` ${UPDATED_STR} ${theCase.notes[i].body}`;
|
||||
if (reason.length >= CASE_SUMMARY_REASON_MAX_LENGTH - UPDATE_STR.length - INCLUDE_MORE_NOTES_THRESHOLD) break;
|
||||
reason += ` ${UPDATE_STR} ${theCase.notes[i].body}`;
|
||||
leftoverNotes--;
|
||||
}
|
||||
|
||||
|
@ -45,23 +48,26 @@ export async function getCaseSummary(
|
|||
reason = disableLinkPreviews(reason);
|
||||
|
||||
const timestamp = moment.utc(theCase.created_at, DBDateFormat);
|
||||
const config = pluginData.config.get();
|
||||
const relativeTimeCutoff = convertDelayStringToMS(config.relative_time_cutoff);
|
||||
const useRelativeTime = config.show_relative_times && Date.now() - timestamp.valueOf() < relativeTimeCutoff;
|
||||
const prettyTimestamp = useRelativeTime
|
||||
? moment.utc().to(timestamp)
|
||||
: inGuildTz(pluginData, timestamp).format(getDateFormat(pluginData, "date"));
|
||||
|
||||
let caseTitle = `\`Case #${theCase.case_number}\``;
|
||||
const icon = getCaseIcon(pluginData, theCase.type);
|
||||
|
||||
let caseTitle = `\`#${theCase.case_number}\``;
|
||||
if (withLinks && theCase.log_message_id) {
|
||||
const [channelId, messageId] = theCase.log_message_id.split("-");
|
||||
caseTitle = `[${caseTitle}](${messageLink(pluginData.guild.id, channelId, messageId)})`;
|
||||
} else {
|
||||
caseTitle = `\`${caseTitle}\``;
|
||||
}
|
||||
const caseType = `__${CaseTypes[theCase.type]}__`;
|
||||
|
||||
let line = `\`[${prettyTimestamp}]\` ${caseTitle} ${caseType} ${reason}`;
|
||||
let caseType = (caseAbbreviations[theCase.type] || String(theCase.type)).toUpperCase();
|
||||
caseType = (caseType + " ").slice(0, 4);
|
||||
|
||||
let line = `${icon} **\`${caseType}\`** \`[${prettyTimestamp}]\` ${caseTitle} ${reason}`;
|
||||
if (leftoverNotes > 1) {
|
||||
line += ` *(+${leftoverNotes} ${leftoverNotes === 1 ? "note" : "notes"})*`;
|
||||
}
|
||||
|
@ -70,5 +76,5 @@ export async function getCaseSummary(
|
|||
line += " *(hidden)*";
|
||||
}
|
||||
|
||||
return line;
|
||||
return line.trim();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue