3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 21:35:02 +00:00

Add user id and show recent cases in 'member joined with prior records' log entry

This commit is contained in:
Dragory 2019-01-15 04:15:22 +02:00
parent 95cded4d2b
commit f6f1c29fc1
4 changed files with 52 additions and 26 deletions

View file

@ -134,12 +134,29 @@ export class LogsPlugin extends Plugin {
account_age: accountAge
});
const cases = (await this.cases.getByUserId(member.id)).filter(c => !c.is_hidden);
const cases = (await this.cases.with("notes").getByUserId(member.id)).filter(c => !c.is_hidden);
cases.sort((a, b) => (a.created_at > b.created_at ? -1 : 1));
if (cases.length) {
const recentCaseLines = [];
const recentCases = cases.slice(0, 2);
for (const theCase of recentCases) {
recentCaseLines.push(this.cases.getSummaryText(theCase));
}
let recentCaseSummary = recentCaseLines.join("\n");
if (recentCases.length < cases.length) {
const remaining = cases.length - recentCases.length;
if (remaining === 1) {
recentCaseSummary += `\n*+${remaining} case*`;
} else {
recentCaseSummary += `\n*+${remaining} cases*`;
}
}
this.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
member: stripObjectToScalars(member, ["user"]),
caseCount: cases.length
recentCaseSummary
});
}
}

View file

@ -922,29 +922,8 @@ export class ModActionsPlugin extends ZeppelinPlugin {
const lines = [];
for (const theCase of casesToDisplay) {
theCase.notes.sort((a, b) => (a.created_at > b.created_at ? 1 : -1));
const firstNote = theCase.notes[0];
let reason = firstNote ? firstNote.body : "";
if (reason.length > CASE_LIST_REASON_MAX_LENGTH) {
const match = reason.slice(CASE_LIST_REASON_MAX_LENGTH, 100).match(/(?:[.,!?\s]|$)/);
const nextWhitespaceIndex = match ? CASE_LIST_REASON_MAX_LENGTH + match.index : CASE_LIST_REASON_MAX_LENGTH;
if (nextWhitespaceIndex < reason.length) {
reason = reason.slice(0, nextWhitespaceIndex - 1) + "...";
}
}
reason = disableLinkPreviews(reason);
let line = `Case \`#${theCase.case_number}\` __${CaseTypes[theCase.type]}__ ${reason}`;
if (theCase.notes.length > 1) {
line += ` *(+${theCase.notes.length - 1} ${theCase.notes.length === 2 ? "note" : "notes"})*`;
}
if (theCase.is_hidden) {
line += " *(hidden)*";
}
lines.push(line);
const caseSummary = this.cases.getSummaryText(theCase);
lines.push(caseSummary);
}
if (!showHidden && hiddenCases.length) {