2020-07-27 01:53:14 +02:00
|
|
|
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";
|
2020-08-10 03:18:34 +03:00
|
|
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
2020-07-27 01:53:14 +02:00
|
|
|
|
|
|
|
export const LogsGuildMemberAddEvt = logsEvent({
|
|
|
|
event: "guildMemberAdd",
|
|
|
|
|
|
|
|
async listener(meta) {
|
|
|
|
const pluginData = meta.pluginData;
|
|
|
|
const member = meta.args.member;
|
|
|
|
|
2020-08-10 00:24:06 +03:00
|
|
|
const newThreshold = moment.utc().valueOf() - 1000 * 60 * 60;
|
|
|
|
const accountAge = humanizeDuration(moment.utc().valueOf() - member.createdAt, {
|
2020-07-27 01:53:14 +02:00
|
|
|
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);
|
2020-08-10 03:18:34 +03:00
|
|
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
2020-07-27 01:53:14 +02:00
|
|
|
for (const theCase of recentCases) {
|
2020-08-10 03:18:34 +03:00
|
|
|
recentCaseLines.push(await casesPlugin.getCaseSummary(theCase, true));
|
2020-07-27 01:53:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|