From a4a7eb41b0971f30f736b082ff972bd5d8bd9280 Mon Sep 17 00:00:00 2001 From: Almeida Date: Thu, 6 May 2021 19:23:47 +0100 Subject: [PATCH] refactor(*): remove unused exception variables (#193) --- backend/ormconfig.js | 4 ++-- .../1573158035867-AddTypeAndPermissionsToApiPermissions.ts | 2 +- backend/src/plugins/Cases/functions/postToCaseLogChannel.ts | 4 ++-- backend/src/plugins/Censor/util/censorMessage.ts | 2 +- backend/src/plugins/ChannelArchiver/rehostAttachment.ts | 4 ++-- backend/src/plugins/LocateUser/utils/moveMember.ts | 2 +- backend/src/plugins/LocateUser/utils/sendWhere.ts | 2 +- backend/src/plugins/MessageSaver/saveMessagesToDB.ts | 2 +- backend/src/plugins/ModActions/commands/ForcebanCmd.ts | 2 +- backend/src/plugins/ModActions/commands/MassBanCmd.ts | 2 +- backend/src/plugins/ModActions/commands/MassUnbanCmd.ts | 2 +- backend/src/plugins/ModActions/commands/UnbanCmd.ts | 2 +- .../src/plugins/ModActions/functions/actualKickMemberCmd.ts | 4 ++-- backend/src/plugins/Mutes/functions/clearExpiredMutes.ts | 2 +- backend/src/plugins/Mutes/functions/muteUser.ts | 2 +- backend/src/plugins/Post/util/scheduledPostLoop.ts | 2 +- backend/src/plugins/Reminders/utils/postDueRemindersLoop.ts | 2 +- backend/src/plugins/SelfGrantableRoles/commands/RoleAddCmd.ts | 2 +- .../src/plugins/SelfGrantableRoles/commands/RoleRemoveCmd.ts | 2 +- .../src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts | 2 +- .../src/plugins/Starboard/events/StarboardReactionAddEvt.ts | 2 +- backend/src/plugins/Utility/commands/AboutCmd.ts | 2 +- backend/src/plugins/Utility/commands/NicknameCmd.ts | 2 +- backend/src/plugins/Utility/commands/NicknameResetCmd.ts | 2 +- backend/src/plugins/Utility/commands/VcdisconnectCmd.ts | 2 +- backend/src/plugins/Utility/commands/VcmoveCmd.ts | 4 ++-- .../plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts | 4 ++-- backend/src/utils.ts | 2 +- dashboard/src/store/auth.ts | 2 +- 29 files changed, 35 insertions(+), 35 deletions(-) diff --git a/backend/ormconfig.js b/backend/ormconfig.js index d9b4770b..9b8b311e 100644 --- a/backend/ormconfig.js +++ b/backend/ormconfig.js @@ -4,11 +4,11 @@ const path = require('path'); try { fs.accessSync(path.resolve(__dirname, 'bot.env')); require('dotenv').config({ path: path.resolve(__dirname, 'bot.env') }); -} catch (e) { +} catch { try { fs.accessSync(path.resolve(__dirname, 'api.env')); require('dotenv').config({ path: path.resolve(__dirname, 'api.env') }); - } catch (e) { + } catch { throw new Error("bot.env or api.env required"); } } diff --git a/backend/src/migrations/1573158035867-AddTypeAndPermissionsToApiPermissions.ts b/backend/src/migrations/1573158035867-AddTypeAndPermissionsToApiPermissions.ts index dc73be22..5186b0a0 100644 --- a/backend/src/migrations/1573158035867-AddTypeAndPermissionsToApiPermissions.ts +++ b/backend/src/migrations/1573158035867-AddTypeAndPermissionsToApiPermissions.ts @@ -4,7 +4,7 @@ export class AddTypeAndPermissionsToApiPermissions1573158035867 implements Migra public async up(queryRunner: QueryRunner): Promise { try { await queryRunner.dropPrimaryKey("api_permissions"); - } catch (e) {} // tslint:disable-line + } catch {} // tslint:disable-line const table = (await queryRunner.getTable("api_permissions"))!; if (table.indices.length) { diff --git a/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts b/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts index 1874b5e9..64057e29 100644 --- a/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts +++ b/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts @@ -52,7 +52,7 @@ export async function postCaseToCaseLogChannel( try { await pluginData.client.editMessage(channelId, messageId, caseEmbed); return null; - } catch (e) {} // tslint:disable-line:no-empty + } catch {} // tslint:disable-line:no-empty } try { @@ -63,7 +63,7 @@ export async function postCaseToCaseLogChannel( }); } return postedMessage; - } catch (e) { + } catch { pluginData.state.logs.log(LogType.BOT_ALERT, { body: `Failed to post case #${theCase.case_number} to the case log channel`, }); diff --git a/backend/src/plugins/Censor/util/censorMessage.ts b/backend/src/plugins/Censor/util/censorMessage.ts index 233c1aed..91302acf 100644 --- a/backend/src/plugins/Censor/util/censorMessage.ts +++ b/backend/src/plugins/Censor/util/censorMessage.ts @@ -14,7 +14,7 @@ export async function censorMessage( try { await pluginData.client.deleteMessage(savedMessage.channel_id, savedMessage.id, "Censored"); - } catch (e) { + } catch { return; } diff --git a/backend/src/plugins/ChannelArchiver/rehostAttachment.ts b/backend/src/plugins/ChannelArchiver/rehostAttachment.ts index d0d37d16..c0bbd289 100644 --- a/backend/src/plugins/ChannelArchiver/rehostAttachment.ts +++ b/backend/src/plugins/ChannelArchiver/rehostAttachment.ts @@ -13,7 +13,7 @@ export async function rehostAttachment(attachment: Attachment, targetChannel: Te let downloaded; try { downloaded = await downloadFile(attachment.url, 3); - } catch (e) { + } catch { return "Failed to download attachment after 3 tries"; } @@ -23,7 +23,7 @@ export async function rehostAttachment(attachment: Attachment, targetChannel: Te file: await fsp.readFile(downloaded.path), }); return rehostMessage.attachments[0].url; - } catch (e) { + } catch { return "Failed to rehost attachment"; } } diff --git a/backend/src/plugins/LocateUser/utils/moveMember.ts b/backend/src/plugins/LocateUser/utils/moveMember.ts index 327b933f..e3c75b16 100644 --- a/backend/src/plugins/LocateUser/utils/moveMember.ts +++ b/backend/src/plugins/LocateUser/utils/moveMember.ts @@ -15,7 +15,7 @@ export async function moveMember( await modMember.edit({ channelID: target.voiceState.channelID, }); - } catch (e) { + } catch { sendErrorMessage(pluginData, errorChannel, "Failed to move you. Are you in a voice channel?"); return; } diff --git a/backend/src/plugins/LocateUser/utils/sendWhere.ts b/backend/src/plugins/LocateUser/utils/sendWhere.ts index 11d07ba1..d6667748 100644 --- a/backend/src/plugins/LocateUser/utils/sendWhere.ts +++ b/backend/src/plugins/LocateUser/utils/sendWhere.ts @@ -21,7 +21,7 @@ export async function sendWhere( let invite: Invite; try { invite = await createOrReuseInvite(voice); - } catch (e) { + } catch { sendErrorMessage(pluginData, channel, "Cannot create an invite to that channel!"); return; } diff --git a/backend/src/plugins/MessageSaver/saveMessagesToDB.ts b/backend/src/plugins/MessageSaver/saveMessagesToDB.ts index a2aebde6..13217074 100644 --- a/backend/src/plugins/MessageSaver/saveMessagesToDB.ts +++ b/backend/src/plugins/MessageSaver/saveMessagesToDB.ts @@ -23,7 +23,7 @@ export async function saveMessagesToDB( } await pluginData.state.savedMessages.createFromMsg(thisMsg, { is_permanent: true }); - } catch (e) { + } catch { failed.push(id); } } diff --git a/backend/src/plugins/ModActions/commands/ForcebanCmd.ts b/backend/src/plugins/ModActions/commands/ForcebanCmd.ts index afda940e..fb060bd5 100644 --- a/backend/src/plugins/ModActions/commands/ForcebanCmd.ts +++ b/backend/src/plugins/ModActions/commands/ForcebanCmd.ts @@ -69,7 +69,7 @@ export const ForcebanCmd = modActionsCmd({ try { // FIXME: Use banUserId()? await pluginData.guild.banMember(user.id, 1, reason != null ? encodeURIComponent(reason) : undefined); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to forceban member"); return; } diff --git a/backend/src/plugins/ModActions/commands/MassBanCmd.ts b/backend/src/plugins/ModActions/commands/MassBanCmd.ts index bd79f7f3..b43994b4 100644 --- a/backend/src/plugins/ModActions/commands/MassBanCmd.ts +++ b/backend/src/plugins/ModActions/commands/MassBanCmd.ts @@ -77,7 +77,7 @@ export const MassbanCmd = modActionsCmd({ }); pluginData.state.events.emit("ban", userId, banReason); - } catch (e) { + } catch { failedBans.push(userId); } } diff --git a/backend/src/plugins/ModActions/commands/MassUnbanCmd.ts b/backend/src/plugins/ModActions/commands/MassUnbanCmd.ts index 897cc25f..e11289c8 100644 --- a/backend/src/plugins/ModActions/commands/MassUnbanCmd.ts +++ b/backend/src/plugins/ModActions/commands/MassUnbanCmd.ts @@ -69,7 +69,7 @@ export const MassunbanCmd = modActionsCmd({ reason: `Mass unban: ${unbanReason}`, postInCaseLogOverride: false, }); - } catch (e) { + } catch { failedUnbans.push({ userId, reason: UnbanFailReasons.UNBAN_FAILED }); } } diff --git a/backend/src/plugins/ModActions/commands/UnbanCmd.ts b/backend/src/plugins/ModActions/commands/UnbanCmd.ts index e5eac07c..ff35ca1a 100644 --- a/backend/src/plugins/ModActions/commands/UnbanCmd.ts +++ b/backend/src/plugins/ModActions/commands/UnbanCmd.ts @@ -50,7 +50,7 @@ export const UnbanCmd = modActionsCmd({ try { ignoreEvent(pluginData, IgnoredEventType.Unban, user.id); await pluginData.guild.unbanMember(user.id, reason != null ? encodeURIComponent(reason) : undefined); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to unban member; are you sure they're banned?"); return; } diff --git a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts index e467212c..23060bb3 100644 --- a/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts +++ b/backend/src/plugins/ModActions/functions/actualKickMemberCmd.ts @@ -83,7 +83,7 @@ export async function actualKickMemberCmd( try { await memberToKick.ban(1, encodeURIComponent("kick -clean")); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to ban the user to clean messages (-clean)"); } @@ -92,7 +92,7 @@ export async function actualKickMemberCmd( try { await pluginData.guild.unbanMember(memberToKick.id, encodeURIComponent("kick -clean")); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to unban the user after banning them (-clean)"); } } diff --git a/backend/src/plugins/Mutes/functions/clearExpiredMutes.ts b/backend/src/plugins/Mutes/functions/clearExpiredMutes.ts index 43acdace..60395d02 100644 --- a/backend/src/plugins/Mutes/functions/clearExpiredMutes.ts +++ b/backend/src/plugins/Mutes/functions/clearExpiredMutes.ts @@ -30,7 +30,7 @@ export async function clearExpiredMutes(pluginData: GuildPluginData Removed ${removedRolesStr.join(", ")} ${removedRolesWord}`, ); } - } catch (e) { + } catch { sendSuccessMessage( pluginData, msg.channel, diff --git a/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts b/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts index f1814922..39b1ab86 100644 --- a/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts +++ b/backend/src/plugins/Slowmode/util/disableBotSlowmodeForChannel.ts @@ -17,7 +17,7 @@ export async function disableBotSlowmodeForChannel( for (const slowmodeUser of users) { try { await clearBotSlowmodeFromUserId(pluginData, channel, slowmodeUser.user_id); - } catch (e) { + } catch { // Removing the slowmode failed. Record this so the permissions can be changed manually, and remove the database entry. failedUsers.push(slowmodeUser.user_id); await pluginData.state.slowmodes.clearSlowmodeUser(channel.id, slowmodeUser.user_id); diff --git a/backend/src/plugins/Starboard/events/StarboardReactionAddEvt.ts b/backend/src/plugins/Starboard/events/StarboardReactionAddEvt.ts index 6c6cf93a..e0adb1f9 100644 --- a/backend/src/plugins/Starboard/events/StarboardReactionAddEvt.ts +++ b/backend/src/plugins/Starboard/events/StarboardReactionAddEvt.ts @@ -19,7 +19,7 @@ export const StarboardReactionAddEvt = starboardEvt({ // Message is not cached, fetch it try { msg = await msg.channel.getMessage(msg.id); - } catch (e) { + } catch { // Sometimes we get this event for messages we can't fetch with getMessage; ignore silently return; } diff --git a/backend/src/plugins/Utility/commands/AboutCmd.ts b/backend/src/plugins/Utility/commands/AboutCmd.ts index 3f1285b4..e3f968ae 100644 --- a/backend/src/plugins/Utility/commands/AboutCmd.ts +++ b/backend/src/plugins/Utility/commands/AboutCmd.ts @@ -25,7 +25,7 @@ export const AboutCmd = utilityCmd({ try { const lcl = new LCL(rootDir); lastCommit = await lcl.getLastCommit(); - } catch (e) {} // tslint:disable-line:no-empty + } catch {} // tslint:disable-line:no-empty let lastUpdate; let version; diff --git a/backend/src/plugins/Utility/commands/NicknameCmd.ts b/backend/src/plugins/Utility/commands/NicknameCmd.ts index 42130544..4df752e8 100644 --- a/backend/src/plugins/Utility/commands/NicknameCmd.ts +++ b/backend/src/plugins/Utility/commands/NicknameCmd.ts @@ -32,7 +32,7 @@ export const NicknameCmd = utilityCmd({ await args.member.edit({ nick: args.nickname, }); - } catch (e) { + } catch { msg.channel.createMessage(errorMessage("Failed to change nickname")); return; } diff --git a/backend/src/plugins/Utility/commands/NicknameResetCmd.ts b/backend/src/plugins/Utility/commands/NicknameResetCmd.ts index e1d74ba0..33085053 100644 --- a/backend/src/plugins/Utility/commands/NicknameResetCmd.ts +++ b/backend/src/plugins/Utility/commands/NicknameResetCmd.ts @@ -23,7 +23,7 @@ export const NicknameResetCmd = utilityCmd({ await args.member.edit({ nick: "", }); - } catch (e) { + } catch { msg.channel.createMessage(errorMessage("Failed to reset nickname")); return; } diff --git a/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts b/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts index 0d5e6925..abd988ab 100644 --- a/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts +++ b/backend/src/plugins/Utility/commands/VcdisconnectCmd.ts @@ -38,7 +38,7 @@ export const VcdisconnectCmd = utilityCmd({ await args.member.edit({ channelID: null, }); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to disconnect member"); return; } diff --git a/backend/src/plugins/Utility/commands/VcmoveCmd.ts b/backend/src/plugins/Utility/commands/VcmoveCmd.ts index aa9a9131..eb85ef71 100644 --- a/backend/src/plugins/Utility/commands/VcmoveCmd.ts +++ b/backend/src/plugins/Utility/commands/VcmoveCmd.ts @@ -75,7 +75,7 @@ export const VcmoveCmd = utilityCmd({ await args.member.edit({ channelID: channel.id, }); - } catch (e) { + } catch { sendErrorMessage(pluginData, msg.channel, "Failed to move member"); return; } @@ -174,7 +174,7 @@ export const VcmoveAllCmd = utilityCmd({ currMember.edit({ channelID: channel.id, }); - } catch (e) { + } catch { if (msg.member.id === currMember.id) { sendErrorMessage(pluginData, msg.channel, "Unknown error when trying to move members"); return; diff --git a/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts b/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts index c807c14c..9ae1e85f 100644 --- a/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts +++ b/backend/src/plugins/WelcomeMessage/events/SendWelcomeMessageEvt.ts @@ -46,7 +46,7 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({ if (config.send_dm) { try { await sendDM(member.user, formatted, "welcome message"); - } catch (e) { + } catch { pluginData.state.logs.log(LogType.DM_FAILED, { source: "welcome message", user: stripObjectToScalars(member.user), @@ -60,7 +60,7 @@ export const SendWelcomeMessageEvt = welcomeMessageEvt({ try { await createChunkedMessage(channel, formatted); - } catch (e) { + } catch { pluginData.state.logs.log(LogType.BOT_ALERT, { body: `Failed send a welcome message for {userMention(member)} to {channelMention(channel)}`, member: stripObjectToScalars(member), diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 5607bfa8..e3f3fdaf 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -526,7 +526,7 @@ export function getUrlsInString(str: string, onlyUnique = false): MatchedURL[] { try { matchUrl = new URL(withProtocol) as MatchedURL; matchUrl.input = match; - } catch (e) { + } catch { return urls; } diff --git a/dashboard/src/store/auth.ts b/dashboard/src/store/auth.ts index 12f0f4e3..db0fd084 100644 --- a/dashboard/src/store/auth.ts +++ b/dashboard/src/store/auth.ts @@ -22,7 +22,7 @@ export const AuthStore: Module = { await dispatch("setApiKey", storedKey); return; } - } catch (e) {} // tslint:disable-line + } catch {} // tslint:disable-line console.log("Unable to validate key, removing from localStorage"); // tslint:disable-line localStorage.removeItem("apiKey");