mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 15:57:43 +02:00
Begin migrating away from stupid "Oh no, an error occurred!"
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user