mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
WIP ModActions
This commit is contained in:
parent
a3d0ec03d9
commit
ebcb28261b
25 changed files with 1162 additions and 6 deletions
|
@ -0,0 +1,49 @@
|
|||
import { eventListener } from "knub";
|
||||
import { IgnoredEventType, ModActionsPluginType } from "../types";
|
||||
import { isEventIgnored } from "../functions/isEventIgnored";
|
||||
import { clearIgnoredEvent } from "../functions/clearIgnoredEvents";
|
||||
import { Constants as ErisConstants } from "eris";
|
||||
import { safeFindRelevantAuditLogEntry } from "../functions/safeFindRelevantAuditLogEntry";
|
||||
import { CasesPlugin } from "../../Cases/CasesPlugin";
|
||||
import { CaseTypes } from "../../../data/CaseTypes";
|
||||
|
||||
/**
|
||||
* 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)) {
|
||||
clearIgnoredEvent(pluginData, IgnoredEventType.Ban, user.id);
|
||||
return;
|
||||
}
|
||||
|
||||
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
|
||||
pluginData,
|
||||
ErisConstants.AuditLogActions.MEMBER_BAN_ADD,
|
||||
user.id,
|
||||
);
|
||||
|
||||
const casesPlugin = pluginData.getPlugin(CasesPlugin);
|
||||
if (relevantAuditLogEntry) {
|
||||
const modId = relevantAuditLogEntry.user.id;
|
||||
const auditLogId = relevantAuditLogEntry.id;
|
||||
|
||||
casesPlugin.createCase({
|
||||
userId: user.id,
|
||||
modId,
|
||||
type: CaseTypes.Ban,
|
||||
auditLogId,
|
||||
reason: relevantAuditLogEntry.reason,
|
||||
automatic: true,
|
||||
});
|
||||
} else {
|
||||
casesPlugin.createCase({
|
||||
userId: user.id,
|
||||
modId: null,
|
||||
type: CaseTypes.Ban,
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue