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

@ -45,5 +45,5 @@
"MASSBAN": "⚒ **{mod.username}#{mod.discriminator}** massbanned {count} users",
"MEMBER_JOIN_WITH_PRIOR_RECORDS": "⚠ **{member.user.username}#{member.user.discriminator}** joined with prior records ({caseCount} case(s))"
"MEMBER_JOIN_WITH_PRIOR_RECORDS": "⚠ **{member.user.username}#{member.user.discriminator}** (`{member.id}`) joined with prior records. Recent cases:\n{recentCaseSummary}"
}

View file

@ -2,6 +2,10 @@ import { Case } from "./entities/Case";
import { CaseNote } from "./entities/CaseNote";
import { BaseRepository } from "./BaseRepository";
import { getRepository, In, Repository } from "typeorm";
import { disableLinkPreviews } from "../utils";
import { CaseTypes } from "./CaseTypes";
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
export class GuildCases extends BaseRepository {
private cases: Repository<Case>;
@ -82,4 +86,30 @@ export class GuildCases extends BaseRepository {
case_id: caseId
});
}
getSummaryText(theCase: Case) {
const firstNote = theCase.notes[0];
let reason = firstNote ? firstNote.body : "";
if (reason.length > CASE_SUMMARY_REASON_MAX_LENGTH) {
const match = reason.slice(CASE_SUMMARY_REASON_MAX_LENGTH, 100).match(/(?:[.,!?\s]|$)/);
const nextWhitespaceIndex = match ? CASE_SUMMARY_REASON_MAX_LENGTH + match.index : CASE_SUMMARY_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)*";
}
return line;
}
}