3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-19 15:30:00 +00:00
zeppelin/backend/src/plugins/ModActions/functions/safeFindRelevantAuditLogEntry.ts

28 lines
845 B
TypeScript
Raw Normal View History

2020-07-23 00:37:33 +03:00
import { findRelevantAuditLogEntry, isDiscordRESTError } from "../../../utils";
import { PluginData } from "knub";
import { ModActionsPluginType } from "../types";
import { LogType } from "../../../data/LogType";
/**
* Wrapper for findRelevantAuditLogEntry() that handles permission errors gracefully
*/
export async function safeFindRelevantAuditLogEntry(
pluginData: PluginData<ModActionsPluginType>,
actionType: number,
userId: string,
attempts?: number,
attemptDelay?: number,
) {
try {
return await findRelevantAuditLogEntry(pluginData.guild, actionType, userId, attempts, attemptDelay);
} catch (e) {
if (isDiscordRESTError(e) && e.code === 50013) {
pluginData.state.serverLogs.log(LogType.BOT_ALERT, {
body: "Missing permissions to read audit log",
});
} else {
throw e;
}
}
}