mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Improve audit log error handling, show BOT_ALERT in more cases
This commit is contained in:
parent
ffc25791ca
commit
5ea0f7eb46
7 changed files with 30 additions and 24 deletions
30
backend/src/utils/safeFindRelevantAuditLogEntry.ts
Normal file
30
backend/src/utils/safeFindRelevantAuditLogEntry.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { PluginData } from "knub";
|
||||
import { LogsPlugin } from "../plugins/Logs/LogsPlugin";
|
||||
import { findRelevantAuditLogEntry, isDiscordRESTError } from "../utils";
|
||||
import { LogType } from "../data/LogType";
|
||||
|
||||
/**
|
||||
* Wrapper for findRelevantAuditLogEntry() that handles permission errors gracefully.
|
||||
* Calling plugin must have LogsPlugin as a dependency (or be LogsPlugin itself).
|
||||
*/
|
||||
export async function safeFindRelevantAuditLogEntry(
|
||||
pluginData: PluginData<any>,
|
||||
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) {
|
||||
const logs = pluginData.getPlugin(LogsPlugin);
|
||||
logs.log(LogType.BOT_ALERT, {
|
||||
body: "Missing permissions to read audit log",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
throw e;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue