3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

refactor: debounce and batch simultaneous audit log requests

This commit is contained in:
Dragory 2021-10-27 00:09:29 +03:00
parent d7c6e34695
commit 8f17a835f9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
8 changed files with 77 additions and 117 deletions

View file

@ -1,11 +1,11 @@
import { GuildAuditLogs } from "discord.js";
import { LogType } from "../../../data/LogType";
import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
import { logMemberBan } from "../logFunctions/logMemberBan";
import { isLogIgnored } from "../util/isLogIgnored";
import { logMemberUnban } from "../logFunctions/logMemberUnban";
import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry";
export const LogsGuildBanAddEvt = logsEvt({
event: "guildBanAdd",
@ -18,11 +18,7 @@ export const LogsGuildBanAddEvt = logsEvt({
return;
}
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
pluginData,
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
user.id,
);
const relevantAuditLogEntry = await findMatchingAuditLogEntry(pluginData.guild, "MEMBER_BAN_ADD", user.id);
const mod = relevantAuditLogEntry?.executor ?? null;
logMemberBan(meta.pluginData, {
mod,
@ -44,11 +40,7 @@ export const LogsGuildBanRemoveEvt = logsEvt({
return;
}
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
pluginData,
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
user.id,
);
const relevantAuditLogEntry = await findMatchingAuditLogEntry(pluginData.guild, "MEMBER_BAN_REMOVE", user.id);
const mod = relevantAuditLogEntry?.executor ?? null;
logMemberUnban(pluginData, {

View file

@ -3,7 +3,6 @@ import diff from "lodash.difference";
import isEqual from "lodash.isequal";
import { memberToTemplateSafeMember, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
import { LogType } from "../../../data/LogType";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { logsEvt } from "../types";
import { logMemberNickChange } from "../logFunctions/logMemberNickChange";
import { logMemberRoleChanges } from "../logFunctions/logMemberRoleChanges";

View file

@ -4,12 +4,12 @@ import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { resolveUser, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { isEventIgnored } from "../functions/isEventIgnored";
import { IgnoredEventType, modActionsEvt } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry";
/**
* Create a BAN case automatically when a user is banned manually.
@ -24,11 +24,7 @@ export const CreateBanCaseOnManualBanEvt = modActionsEvt({
return;
}
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
pluginData,
GuildAuditLogs.Actions.MEMBER_BAN_ADD as number,
user.id,
);
const relevantAuditLogEntry = await findMatchingAuditLogEntry(pluginData.guild, "MEMBER_BAN_ADD", user.id);
const casesPlugin = pluginData.getPlugin(CasesPlugin);

View file

@ -5,12 +5,12 @@ import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { resolveUser, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { isEventIgnored } from "../functions/isEventIgnored";
import { IgnoredEventType, modActionsEvt } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry";
/**
* Create a KICK case automatically when a user is kicked manually.
@ -24,11 +24,7 @@ export const CreateKickCaseOnManualKickEvt = modActionsEvt({
return;
}
const kickAuditLogEntry = await safeFindRelevantAuditLogEntry(
pluginData,
GuildAuditLogs.Actions.MEMBER_KICK as number,
member.id,
);
const kickAuditLogEntry = await findMatchingAuditLogEntry(pluginData.guild, "MEMBER_KICK", member.id);
let mod: User | UnknownUser | null = null;
let createdCase: Case | null = null;

View file

@ -4,12 +4,12 @@ import { CaseTypes } from "../../../data/CaseTypes";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { resolveUser, UnknownUser } from "../../../utils";
import { safeFindRelevantAuditLogEntry } from "../../../utils/safeFindRelevantAuditLogEntry";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { clearIgnoredEvents } from "../functions/clearIgnoredEvents";
import { isEventIgnored } from "../functions/isEventIgnored";
import { IgnoredEventType, modActionsEvt } from "../types";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { findMatchingAuditLogEntry } from "../../../utils/findMatchingAuditLogEntry";
/**
* Create an UNBAN case automatically when a user is unbanned manually.
@ -24,11 +24,7 @@ export const CreateUnbanCaseOnManualUnbanEvt = modActionsEvt({
return;
}
const relevantAuditLogEntry = await safeFindRelevantAuditLogEntry(
pluginData,
GuildAuditLogs.Actions.MEMBER_BAN_REMOVE as number,
user.id,
);
const relevantAuditLogEntry = await findMatchingAuditLogEntry(pluginData.guild, "MEMBER_BAN_REMOVE", user.id);
const casesPlugin = pluginData.getPlugin(CasesPlugin);