Finish removing "Oh no, an error occurred"

This commit is contained in:
Dragon Fire
2024-03-30 11:59:42 -04:00
parent f6b59c2d46
commit a135cac031
119 changed files with 3418 additions and 4116 deletions
+3 -7
View File
@@ -21,12 +21,8 @@ module.exports = class AdviceCommand extends Command {
}
async run(msg) {
try {
const { text } = await request.get('http://api.adviceslip.com/advice');
const body = JSON.parse(text);
return msg.say(`${body.slip.advice} (#${body.slip.id})`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request.get('http://api.adviceslip.com/advice');
const body = JSON.parse(text);
return msg.say(`${body.slip.advice} (#${body.slip.id})`);
}
};
+2 -6
View File
@@ -20,11 +20,7 @@ module.exports = class BoredomCommand extends Command {
}
async run(msg) {
try {
const { body } = await request.get('https://www.boredapi.com/api/activity/');
return msg.say(`${body.activity} (${body.type})`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request.get('https://www.boredapi.com/api/activity/');
return msg.say(`${body.activity} (${body.type})`);
}
};
+2 -6
View File
@@ -26,11 +26,7 @@ module.exports = class ChuckNorrisCommand extends Command {
}
async run(msg) {
try {
const { body } = await request.get('https://api.chucknorris.io/jokes/random');
return msg.say(body.value);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request.get('https://api.chucknorris.io/jokes/random');
return msg.say(body.value);
}
};
+19 -23
View File
@@ -20,30 +20,26 @@ module.exports = class FactCommand extends Command {
}
async run(msg) {
try {
const article = await this.randomWikipediaArticle();
const { body } = await request
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: article,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
let fact = body.query.pages[0].extract;
if (fact.length > 200) {
const facts = fact.split('.');
fact = `${facts[0]}.`;
if (fact.length < 200 && facts.length > 1) fact += `${facts[1]}.`;
}
return msg.say(fact);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
const article = await this.randomWikipediaArticle();
const { body } = await request
.get('https://en.wikipedia.org/w/api.php')
.query({
action: 'query',
prop: 'extracts',
format: 'json',
titles: article,
exintro: '',
explaintext: '',
redirects: '',
formatversion: 2
});
let fact = body.query.pages[0].extract;
if (fact.length > 200) {
const facts = fact.split('.');
fact = `${facts[0]}.`;
if (fact.length < 200 && facts.length > 1) fact += `${facts[1]}.`;
}
return msg.say(fact);
}
async randomWikipediaArticle() {
+4 -8
View File
@@ -22,13 +22,9 @@ module.exports = class FmlCommand extends Command {
}
async run(msg) {
try {
const { text } = await request.get('http://www.fmylife.com/random');
const $ = cheerio.load(text, { normalizeWhitespace: true });
const fml = $('a.block').first().text().trim();
return msg.say(fml);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request.get('http://www.fmylife.com/random');
const $ = cheerio.load(text, { normalizeWhitespace: true });
const fml = $('a.block').first().text().trim();
return msg.say(fml);
}
};
+2 -6
View File
@@ -21,11 +21,7 @@ module.exports = class GithubZenCommand extends Command {
}
async run(msg) {
try {
const { text } = await request.get('https://api.github.com/zen');
return msg.say(text);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request.get('https://api.github.com/zen');
return msg.say(text);
}
};
+9 -13
View File
@@ -23,19 +23,15 @@ module.exports = class JokeCommand extends Command {
async run(msg) {
const blacklist = msg.channel.nsfw ? blacklistFlags : blacklistFlags.concat(nsfw);
try {
const { body } = await request
.get('https://v2.jokeapi.dev/joke/Any')
.query({ blacklistFlags: blacklist.join(',') });
if (body.type === 'twopart') {
return msg.say(stripIndents`
${body.setup}
${body.delivery}
`);
}
return msg.say(body.joke);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
const { body } = await request
.get('https://v2.jokeapi.dev/joke/Any')
.query({ blacklistFlags: blacklist.join(',') });
if (body.type === 'twopart') {
return msg.say(stripIndents`
${body.setup}
${body.delivery}
`);
}
return msg.say(body.joke);
}
};
+2 -6
View File
@@ -20,11 +20,7 @@ module.exports = class LightNovelTitleCommand extends Command {
}
async run(msg) {
try {
const { text } = await request.get('https://salty-salty-studios.com/shiz/ln.php');
return msg.say(text.match(/<h1>(.+)<\/h1>/i)[1]);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { text } = await request.get('https://salty-salty-studios.com/shiz/ln.php');
return msg.say(text.match(/<h1>(.+)<\/h1>/i)[1]);
}
};
+2 -6
View File
@@ -21,11 +21,7 @@ module.exports = class MtgCardCommand extends Command {
}
async run(msg) {
try {
const { url } = await request.get('https://scryfall.com/random?q=is%3Aspell+game%3Apaper');
return msg.say(url);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { url } = await request.get('https://scryfall.com/random?q=is%3Aspell+game%3Apaper');
return msg.say(url);
}
};
+10 -14
View File
@@ -30,19 +30,15 @@ module.exports = class NameCommand extends Command {
}
async run(msg, { gender }) {
try {
const { body } = await request
.get('https://randomuser.me/api/')
.query({
inc: 'name',
noinfo: '',
gender: gender === 'both' ? '' : gender,
nat: 'AU,US,CA,GB'
});
const data = body.results[0].name;
return msg.say(`${data.first} ${data.last}`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const { body } = await request
.get('https://randomuser.me/api/')
.query({
inc: 'name',
noinfo: '',
gender: gender === 'both' ? '' : gender,
nat: 'AU,US,CA,GB'
});
const data = body.results[0].name;
return msg.say(`${data.first} ${data.last}`);
}
};
+1 -1
View File
@@ -31,7 +31,7 @@ module.exports = class NumberFactCommand extends Command {
return msg.say(text);
} catch (err) {
if (err.status === 404) return msg.say('Could not find any results.');
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
throw err;
}
}
};
+9 -13
View File
@@ -23,19 +23,15 @@ module.exports = class PunCommand extends Command {
async run(msg) {
const blacklist = msg.channel.nsfw ? blacklistFlags : blacklistFlags.concat(nsfw);
try {
const { body } = await request
.get('https://v2.jokeapi.dev/joke/Pun')
.query({ blacklistFlags: blacklist.join(',') });
if (body.type === 'twopart') {
return msg.say(stripIndents`
${body.setup}
${body.delivery}
`);
}
return msg.say(body.joke);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
const { body } = await request
.get('https://v2.jokeapi.dev/joke/Pun')
.query({ blacklistFlags: blacklist.join(',') });
if (body.type === 'twopart') {
return msg.say(stripIndents`
${body.setup}
${body.delivery}
`);
}
return msg.say(body.joke);
}
};
+6 -10
View File
@@ -26,16 +26,12 @@ module.exports = class SuperpowerCommand extends Command {
}
async run(msg) {
try {
const id = await this.random();
const article = await this.fetchSuperpower(id);
return msg.reply(stripIndents`
Your superpower is... **${article.title}**!
_${article.abstract.split('1')[0].trim()}_
`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
const id = await this.random();
const article = await this.fetchSuperpower(id);
return msg.reply(stripIndents`
Your superpower is... **${article.title}**!
_${article.abstract.split('1')[0].trim()}_
`);
}
async random() {