mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-15 05:41:51 +00:00
Change DiscordRESTError to DiscordAPIError
This commit is contained in:
parent
be71357ff9
commit
1ad70ffe1a
18 changed files with 50 additions and 50 deletions
18
backend/package-lock.json
generated
18
backend/package-lock.json
generated
|
@ -73,7 +73,7 @@
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"source-map-support": "^0.5.16",
|
"source-map-support": "^0.5.16",
|
||||||
"tsc-watch": "^4.0.0",
|
"tsc-watch": "^4.0.0",
|
||||||
"typescript": "^4.4.0-dev.20210629"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"../../Knub": {
|
"../../Knub": {
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/voice": "^0.5.1",
|
"@discordjs/voice": "^0.5.1",
|
||||||
"discord-api-types": "^0.18.1",
|
"discord-api-types": "^0.18.1",
|
||||||
"discord.js": "^13.0.0-dev.edab5af.1624996138",
|
"discord.js": "^13.0.0-dev.64f093f.1625054868",
|
||||||
"knub-command-manager": "^9.1.0",
|
"knub-command-manager": "^9.1.0",
|
||||||
"ts-essentials": "^6.0.7"
|
"ts-essentials": "^6.0.7"
|
||||||
},
|
},
|
||||||
|
@ -5721,9 +5721,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "4.4.0-dev.20210629",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.0-dev.20210629.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
|
||||||
"integrity": "sha512-kqDceSuAA0qQ6z5mrQc3LcD6IcwrKOZZ2YO7oBgwfGM0zzraUKhpdJSZovwN0pF3MdI211HccvrHf8JX7UJD7A==",
|
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
@ -8880,7 +8880,7 @@
|
||||||
"@typescript-eslint/parser": "^4.23.0",
|
"@typescript-eslint/parser": "^4.23.0",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"discord-api-types": "^0.18.1",
|
"discord-api-types": "^0.18.1",
|
||||||
"discord.js": "^13.0.0-dev.edab5af.1624996138",
|
"discord.js": "^13.0.0-dev.64f093f.1625054868",
|
||||||
"eslint": "^7.2.0",
|
"eslint": "^7.2.0",
|
||||||
"husky": "^4.3.8",
|
"husky": "^4.3.8",
|
||||||
"knub-command-manager": "^9.1.0",
|
"knub-command-manager": "^9.1.0",
|
||||||
|
@ -10844,9 +10844,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "4.4.0-dev.20210629",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.4.0-dev.20210629.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
|
||||||
"integrity": "sha512-kqDceSuAA0qQ6z5mrQc3LcD6IcwrKOZZ2YO7oBgwfGM0zzraUKhpdJSZovwN0pF3MdI211HccvrHf8JX7UJD7A==",
|
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"uid2": {
|
"uid2": {
|
||||||
|
|
|
@ -88,7 +88,7 @@
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"source-map-support": "^0.5.16",
|
"source-map-support": "^0.5.16",
|
||||||
"tsc-watch": "^4.0.0",
|
"tsc-watch": "^4.0.0",
|
||||||
"typescript": "^4.4.0-dev.20210629"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"files": [
|
"files": [
|
||||||
|
|
|
@ -19,7 +19,7 @@ import { RecoverablePluginError } from "./RecoverablePluginError";
|
||||||
import { SimpleError } from "./SimpleError";
|
import { SimpleError } from "./SimpleError";
|
||||||
import { ZeppelinGlobalConfig, ZeppelinGuildConfig } from "./types";
|
import { ZeppelinGlobalConfig, ZeppelinGuildConfig } from "./types";
|
||||||
import { startUptimeCounter } from "./uptime";
|
import { startUptimeCounter } from "./uptime";
|
||||||
import { errorMessage, isDiscordHTTPError, isDiscordRESTError, successMessage } from "./utils";
|
import { errorMessage, isDiscordHTTPError, isDiscordAPIError, successMessage } from "./utils";
|
||||||
|
|
||||||
const fsp = fs.promises;
|
const fsp = fs.promises;
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ function errorHandler(err) {
|
||||||
console.error(`Exiting after ${RECENT_PLUGIN_ERROR_EXIT_THRESHOLD} plugin errors`);
|
console.error(`Exiting after ${RECENT_PLUGIN_ERROR_EXIT_THRESHOLD} plugin errors`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
} else if (isDiscordRESTError(err) || isDiscordHTTPError(err)) {
|
} else if (isDiscordAPIError(err) || isDiscordHTTPError(err)) {
|
||||||
// Discord API errors, usually safe to just log instead of crash
|
// Discord API errors, usually safe to just log instead of crash
|
||||||
// We still bail if we get a ton of them in a short amount of time
|
// We still bail if we get a ton of them in a short amount of time
|
||||||
if (++recentDiscordErrors >= RECENT_DISCORD_ERROR_EXIT_THRESHOLD) {
|
if (++recentDiscordErrors >= RECENT_DISCORD_ERROR_EXIT_THRESHOLD) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { GuildChannel, Permissions } from "discord.js";
|
import { GuildChannel, Permissions } from "discord.js";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { isDiscordRESTError } from "../../../utils";
|
import { isDiscordAPIError } from "../../../utils";
|
||||||
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
|
import { getMissingChannelPermissions } from "../../../utils/getMissingChannelPermissions";
|
||||||
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
import { missingPermissionError } from "../../../utils/missingPermissionError";
|
||||||
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
|
import { readChannelPermissions } from "../../../utils/readChannelPermissions";
|
||||||
|
@ -36,7 +36,7 @@ export const AddReactionsEvt = autoReactionsEvt({
|
||||||
try {
|
try {
|
||||||
await message.react(reaction);
|
await message.react(reaction);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
if (e.code === 10008) {
|
if (e.code === 10008) {
|
||||||
logs.log(LogType.BOT_ALERT, {
|
logs.log(LogType.BOT_ALERT, {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Snowflake, TextChannel } from "discord.js";
|
||||||
import * as t from "io-ts";
|
import * as t from "io-ts";
|
||||||
import { ChannelTypeStrings } from "src/types";
|
import { ChannelTypeStrings } from "src/types";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { convertDelayStringToMS, isDiscordRESTError, tDelayString, tNullable } from "../../../utils";
|
import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils";
|
||||||
import { automodAction } from "../helpers";
|
import { automodAction } from "../helpers";
|
||||||
|
|
||||||
export const SetSlowmodeAction = automodAction({
|
export const SetSlowmodeAction = automodAction({
|
||||||
|
@ -49,7 +49,7 @@ export const SetSlowmodeAction = automodAction({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Check for invalid form body -> indicates duration was too large
|
// Check for invalid form body -> indicates duration was too large
|
||||||
const errorMessage =
|
const errorMessage =
|
||||||
isDiscordRESTError(e) && e.code === 50035
|
isDiscordAPIError(e) && e.code === 50035
|
||||||
? `Duration is greater than maximum native slowmode duration`
|
? `Duration is greater than maximum native slowmode duration`
|
||||||
: e.message;
|
: e.message;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { FileOptions, Message, MessageOptions, Snowflake, TextChannel } from "di
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { Case } from "../../../data/entities/Case";
|
import { Case } from "../../../data/entities/Case";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { isDiscordRESTError } from "../../../utils";
|
import { isDiscordAPIError } from "../../../utils";
|
||||||
import { CasesPluginType } from "../types";
|
import { CasesPluginType } from "../types";
|
||||||
import { getCaseEmbed } from "./getCaseEmbed";
|
import { getCaseEmbed } from "./getCaseEmbed";
|
||||||
import { resolveCaseId } from "./resolveCaseId";
|
import { resolveCaseId } from "./resolveCaseId";
|
||||||
|
@ -25,7 +25,7 @@ export async function postToCaseLogChannel(
|
||||||
}
|
}
|
||||||
result = await caseLogChannel.send({ ...content });
|
result = await caseLogChannel.send({ ...content });
|
||||||
} catch (e) {
|
} 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, {
|
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||||
body: `Missing permissions to post mod cases in <#${caseLogChannel.id}>`,
|
body: `Missing permissions to post mod cases in <#${caseLogChannel.id}>`,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Permissions, Snowflake, StageChannel, TextChannel, VoiceChannel } from "discord.js";
|
import { Permissions, Snowflake, StageChannel, TextChannel, VoiceChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { isDiscordRESTError, MINUTES } from "../../../utils";
|
import { isDiscordAPIError, MINUTES } from "../../../utils";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
import { CompanionChannelsPluginType, TCompanionChannelOpts } from "../types";
|
||||||
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
import { getCompanionChannelOptsForVoiceChannelId } from "./getCompanionChannelOptsForVoiceChannelId";
|
||||||
|
@ -66,7 +66,7 @@ export async function handleCompanionPermissions(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e) && e.code === 50001) {
|
if (isDiscordAPIError(e) && e.code === 50001) {
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
logs.log(LogType.BOT_ALERT, {
|
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.`,
|
body: `Missing permissions to handle companion channels. Pausing companion channels for 5 minutes or until the bot is reloaded on this server.`,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { GuildPluginData } from "knub";
|
||||||
import { logger } from "../../../logger";
|
import { logger } from "../../../logger";
|
||||||
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
import { hasPermission, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||||
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError";
|
||||||
import { asSingleLine, isDiscordRESTError, UnknownUser } from "../../../utils";
|
import { asSingleLine, isDiscordAPIError, UnknownUser } from "../../../utils";
|
||||||
import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
import { MutesPlugin } from "../../Mutes/MutesPlugin";
|
||||||
import { MuteResult } from "../../Mutes/types";
|
import { MuteResult } from "../../Mutes/types";
|
||||||
import { ModActionsPluginType } from "../types";
|
import { ModActionsPluginType } from "../types";
|
||||||
|
@ -60,7 +60,7 @@ export async function actualMuteUserCmd(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
|
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");
|
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");
|
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not mute the user: unknown member");
|
||||||
} else {
|
} else {
|
||||||
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);
|
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Permissions, Snowflake } from "discord.js";
|
import { Permissions, Snowflake } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { LogType } from "../../../data/LogType";
|
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 { hasDiscordPermissions } from "../../../utils/hasDiscordPermissions";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { ModActionsPluginType } from "../types";
|
import { ModActionsPluginType } from "../types";
|
||||||
|
@ -26,7 +26,7 @@ export async function isBanned(
|
||||||
]);
|
]);
|
||||||
return potentialBan != null;
|
return potentialBan != null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e) && e.code === 10026) {
|
if (isDiscordAPIError(e) && e.code === 10026) {
|
||||||
// [10026]: Unknown Ban
|
// [10026]: Unknown Ban
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ export async function isBanned(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDiscordRESTError(e) && e.code === 50013) {
|
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||||
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
|
pluginData.getPlugin(LogsPlugin).log(LogType.BOT_ALERT, {
|
||||||
body: `Missing "Ban Members" permission to check for existing bans`,
|
body: `Missing "Ban Members" permission to check for existing bans`,
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Message, Snowflake } from "discord.js";
|
import { Message, Snowflake } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||||
import { isDiscordRESTError } from "../../../utils";
|
import { isDiscordAPIError } from "../../../utils";
|
||||||
import { reactionRolesCmd } from "../types";
|
import { reactionRolesCmd } from "../types";
|
||||||
|
|
||||||
export const ClearReactionRolesCmd = reactionRolesCmd({
|
export const ClearReactionRolesCmd = reactionRolesCmd({
|
||||||
|
@ -25,7 +25,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
|
||||||
try {
|
try {
|
||||||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake);
|
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (isDiscordRESTError(err) && err.code === 50001) {
|
if (isDiscordAPIError(err) && err.code === 50001) {
|
||||||
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
|
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Snowflake } from "discord.js";
|
import { Snowflake } from "discord.js";
|
||||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
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 { canReadChannel } from "../../../utils/canReadChannel";
|
||||||
import { reactionRolesCmd, TReactionRolePair } from "../types";
|
import { reactionRolesCmd, TReactionRolePair } from "../types";
|
||||||
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
|
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
|
||||||
|
@ -42,7 +42,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
|
||||||
try {
|
try {
|
||||||
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake).catch(noop);
|
targetMessage = await args.message.channel.messages.fetch(args.message.messageId as Snowflake).catch(noop);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);
|
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { ReactionRole } from "../../../data/entities/ReactionRole";
|
import { ReactionRole } from "../../../data/entities/ReactionRole";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { isDiscordRESTError, sleep } from "../../../utils";
|
import { isDiscordAPIError, sleep } from "../../../utils";
|
||||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||||
import { ReactionRolesPluginType } from "../types";
|
import { ReactionRolesPluginType } from "../types";
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ export async function applyReactionRoleReactionsToMessage(
|
||||||
try {
|
try {
|
||||||
targetMessage = await channel.messages.fetch(messageId as Snowflake);
|
targetMessage = await channel.messages.fetch(messageId as Snowflake);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
if (e.code === 10008) {
|
if (e.code === 10008) {
|
||||||
// Unknown message, remove reaction roles from the message
|
// Unknown message, remove reaction roles from the message
|
||||||
logs.log(LogType.BOT_ALERT, {
|
logs.log(LogType.BOT_ALERT, {
|
||||||
|
@ -51,7 +51,7 @@ export async function applyReactionRoleReactionsToMessage(
|
||||||
try {
|
try {
|
||||||
await targetMessage.reactions.removeAll();
|
await targetMessage.reactions.removeAll();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
errors.push(`Error ${e.code} while removing old reactions: ${e.message}`);
|
errors.push(`Error ${e.code} while removing old reactions: ${e.message}`);
|
||||||
logs.log(LogType.BOT_ALERT, {
|
logs.log(LogType.BOT_ALERT, {
|
||||||
body: `Error ${e.code} while removing old reaction role reactions from message ${channelId}/${messageId}: ${e.message}`,
|
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 targetMessage.react(rawEmoji);
|
||||||
await sleep(750); // Make sure we don't hit rate limits
|
await sleep(750); // Make sure we don't hit rate limits
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e)) {
|
if (isDiscordAPIError(e)) {
|
||||||
if (e.code === 10014) {
|
if (e.code === 10014) {
|
||||||
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
|
pluginData.state.reactionRoles.removeFromMessage(messageId, rawEmoji);
|
||||||
errors.push(`Unknown emoji: ${rawEmoji}`);
|
errors.push(`Unknown emoji: ${rawEmoji}`);
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { GuildChannel, Permissions, Snowflake, TextChannel } from "discord.js";
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { LogType } from "../../../data/LogType";
|
import { LogType } from "../../../data/LogType";
|
||||||
import { logger } from "../../../logger";
|
import { logger } from "../../../logger";
|
||||||
import { isDiscordRESTError, stripObjectToScalars, UnknownUser } from "../../../utils";
|
import { isDiscordAPIError, stripObjectToScalars, UnknownUser } from "../../../utils";
|
||||||
import { SlowmodePluginType } from "../types";
|
import { SlowmodePluginType } from "../types";
|
||||||
|
|
||||||
export async function applyBotSlowmodeToUserId(
|
export async function applyBotSlowmodeToUserId(
|
||||||
|
@ -24,7 +24,7 @@ export async function applyBotSlowmodeToUserId(
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const user = pluginData.client.users.fetch(userId as Snowflake) || new UnknownUser({ id: userId });
|
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(
|
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})`,
|
`Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${channel.id}) on server ${pluginData.guild.name} (${pluginData.guild.id})`,
|
||||||
);
|
);
|
||||||
|
|
|
@ -70,13 +70,13 @@ export function isValidSnowflake(str: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DISCORD_HTTP_ERROR_NAME = "DiscordHTTPError";
|
export const DISCORD_HTTP_ERROR_NAME = "DiscordHTTPError";
|
||||||
export const DISCORD_REST_ERROR_NAME = "DiscordRESTError";
|
export const DISCORD_REST_ERROR_NAME = "DiscordAPIError";
|
||||||
|
|
||||||
export function isDiscordHTTPError(err: Error | string) {
|
export function isDiscordHTTPError(err: Error | string) {
|
||||||
return typeof err === "object" && err.constructor?.name === DISCORD_HTTP_ERROR_NAME;
|
return typeof err === "object" && err.constructor?.name === DISCORD_HTTP_ERROR_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isDiscordRESTError(err: Error | string) {
|
export function isDiscordAPIError(err: Error | string) {
|
||||||
return typeof err === "object" && err.constructor?.name === DISCORD_REST_ERROR_NAME;
|
return typeof err === "object" && err.constructor?.name === DISCORD_REST_ERROR_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +470,7 @@ export async function findRelevantAuditLogEntry(
|
||||||
try {
|
try {
|
||||||
auditLogs = await guild.fetchAuditLogs({ limit: 5, type: actionType });
|
auditLogs = await guild.fetchAuditLogs({ limit: 5, type: actionType });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e) && e.code === 50013) {
|
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||||
// If we don't have permission to read audit log, set audit log requests on cooldown
|
// If we don't have permission to read audit log, set audit log requests on cooldown
|
||||||
auditLogNextAttemptAfterFail.set(guild.id, Date.now() + AUDIT_LOG_FAIL_COOLDOWN);
|
auditLogNextAttemptAfterFail.set(guild.id, Date.now() + AUDIT_LOG_FAIL_COOLDOWN);
|
||||||
} else if (isDiscordHTTPError(e) && e.code === 500) {
|
} else if (isDiscordHTTPError(e) && e.code === 500) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { GuildPluginData } from "knub";
|
import { GuildPluginData } from "knub";
|
||||||
import { LogType } from "../data/LogType";
|
import { LogType } from "../data/LogType";
|
||||||
import { LogsPlugin } from "../plugins/Logs/LogsPlugin";
|
import { LogsPlugin } from "../plugins/Logs/LogsPlugin";
|
||||||
import { findRelevantAuditLogEntry, isDiscordRESTError } from "../utils";
|
import { findRelevantAuditLogEntry, isDiscordAPIError } from "../utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper for findRelevantAuditLogEntry() that handles permission errors gracefully.
|
* Wrapper for findRelevantAuditLogEntry() that handles permission errors gracefully.
|
||||||
|
@ -17,7 +17,7 @@ export async function safeFindRelevantAuditLogEntry(
|
||||||
try {
|
try {
|
||||||
return await findRelevantAuditLogEntry(pluginData.guild, actionType, userId, attempts, attemptDelay);
|
return await findRelevantAuditLogEntry(pluginData.guild, actionType, userId, attempts, attemptDelay);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e) && e.code === 50013) {
|
if (isDiscordAPIError(e) && e.code === 50013) {
|
||||||
const logs = pluginData.getPlugin(LogsPlugin);
|
const logs = pluginData.getPlugin(LogsPlugin);
|
||||||
logs.log(LogType.BOT_ALERT, {
|
logs.log(LogType.BOT_ALERT, {
|
||||||
body: "Missing permissions to read audit log",
|
body: "Missing permissions to read audit log",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { MessagePayload, User } from "discord.js";
|
import { MessagePayload, User } from "discord.js";
|
||||||
import { logger } from "../logger";
|
import { logger } from "../logger";
|
||||||
import { createChunkedMessage, HOURS, isDiscordRESTError } from "../utils";
|
import { createChunkedMessage, HOURS, isDiscordAPIError } from "../utils";
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
|
|
||||||
let dmsDisabled = false;
|
let dmsDisabled = false;
|
||||||
|
@ -30,7 +30,7 @@ export async function sendDM(user: User, content: string | MessagePayload, sourc
|
||||||
await user.send(content);
|
await user.send(content);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (isDiscordRESTError(e) && e.code === 20026) {
|
if (isDiscordAPIError(e) && e.code === 20026) {
|
||||||
logger.warn(`Received error code 20026: ${e.message}`);
|
logger.warn(`Received error code 20026: ${e.message}`);
|
||||||
logger.warn("Disabling attempts to send DMs for 1 hour");
|
logger.warn("Disabling attempts to send DMs for 1 hour");
|
||||||
disableDMs(1 * HOURS);
|
disableDMs(1 * HOURS);
|
||||||
|
|
14
package-lock.json
generated
14
package-lock.json
generated
|
@ -13,7 +13,7 @@
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"tslint": "^5.13.1",
|
"tslint": "^5.13.1",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "^1.18.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.3.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
|
@ -1975,9 +1975,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/typescript": {
|
"node_modules/typescript": {
|
||||||
"version": "4.1.3",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
|
||||||
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
|
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsc": "bin/tsc",
|
"tsc": "bin/tsc",
|
||||||
|
@ -3611,9 +3611,9 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"typescript": {
|
"typescript": {
|
||||||
"version": "4.1.3",
|
"version": "4.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.3.4.tgz",
|
||||||
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
|
"integrity": "sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"validate-npm-package-license": {
|
"validate-npm-package-license": {
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
"tslint": "^5.13.1",
|
"tslint": "^5.13.1",
|
||||||
"tslint-config-prettier": "^1.18.0",
|
"tslint-config-prettier": "^1.18.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.3.4"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue