2020-10-01 01:43:38 +03:00
|
|
|
import { GuildPluginData } from "knub";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { LogType } from "../data/LogType";
|
2020-08-05 02:25:13 +03:00
|
|
|
import { LogsPlugin } from "../plugins/Logs/LogsPlugin";
|
|
|
|
import { findRelevantAuditLogEntry, isDiscordRESTError } from "../utils";
|
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-10-01 01:43:38 +03:00
|
|
|
pluginData: GuildPluginData<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
|
|
|
}
|
|
|
|
}
|