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

Another potential fix for Node.js 13/14 incompatibility

This commit is contained in:
Dragory 2020-05-08 18:29:17 +03:00
parent 0de53d1fb4
commit 31d3e2b1d7
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
9 changed files with 33 additions and 31 deletions

View file

@ -3,9 +3,8 @@ import { GuildSavedMessages } from "../data/GuildSavedMessages";
import { SavedMessage } from "../data/entities/SavedMessage";
import { GuildAutoReactions } from "../data/GuildAutoReactions";
import { Message } from "eris";
import { customEmojiRegex, errorMessage, isEmoji } from "../utils";
import { customEmojiRegex, errorMessage, isDiscordRESTError, isEmoji } from "../utils";
import { CommandInfo, trimPluginDescription, ZeppelinPlugin } from "./ZeppelinPlugin";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import * as t from "io-ts";
import { GuildLogs } from "../data/GuildLogs";
import { LogType } from "../data/LogType";
@ -128,7 +127,7 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
realMsg = await this.bot.getMessage(msg.channel_id, msg.id);
} catch (e) {
if (e instanceof DiscordRESTError) {
if (isDiscordRESTError(e)) {
logger.warn(
`Could not load auto-reaction message ${msg.channel_id}/${msg.id} in guild ${this.guild.name} (${this.guildId}) (error code ${e.code})`,
);
@ -157,7 +156,7 @@ export class AutoReactionsPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
await realMsg.addReaction(reaction);
} catch (e) {
if (e instanceof DiscordRESTError) {
if (isDiscordRESTError(e)) {
logger.warn(
`Could not apply auto-reaction to ${msg.channel_id}/${msg.id} in guild ${this.guild.name} (${this.guildId}) (error code ${e.code})`,
);

View file

@ -10,11 +10,9 @@ import { IPluginOptions, logger } from "knub";
import { GuildLogs } from "../data/GuildLogs";
import { LogType } from "../data/LogType";
import * as t from "io-ts";
import { tNullable } from "../utils";
import { isDiscordRESTError, tNullable } from "../utils";
import { ERRORS } from "../RecoverablePluginError";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
const ConfigSchema = t.type({
log_automatic_actions: t.boolean,
case_log_channel: tNullable(t.string),
@ -277,7 +275,7 @@ export class CasesPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
result = await caseLogChannel.createMessage(content, file);
} catch (e) {
if (e instanceof DiscordRESTError && e.code === 50013) {
if (isDiscordRESTError(e) && e.code === 50013) {
logger.warn(
`Missing permissions to post mod cases in <#${caseLogChannel.id}> in guild ${this.guild.name} (${this.guild.id})`,
);

View file

@ -2,10 +2,10 @@ import { decorators as d, IPluginOptions, logger } from "knub";
import { GuildLogs } from "../data/GuildLogs";
import { LogType } from "../data/LogType";
import { Attachment, Channel, Constants as ErisConstants, Embed, Member, TextChannel, User } from "eris";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import {
createChunkedMessage,
findRelevantAuditLogEntry,
isDiscordRESTError,
messageSummary,
noop,
stripObjectToScalars,
@ -263,7 +263,7 @@ export class LogsPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
return await findRelevantAuditLogEntry(this.guild, actionType, userId, attempts, attemptDelay);
} catch (e) {
if (e instanceof DiscordRESTError && e.code === 50013) {
if (isDiscordRESTError(e) && e.code === 50013) {
this.guildLogs.log(LogType.BOT_ALERT, {
body: "Missing permissions to read audit log",
});

View file

@ -1,7 +1,5 @@
import { decorators as d, IPluginOptions, logger, waitForReaction, waitForReply } from "knub";
import { Attachment, Constants as ErisConstants, Guild, Member, Message, TextChannel, User } from "eris";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import DiscordHTTPError = require("eris/lib/errors/DiscordHTTPError.js"); // tslint:disable-line
import humanizeDuration from "humanize-duration";
import { GuildCases } from "../data/GuildCases";
import {
@ -10,6 +8,8 @@ import {
disableUserNotificationStrings,
errorMessage,
findRelevantAuditLogEntry,
isDiscordHTTPError,
isDiscordRESTError,
MINUTES,
multiSorter,
notifyUser,
@ -281,7 +281,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
const bans = (await this.guild.getBans()) as any;
return bans.some(b => b.user.id === userId);
} catch (e) {
if (e instanceof DiscordHTTPError && e.code === 500) {
if (isDiscordHTTPError(e) && e.code === 500) {
return false;
}
@ -293,7 +293,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
return await findRelevantAuditLogEntry(this.guild, actionType, userId, attempts, attemptDelay);
} catch (e) {
if (e instanceof DiscordRESTError && e.code === 50013) {
if (isDiscordRESTError(e) && e.code === 50013) {
this.serverLogs.log(LogType.BOT_ALERT, {
body: "Missing permissions to read audit log",
});
@ -827,7 +827,7 @@ export class ModActionsPlugin extends ZeppelinPlugin<TConfigSchema> {
} catch (e) {
if (e instanceof RecoverablePluginError && e.code === ERRORS.NO_MUTE_ROLE_IN_CONFIG) {
this.sendErrorMessage(msg.channel, "Could not mute the user: no mute role set in config");
} else if (e instanceof DiscordRESTError && e.code === 10007) {
} else if (isDiscordRESTError(e) && e.code === 10007) {
this.sendErrorMessage(msg.channel, "Could not mute the user: unknown member");
} else {
logger.error(`Failed to mute user ${user.id}: ${e.stack}`);

View file

@ -1,12 +1,11 @@
import { decorators as d, IPluginOptions, logger } from "knub";
import { CustomEmoji, errorMessage, isSnowflake, noop, sleep } from "../utils";
import { CustomEmoji, errorMessage, isDiscordRESTError, isSnowflake, noop, sleep } from "../utils";
import { GuildReactionRoles } from "../data/GuildReactionRoles";
import { Message, TextChannel } from "eris";
import { ZeppelinPlugin } from "./ZeppelinPlugin";
import { GuildSavedMessages } from "../data/GuildSavedMessages";
import { Queue } from "../Queue";
import { ReactionRole } from "../data/entities/ReactionRole";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import * as t from "io-ts";
import { ERRORS, RecoverablePluginError } from "../RecoverablePluginError";
import Timeout = NodeJS.Timeout;
@ -143,7 +142,7 @@ export class ReactionRolesPlugin extends ZeppelinPlugin<TConfigSchema> {
try {
targetMessage = await channel.getMessage(messageId);
} catch (e) {
if (e instanceof DiscordRESTError) {
if (isDiscordRESTError(e)) {
if (e.code === 10008) {
// Unknown message, remove reaction roles from the message
logger.warn(

View file

@ -4,6 +4,7 @@ import {
convertDelayStringToMS,
createChunkedMessage,
errorMessage,
isDiscordRESTError,
noop,
stripObjectToScalars,
successMessage,
@ -14,7 +15,6 @@ import humanizeDuration from "humanize-duration";
import { ZeppelinPlugin } from "./ZeppelinPlugin";
import { SavedMessage } from "../data/entities/SavedMessage";
import { GuildSavedMessages } from "../data/GuildSavedMessages";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import { GuildLogs } from "../data/GuildLogs";
import { LogType } from "../data/LogType";
import * as t from "io-ts";
@ -99,7 +99,7 @@ export class SlowmodePlugin extends ZeppelinPlugin<TConfigSchema> {
} catch (e) {
const user = this.bot.users.get(userId) || new UnknownUser({ id: userId });
if (e instanceof DiscordRESTError && e.code === 50013) {
if (isDiscordRESTError(e) && e.code === 50013) {
logger.warn(
`Missing permissions to apply bot slowmode to user ${userId} on channel ${channel.name} (${channel.id}) on server ${this.guild.name} (${this.guildId})`,
);

View file

@ -2,6 +2,7 @@ import { configUtils, IBasePluginConfig, IPluginOptions, logger, Plugin } from "
import * as t from "io-ts";
import {
deepKeyIntersect,
isDiscordRESTError,
isSnowflake,
isUnicodeEmoji,
MINUTES,
@ -16,7 +17,6 @@ import {
UnknownUser,
} from "../utils";
import { Invite, Member, User } from "eris";
import DiscordRESTError = require("eris/lib/errors/DiscordRESTError.js"); // tslint:disable-line
import { performance } from "perf_hooks";
import { decodeAndValidateStrict, StrictValidationError, validate } from "../validatorUtils";
import { SimpleCache } from "../SimpleCache";
@ -270,7 +270,7 @@ export class ZeppelinPlugin<
try {
member = userId && (await this.bot.getRESTGuildMember(this.guild.id, userId));
} catch (e) {
if (!(e instanceof DiscordRESTError)) {
if (!isDiscordRESTError(e)) {
throw e;
}
}