2020-07-23 00:37:33 +03:00
|
|
|
import { eventListener } from "knub";
|
|
|
|
import { IgnoredEventType, ModActionsPluginType } from "../types";
|
|
|
|
import { isEventIgnored } from "../functions/isEventIgnored";
|
2020-07-24 02:25:33 +02:00
|
|
|
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
|
2020-07-23 00:37:33 +03:00
|
|
|
import { Constants as ErisConstants } from "eris";
|
|
|
|
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
|
|
|
import { CaseTypes } from "../../../data/CaseTypes";
|
2020-08-05 02:25:13 +03:00
|
|
|
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
|
2020-08-02 02:30:01 +02:00
|
|
|
import { LogType } from "src/data/LogType";
|
|
|
|
import { stripObjectToScalars, resolveUser } from "src/utils";
|
2020-07-23 00:37:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a BAN case automatically when a user is banned manually.
|
|
|
|
* Attempts to find the ban's details in the audit log.
|
|
|
|
*/
|
|
|
|
export const CreateBanCaseOnManualBanEvt = eventListener<ModActionsPluginType>()(
|
|
|
|
"guildBanAdd",
|
|
|
|
async ({ pluginData, args: { guild, user } }) => {
|
|
|
|
if (isEventIgnored(pluginData, IgnoredEventType.Ban, user.id)) {
|
2020-07-24 02:25:33 +02:00
|
|
|
clearIgnoredEvents(pluginData, IgnoredEventType.Ban, user.id);
|
2020-07-23 00:37:33 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
|
|
|
|
pluginData,
|
|
|
|
ErisConstants.AuditLogActions.MEMBER_BAN_ADD,
|
|
|
|
user.id,
|
|
|
|
);
|
|
|
|
|
|
|
|
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
2020-08-02 02:30:01 +02:00
|
|
|
|
|
|
|
let createdCase;
|
|
|
|
let mod = null;
|
|
|
|
let reason = "";
|
|
|
|
|
2020-07-23 00:37:33 +03:00
|
|
|
if (relevantAuditLogEntry) {
|
|
|
|
const modId = relevantAuditLogEntry.user.id;
|
|
|
|
const auditLogId = relevantAuditLogEntry.id;
|
|
|
|
|
2020-08-02 02:30:01 +02:00
|
|
|
mod = resolveUser(pluginData.client, modId);
|
|
|
|
reason = relevantAuditLogEntry.reason;
|
|
|
|
createdCase = await casesPlugin.createCase({
|
2020-07-23 00:37:33 +03:00
|
|
|
userId: user.id,
|
|
|
|
modId,
|
|
|
|
type: CaseTypes.Ban,
|
|
|
|
auditLogId,
|
2020-08-02 02:30:01 +02:00
|
|
|
reason,
|
2020-07-23 00:37:33 +03:00
|
|
|
automatic: true,
|
|
|
|
});
|
|
|
|
} else {
|
2020-08-02 02:30:01 +02:00
|
|
|
createdCase = await casesPlugin.createCase({
|
2020-07-23 00:37:33 +03:00
|
|
|
userId: user.id,
|
|
|
|
modId: null,
|
|
|
|
type: CaseTypes.Ban,
|
|
|
|
});
|
|
|
|
}
|
2020-08-02 02:30:01 +02:00
|
|
|
|
|
|
|
mod = await mod;
|
|
|
|
pluginData.state.serverLogs.log(LogType.MEMBER_BAN, {
|
|
|
|
mod: mod ? stripObjectToScalars(mod, ["user"]) : null,
|
|
|
|
user: stripObjectToScalars(user, ["user"]),
|
|
|
|
caseNumber: createdCase.case_number,
|
|
|
|
reason,
|
|
|
|
});
|
2020-07-23 00:37:33 +03:00
|
|
|
},
|
|
|
|
);
|