Migrate Logs to new Plugin structure, also dont ignore it
This commit is contained in:
parent
140ba84544
commit
aea019181c
16 changed files with 764 additions and 1 deletions
52
backend/src/plugins/Logs/events/LogsGuildMemberAddEvt.ts
Normal file
52
backend/src/plugins/Logs/events/LogsGuildMemberAddEvt.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { logsEvent } from "../types";
|
||||
import { stripObjectToScalars } from "src/utils";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
|
||||
export const LogsGuildMemberAddEvt = logsEvent({
|
||||
event: "guildMemberAdd",
|
||||
|
||||
async listener(meta) {
|
||||
const pluginData = meta.pluginData;
|
||||
const member = meta.args.member;
|
||||
|
||||
const newThreshold = moment().valueOf() - 1000 * 60 * 60;
|
||||
const accountAge = humanizeDuration(moment().valueOf() - member.createdAt, {
|
||||
largest: 2,
|
||||
round: true,
|
||||
});
|
||||
|
||||
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
new: member.createdAt >= newThreshold ? " :new:" : "",
|
||||
account_age: accountAge,
|
||||
});
|
||||
|
||||
const cases = (await pluginData.state.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(pluginData.state.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*`;
|
||||
}
|
||||
}
|
||||
|
||||
pluginData.state.guildLogs.log(LogType.MEMBER_JOIN_WITH_PRIOR_RECORDS, {
|
||||
member: stripObjectToScalars(member, ["user", "roles"]),
|
||||
recentCaseSummary,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue