From e7dfa229f1dd974e30fc4356491a0e5036f116dd Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sat, 14 Mar 2020 11:57:15 -0400 Subject: [PATCH] Omit catch block errors when not needed --- Xiao.js | 4 ++-- commands/analyze/what-anime.js | 4 ++-- commands/info/user.js | 2 +- commands/number-edit/math.js | 2 +- commands/number-edit/units.js | 2 +- commands/other/phone.js | 2 +- commands/other/portal-send.js | 2 +- commands/other/prune.js | 2 +- commands/other/rename-all.js | 2 +- commands/search/google.js | 2 +- commands/single/hi.js | 2 +- commands/text-edit/say.js | 2 +- commands/util/help.js | 2 +- commands/util/report.js | 4 ++-- types/image.js | 2 +- 15 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Xiao.js b/Xiao.js index 87a3c474..fe795a26 100644 --- a/Xiao.js +++ b/Xiao.js @@ -67,7 +67,7 @@ client.on('message', async msg => { if (!call.active) return; try { await call.send(origin ? call.recipient : call.origin, msg); - } catch (err) { + } catch { return; // eslint-disable-line no-useless-return } }); @@ -80,7 +80,7 @@ client.on('guildMemberRemove', async member => { const leaveMsg = leaveMsgs[Math.floor(Math.random() * leaveMsgs.length)]; await channel.send(leaveMsg.replace(/{{user}}/gi, `**${member.user.tag}**`)); return null; - } catch (err) { + } catch { return null; } }); diff --git a/commands/analyze/what-anime.js b/commands/analyze/what-anime.js index d87593a6..84d94184 100644 --- a/commands/analyze/what-anime.js +++ b/commands/analyze/what-anime.js @@ -59,7 +59,7 @@ module.exports = class WhatAnimeCommand extends Command { .get('https://trace.moe/api/me') .query({ token: WHATANIME_KEY }); return { status: body.quota > 0, refresh: body.quota_ttl }; - } catch (err) { + } catch { return { status: false, refresh: Infinity }; } } @@ -89,7 +89,7 @@ module.exports = class WhatAnimeCommand extends Command { token: data.tokenthumb }); return body; - } catch (err) { + } catch { return null; } } diff --git a/commands/info/user.js b/commands/info/user.js index 028f5647..90e7753e 100644 --- a/commands/info/user.js +++ b/commands/info/user.js @@ -54,7 +54,7 @@ module.exports = class UserCommand extends Command { • ${roles.length ? trimArray(roles, 6).join(', ') : 'None'} `; embed.setColor(member.displayHexColor); - } catch (err) { + } catch { embed.setFooter('Failed to resolve member, showing basic user information instead.'); } } diff --git a/commands/number-edit/math.js b/commands/number-edit/math.js index 54264fd8..ae6280e2 100644 --- a/commands/number-edit/math.js +++ b/commands/number-edit/math.js @@ -30,7 +30,7 @@ module.exports = class MathCommand extends Command { try { const evaluated = math.evaluate(expression).toString(); return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.')); - } catch (err) { + } catch { return msg.reply('Invalid expression.'); } } diff --git a/commands/number-edit/units.js b/commands/number-edit/units.js index 20cf5e22..0a5fccd6 100644 --- a/commands/number-edit/units.js +++ b/commands/number-edit/units.js @@ -43,7 +43,7 @@ module.exports = class UnitsCommand extends Command { try { const value = math.unit(amount, base).toNumber(target); return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(value)} ${target}.`); - } catch (err) { + } catch { return msg.say('Either an invalid unit type was provided or the unit types do not match.'); } } diff --git a/commands/other/phone.js b/commands/other/phone.js index 8317e8b7..62bd6291 100644 --- a/commands/other/phone.js +++ b/commands/other/phone.js @@ -47,7 +47,7 @@ module.exports = class PhoneCommand extends Command { this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel)); await this.client.phone.get(id).start(); return null; - } catch (err) { + } catch { return msg.reply('Failed to start the call. Try again later!'); } } diff --git a/commands/other/portal-send.js b/commands/other/portal-send.js index b199cdc5..0cb5b7a9 100644 --- a/commands/other/portal-send.js +++ b/commands/other/portal-send.js @@ -37,7 +37,7 @@ module.exports = class PortalSendCommand extends Command { const displayName = msg.channel.type === 'text' ? msg.guild.name : 'DM'; await channel.send(`**${this.portalEmoji} ${msg.author.tag} (${displayName}):** ${message}`); return msg.say(`Message sent to **${channel.name}** in **${channel.guild.name}**!`); - } catch (err) { + } catch { return msg.reply('Failed to send the message. Try again later!'); } } diff --git a/commands/other/prune.js b/commands/other/prune.js index 2d4364e4..82c0a645 100644 --- a/commands/other/prune.js +++ b/commands/other/prune.js @@ -33,7 +33,7 @@ module.exports = class PruneCommand extends Command { const messages = await msg.channel.messages.fetch({ limit: count + 1 }); await msg.channel.bulkDelete(messages, true); return null; - } catch (err) { + } catch { return msg.reply('There are no messages younger than two weeks that can be deleted.'); } } diff --git a/commands/other/rename-all.js b/commands/other/rename-all.js index 4c5e57bb..c4655ff6 100644 --- a/commands/other/rename-all.js +++ b/commands/other/rename-all.js @@ -50,7 +50,7 @@ module.exports = class RenameAllCommand extends Command { for (const member of msg.guild.members.cache.values()) { try { await member.setNickname(nickname); - } catch (err) { + } catch { i++; continue; } diff --git a/commands/search/google.js b/commands/search/google.js index 89fc5432..ecbe7ff5 100644 --- a/commands/search/google.js +++ b/commands/search/google.js @@ -42,7 +42,7 @@ module.exports = class GoogleCommand extends Command { const nsfw = msg.channel.nsfw || false; try { href = await this.customSearch(query, nsfw); - } catch (err) { + } catch { href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`; } if (!href) return msg.say('Could not find any results.'); diff --git a/commands/single/hi.js b/commands/single/hi.js index cdf32358..369f24ac 100644 --- a/commands/single/hi.js +++ b/commands/single/hi.js @@ -15,7 +15,7 @@ module.exports = class HiCommand extends Command { try { await msg.react('👋'); return null; - } catch (err) { + } catch { return msg.reply('Hi there!'); } } diff --git a/commands/text-edit/say.js b/commands/text-edit/say.js index bac58b4b..a6359afa 100644 --- a/commands/text-edit/say.js +++ b/commands/text-edit/say.js @@ -22,7 +22,7 @@ module.exports = class SayCommand extends Command { try { if (msg.channel.type === 'text' && msg.deletable) await msg.delete(); return msg.say(text); - } catch (err) { + } catch { return msg.say(text); } } diff --git a/commands/util/help.js b/commands/util/help.js index 711ce113..9b19e248 100644 --- a/commands/util/help.js +++ b/commands/util/help.js @@ -48,7 +48,7 @@ module.exports = class HelpCommand extends Command { msgs.push(await msg.direct({ embed })); if (msg.channel.type !== 'dm') msgs.push(await msg.say('📬 Sent you a DM with information.')); return msgs; - } catch (err) { + } catch { return msg.reply('Failed to send DM. You probably have DMs disabled.'); } } diff --git a/commands/util/report.js b/commands/util/report.js index 2e8d826e..13e3f0d0 100644 --- a/commands/util/report.js +++ b/commands/util/report.js @@ -44,7 +44,7 @@ module.exports = class ReportCommand extends Command { try { const channel = await this.client.channels.fetch(REPORT_CHANNEL_ID); await channel.send({ embed }); - } catch (err) { + } catch { await this.sendOwnerDM(embed); } } else { @@ -57,7 +57,7 @@ module.exports = class ReportCommand extends Command { for (const owner of this.client.owners) { try { await owner.send({ embed }); - } catch (err) { + } catch { continue; } } diff --git a/types/image.js b/types/image.js index 5e77f389..c64b9d23 100644 --- a/types/image.js +++ b/types/image.js @@ -19,7 +19,7 @@ module.exports = class ImageArgumentType extends ArgumentType { try { await request.get(value); return true; - } catch (err) { + } catch { return false; } }