2020-07-23 00:37:33 +03:00
|
|
|
import { PluginData } from "knub";
|
2020-08-05 02:25:13 +03:00
|
|
|
import { LogsPlugin } from "../plugins/Logs/LogsPlugin";
|
|
|
|
import { findRelevantAuditLogEntry, isDiscordRESTError } from "../utils";
|
|
|
|
import { LogType } from "../data/LogType";
|
2020-07-23 00:37:33 +03:00
|
|
|
|
|
|
|
/**
|
2020-08-05 02:25:13 +03:00
|
|
|
* Wrapper for findRelevantAuditLogEntry() that handles permission errors gracefully.
|
|
|
|
* Calling plugin must have LogsPlugin as a dependency (or be LogsPlugin itself).
|
2020-07-23 00:37:33 +03:00
|
|
|
*/
|
|
|
|
export async function safeFindRelevantAuditLogEntry(
|
2020-08-05 02:25:13 +03:00
|
|
|
pluginData: PluginData<any>,
|
2020-07-23 00:37:33 +03:00
|
|
|
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) {
|
2020-08-05 02:25:13 +03:00
|
|
|
const logs = pluginData.getPlugin(LogsPlugin);
|
|
|
|
logs.log(LogType.BOT_ALERT, {
|
2020-07-23 00:37:33 +03:00
|
|
|
body: "Missing permissions to read audit log",
|
|
|
|
});
|
2020-08-05 02:25:13 +03:00
|
|
|
return;
|
2020-07-23 00:37:33 +03:00
|
|
|
}
|
2020-08-05 02:25:13 +03:00
|
|
|
|
|
|
|
throw e;
|
2020-07-23 00:37:33 +03:00
|
|
|
}
|
|
|
|
}
|