Begin migrating away from stupid "Oh no, an error occurred!"

This commit is contained in:
Dragon Fire
2024-03-29 23:57:49 -04:00
parent 067545b818
commit 0b807767d1
130 changed files with 1692 additions and 2190 deletions
+7 -11
View File
@@ -28,16 +28,12 @@ module.exports = class CowSayCommand extends Command {
}
async run(msg, { text }) {
try {
const { body } = await request
.get('http://cowsay.morecode.org/say')
.query({
message: text,
format: 'json'
});
return msg.code(null, body.cow);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request
.get('http://cowsay.morecode.org/say')
.query({
message: text,
format: 'json'
});
return msg.code(null, body.cow);
}
};
+6 -10
View File
@@ -29,15 +29,11 @@ module.exports = class LolcatCommand extends Command {
}
async run(msg, { from }) {
try {
const { text } = await request
.get('https://speaklolcat.com/')
.query({ from });
const $ = cheerio.load(text);
const translated = $('textarea[id="to"]').first().text();
return msg.say(translated);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request
.get('https://speaklolcat.com/')
.query({ from });
const $ = cheerio.load(text);
const translated = $('textarea[id="to"]').first().text();
return msg.say(translated);
}
};
+1 -1
View File
@@ -41,7 +41,7 @@ module.exports = class ShortenUrlCommand extends Command {
return msg.say(body.link);
} catch (err) {
if (err.status === 400) return msg.reply('You provided an invalid URL. Please try again.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
throw err;
}
}
};
+7 -11
View File
@@ -55,16 +55,12 @@ module.exports = class TranslateCommand extends Command {
}
async run(msg, { text, target, base }) {
try {
const { text: result, from } = await translate(text, { to: target, from: base });
const embed = new MessageEmbed()
.setColor(0x4285F4)
.setFooter('Powered by Google Translate', 'https://i.imgur.com/h3RoHyp.png')
.addField(` From: ${translate.languages[from.language.iso]}`, from.text.value || text)
.addField(` To: ${translate.languages[target]}`, result);
return msg.embed(embed);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text: result, from } = await translate(text, { to: target, from: base });
const embed = new MessageEmbed()
.setColor(0x4285F4)
.setFooter('Powered by Google Translate', 'https://i.imgur.com/h3RoHyp.png')
.addField(` From: ${translate.languages[from.language.iso]}`, from.text.value || text)
.addField(` To: ${translate.languages[target]}`, result);
return msg.embed(embed);
}
};