mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 14:19:56 +02:00
Omit catch block errors when not needed
This commit is contained in:
@@ -67,7 +67,7 @@ client.on('message', async msg => {
|
|||||||
if (!call.active) return;
|
if (!call.active) return;
|
||||||
try {
|
try {
|
||||||
await call.send(origin ? call.recipient : call.origin, msg);
|
await call.send(origin ? call.recipient : call.origin, msg);
|
||||||
} catch (err) {
|
} catch {
|
||||||
return; // eslint-disable-line no-useless-return
|
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)];
|
const leaveMsg = leaveMsgs[Math.floor(Math.random() * leaveMsgs.length)];
|
||||||
await channel.send(leaveMsg.replace(/{{user}}/gi, `**${member.user.tag}**`));
|
await channel.send(leaveMsg.replace(/{{user}}/gi, `**${member.user.tag}**`));
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ module.exports = class WhatAnimeCommand extends Command {
|
|||||||
.get('https://trace.moe/api/me')
|
.get('https://trace.moe/api/me')
|
||||||
.query({ token: WHATANIME_KEY });
|
.query({ token: WHATANIME_KEY });
|
||||||
return { status: body.quota > 0, refresh: body.quota_ttl };
|
return { status: body.quota > 0, refresh: body.quota_ttl };
|
||||||
} catch (err) {
|
} catch {
|
||||||
return { status: false, refresh: Infinity };
|
return { status: false, refresh: Infinity };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,7 @@ module.exports = class WhatAnimeCommand extends Command {
|
|||||||
token: data.tokenthumb
|
token: data.tokenthumb
|
||||||
});
|
});
|
||||||
return body;
|
return body;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module.exports = class UserCommand extends Command {
|
|||||||
• ${roles.length ? trimArray(roles, 6).join(', ') : 'None'}
|
• ${roles.length ? trimArray(roles, 6).join(', ') : 'None'}
|
||||||
`;
|
`;
|
||||||
embed.setColor(member.displayHexColor);
|
embed.setColor(member.displayHexColor);
|
||||||
} catch (err) {
|
} catch {
|
||||||
embed.setFooter('Failed to resolve member, showing basic user information instead.');
|
embed.setFooter('Failed to resolve member, showing basic user information instead.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ module.exports = class MathCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const evaluated = math.evaluate(expression).toString();
|
const evaluated = math.evaluate(expression).toString();
|
||||||
return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.'));
|
return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.'));
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.reply('Invalid expression.');
|
return msg.reply('Invalid expression.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ module.exports = class UnitsCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const value = math.unit(amount, base).toNumber(target);
|
const value = math.unit(amount, base).toNumber(target);
|
||||||
return msg.say(`${formatNumber(amount)} ${base} is ${formatNumber(value)} ${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.');
|
return msg.say('Either an invalid unit type was provided or the unit types do not match.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ module.exports = class PhoneCommand extends Command {
|
|||||||
this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel));
|
this.client.phone.set(id, new PhoneCall(this.client, msg.channel, channel));
|
||||||
await this.client.phone.get(id).start();
|
await this.client.phone.get(id).start();
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.reply('Failed to start the call. Try again later!');
|
return msg.reply('Failed to start the call. Try again later!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ module.exports = class PortalSendCommand extends Command {
|
|||||||
const displayName = msg.channel.type === 'text' ? msg.guild.name : 'DM';
|
const displayName = msg.channel.type === 'text' ? msg.guild.name : 'DM';
|
||||||
await channel.send(`**${this.portalEmoji} ${msg.author.tag} (${displayName}):** ${message}`);
|
await channel.send(`**${this.portalEmoji} ${msg.author.tag} (${displayName}):** ${message}`);
|
||||||
return msg.say(`Message sent to **${channel.name}** in **${channel.guild.name}**!`);
|
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!');
|
return msg.reply('Failed to send the message. Try again later!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ module.exports = class PruneCommand extends Command {
|
|||||||
const messages = await msg.channel.messages.fetch({ limit: count + 1 });
|
const messages = await msg.channel.messages.fetch({ limit: count + 1 });
|
||||||
await msg.channel.bulkDelete(messages, true);
|
await msg.channel.bulkDelete(messages, true);
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.reply('There are no messages younger than two weeks that can be deleted.');
|
return msg.reply('There are no messages younger than two weeks that can be deleted.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ module.exports = class RenameAllCommand extends Command {
|
|||||||
for (const member of msg.guild.members.cache.values()) {
|
for (const member of msg.guild.members.cache.values()) {
|
||||||
try {
|
try {
|
||||||
await member.setNickname(nickname);
|
await member.setNickname(nickname);
|
||||||
} catch (err) {
|
} catch {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ module.exports = class GoogleCommand extends Command {
|
|||||||
const nsfw = msg.channel.nsfw || false;
|
const nsfw = msg.channel.nsfw || false;
|
||||||
try {
|
try {
|
||||||
href = await this.customSearch(query, nsfw);
|
href = await this.customSearch(query, nsfw);
|
||||||
} catch (err) {
|
} catch {
|
||||||
href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`;
|
href = `http://lmgtfy.com/?iie=1&q=${encodeURIComponent(query)}`;
|
||||||
}
|
}
|
||||||
if (!href) return msg.say('Could not find any results.');
|
if (!href) return msg.say('Could not find any results.');
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ module.exports = class HiCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
await msg.react('👋');
|
await msg.react('👋');
|
||||||
return null;
|
return null;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.reply('Hi there!');
|
return msg.reply('Hi there!');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ module.exports = class SayCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
if (msg.channel.type === 'text' && msg.deletable) await msg.delete();
|
if (msg.channel.type === 'text' && msg.deletable) await msg.delete();
|
||||||
return msg.say(text);
|
return msg.say(text);
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.say(text);
|
return msg.say(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ module.exports = class HelpCommand extends Command {
|
|||||||
msgs.push(await msg.direct({ embed }));
|
msgs.push(await msg.direct({ embed }));
|
||||||
if (msg.channel.type !== 'dm') msgs.push(await msg.say('📬 Sent you a DM with information.'));
|
if (msg.channel.type !== 'dm') msgs.push(await msg.say('📬 Sent you a DM with information.'));
|
||||||
return msgs;
|
return msgs;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return msg.reply('Failed to send DM. You probably have DMs disabled.');
|
return msg.reply('Failed to send DM. You probably have DMs disabled.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ module.exports = class ReportCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const channel = await this.client.channels.fetch(REPORT_CHANNEL_ID);
|
const channel = await this.client.channels.fetch(REPORT_CHANNEL_ID);
|
||||||
await channel.send({ embed });
|
await channel.send({ embed });
|
||||||
} catch (err) {
|
} catch {
|
||||||
await this.sendOwnerDM(embed);
|
await this.sendOwnerDM(embed);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -57,7 +57,7 @@ module.exports = class ReportCommand extends Command {
|
|||||||
for (const owner of this.client.owners) {
|
for (const owner of this.client.owners) {
|
||||||
try {
|
try {
|
||||||
await owner.send({ embed });
|
await owner.send({ embed });
|
||||||
} catch (err) {
|
} catch {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ module.exports = class ImageArgumentType extends ArgumentType {
|
|||||||
try {
|
try {
|
||||||
await request.get(value);
|
await request.get(value);
|
||||||
return true;
|
return true;
|
||||||
} catch (err) {
|
} catch {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user