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

Change DiscordRESTError to DiscordAPIError

This commit is contained in:
Dark 2021-06-30 23:06:02 +02:00
parent be71357ff9
commit 1ad70ffe1a
No known key found for this signature in database
GPG key ID: 384C4B4F5B1E25A8
18 changed files with 50 additions and 50 deletions

View file

@ -1,6 +1,6 @@
import { GuildChannel, Permissions } from "discord.js";
import { LogType } from "../../../data/LogType";
import { isDiscordRESTError } from "../../../utils";
import { isDiscordAPIError } from "../../../utils";
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
import { missingPermissionError } from "../../../utils/missingPermissionError";
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
@ -36,7 +36,7 @@ export const AddReactionsEvt = autoReactionsEvt({
try {
await message.react(reaction);
} catch (e) {
if (isDiscordRESTError(e)) {
if (isDiscordAPIError(e)) {
const logs = pluginData.getPlugin(LogsPlugin);
if (e.code === 10008) {
logs.log(LogType.BOT_ALERT, {

View file

@ -2,7 +2,7 @@ import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { ChannelTypeStrings } from "src/types";
import { LogType } from "../../../data/LogType";
import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils";
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
import { automodAction } from "../helpers";
export const SetSlowmodeAction = automodAction({
@ -49,7 +49,7 @@ export const SetSlowmodeAction = automodAction({
} catch (e) {
// Check for invalid form body -> indicates duration was too large
const errorMessage =
isDiscordRESTError(e) && e.code === 50035
isDiscordAPIError(e) && e.code === 50035
? `Duration is greater than maximum native slowmode duration`
: e.message;

View file

@ -2,7 +2,7 @@ import { FileOptions, Message, MessageOptions, Snowflake, TextChannel } from "di
import { GuildPluginData } from "knub";
import { Case } from "../../../data/entities/Case";
import { LogType } from "../../../data/LogType";
import { isDiscordRESTError } from "../../../utils";
import { isDiscordAPIError } from "../../../utils";
import { CasesPluginType } from "../types";
import { getCaseEmbed } from "./getCaseEmbed";
import { resolveCaseId } from "./resolveCaseId";
@ -25,7 +25,7 @@ export async function postToCaseLogChannel(
}
result = await caseLogChannel.send({ ...content });
} catch (e) {
if (isDiscordRESTError(e) && (e.code === 50013 || e.code === 50001)) {
if (isDiscordAPIError(e) && (e.code === 50013 || e.code === 50001)) {
pluginData.state.logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to post mod cases in <#${caseLogChannel.id}>`,
});

View file

@ -1,7 +1,7 @@
import { Permissions, Snowflake, StageChannel, TextChannel, VoiceChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { isDiscordRESTError, MINUTES } from "../../../utils";
import { isDiscordAPIError, MINUTES } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
@ -66,7 +66,7 @@ export async function handleCompanionPermissions(
});
}
} catch (e) {
if (isDiscordRESTError(e) && e.code === 50001) {
if (isDiscordAPIError(e) && e.code === 50001) {
const logs = pluginData.getPlugin(LogsPlugin);
logs.log(LogType.BOT_ALERT, {
body: `Missing permissions to handle companion channels. Pausing companion channels for 5 minutes or until the bot is reloaded on this server.`,

View file

@ -4,7 +4,7 @@ import { GuildPluginData } from "knub";
import { logger } from "../../../logger";
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
import { asSingleLine, isDiscordRESTError, UnknownUser } from "../../../utils";
import { asSingleLine, isDiscordAPIError, UnknownUser } from "../../../utils";
import { MutesPlugin } from "../../Mutes/MutesPlugin";
import { MuteResult } from "../../Mutes/types";
import { ModActionsPluginType } from "../types";
@ -60,7 +60,7 @@ export async function actualMuteUserCmd(
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: no mute role set in config");
} else if (isDiscordRESTError(e) && e.code === 10007) {
} else if (isDiscordAPIError(e) && e.code === 10007) {
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: unknown member");
} else {
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);

View file

@ -1,7 +1,7 @@
import { Permissions, Snowflake } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { isDiscordHTTPError, isDiscordRESTError, SECONDS, sleep } from "../../../utils";
import { isDiscordHTTPError, isDiscordAPIError, SECONDS, sleep } from "../../../utils";
import { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ModActionsPluginType } from "../types";
@ -26,7 +26,7 @@ export async function isBanned(
]);
return potentialBan != null;
} catch (e) {
if (isDiscordRESTError(e) && e.code === 10026) {
if (isDiscordAPIError(e) && e.code === 10026) {
// [10026]: Unknown Ban
return false;
}
@ -36,7 +36,7 @@ export async function isBanned(
return false;
}
if (isDiscordRESTError(e) && e.code === 50013) {
if (isDiscordAPIError(e) && e.code === 50013) {
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
body: `Missing "Ban Members" permission to check for existing bans`,
});

View file

@ -1,7 +1,7 @@
import { Message, Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isDiscordRESTError } from "../../../utils";
import { isDiscordAPIError } from "../../../utils";
import { reactionRolesCmd } from "../types";
export const ClearReactionRolesCmd = reactionRolesCmd({
@ -25,7 +25,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
try {
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake);
} catch (err) {
if (isDiscordRESTError(err) && err.code === 50001) {
if (isDiscordAPIError(err) && err.code === 50001) {
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
return;
}

View file

@ -1,7 +1,7 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { canUseEmoji, isDiscordRESTError, isValidEmoji, noop, trimPluginDescription } from "../../../utils";
import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescription } from "../../../utils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { reactionRolesCmd, TReactionRolePair } from "../types";
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
@ -42,7 +42,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
try {
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake).catch(noop);
} catch (e) {
if (isDiscordRESTError(e)) {
if (isDiscordAPIError(e)) {
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);
return;
}

View file

@ -2,7 +2,7 @@ import { Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { ReactionRole } from "../../../data/entities/ReactionRole";
import { LogType } from "../../../data/LogType";
import { isDiscordRESTError, sleep } from "../../../utils";
import { isDiscordAPIError, sleep } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ReactionRolesPluginType } from "../types";
@ -27,7 +27,7 @@ export async function applyReactionRoleReactionsToMessage(
try {
targetMessage = await channel.messages.fetch(messageId as Snowflake);
} catch (e) {
if (isDiscordRESTError(e)) {
if (isDiscordAPIError(e)) {
if (e.code === 10008) {
// Unknown message, remove reaction roles from the message
logs.log(LogType.BOT_ALERT, {
@ -51,7 +51,7 @@ export async function applyReactionRoleReactionsToMessage(
try {
await targetMessage.reactions.removeAll();
} catch (e) {
if (isDiscordRESTError(e)) {
if (isDiscordAPIError(e)) {
errors.push(`Error ${e.code} while removing old reactions: ${e.message}`);
logs.log(LogType.BOT_ALERT, {
body: `Error ${e.code} while removing old reaction role reactions from message ${channelId}/${messageId}: ${e.message}`,
@ -73,7 +73,7 @@ export async function applyReactionRoleReactionsToMessage(
await targetMessage.react(rawEmoji);
await sleep(750); // Make sure we don't hit rate limits
} catch (e) {
if (isDiscordRESTError(e)) {
if (isDiscordAPIError(e)) {
if (e.code === 10014) {
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
errors.push(`Unknown emoji: ${rawEmoji}`);

View file

@ -2,7 +2,7 @@ import { GuildChannel, Permissions, Snowflake, TextChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { LogType } from "../../../data/LogType";
import { logger } from "../../../logger";
import { isDiscordRESTError, stripObjectToScalars, UnknownUser } from "../../../utils";
import { isDiscordAPIError, stripObjectToScalars, UnknownUser } from "../../../utils";
import { SlowmodePluginType } from "../types";
export async function applyBotSlowmodeToUserId(
@ -24,7 +24,7 @@ export async function applyBotSlowmodeToUserId(
} catch (e) {
const user = pluginData.client.users.fetch(userId as Snowflake) || new UnknownUser({ id: userId });
if (isDiscordRESTError(e) && e.code === 50013) {
if (isDiscordAPIError(e) && e.code === 50013) {
logger.warn(
`Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${channel.id}) on server ${pluginData.guild.name} (${pluginData.guild.id})`,
);